pgsql-deparser 13.18.0 → 13.19.1

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.
Files changed (43) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +12 -10
  3. package/deparser/deparser.d.ts +308 -0
  4. package/deparser/deparser.js +10477 -0
  5. package/deparser/index.d.ts +9 -0
  6. package/deparser/index.js +17 -0
  7. package/deparser/utils/list-utils.d.ts +8 -0
  8. package/deparser/utils/list-utils.js +30 -0
  9. package/deparser/utils/quote-utils.d.ts +24 -0
  10. package/deparser/utils/quote-utils.js +89 -0
  11. package/deparser/utils/sql-formatter.d.ts +16 -0
  12. package/deparser/utils/sql-formatter.js +40 -0
  13. package/deparser/visitors/base.d.ts +68 -0
  14. package/deparser/visitors/base.js +122 -0
  15. package/{src/deparser/deparser.ts → esm/deparser/deparser.js} +751 -752
  16. package/{src/deparser/index.ts → esm/deparser/index.js} +3 -4
  17. package/{src/deparser/utils/list-utils.ts → esm/deparser/utils/list-utils.js} +2 -3
  18. package/{src/deparser/utils/quote-utils.ts → esm/deparser/utils/quote-utils.js} +6 -7
  19. package/{src/deparser/utils/sql-formatter.ts → esm/deparser/utils/sql-formatter.js} +10 -11
  20. package/{src/deparser/visitors/base.ts → esm/deparser/visitors/base.js} +34 -62
  21. package/esm/index.js +15 -0
  22. package/{src/v13-to-v14.ts → esm/v13-to-v14.js} +472 -609
  23. package/{src/v13-to-v17-direct.ts → esm/v13-to-v17-direct.js} +11 -12
  24. package/{src/v14-to-v15.ts → esm/v14-to-v15.js} +261 -662
  25. package/{src/v15-to-v16.ts → esm/v15-to-v16.js} +814 -1229
  26. package/esm/v16-to-v17.js +1488 -0
  27. package/index.d.ts +9 -0
  28. package/index.js +19 -0
  29. package/package.json +5 -5
  30. package/v13-to-v14.d.ts +253 -0
  31. package/v13-to-v14.js +2754 -0
  32. package/v13-to-v17-direct.d.ts +24 -0
  33. package/v13-to-v17-direct.js +82 -0
  34. package/v14-to-v15.d.ts +616 -0
  35. package/v14-to-v15.js +1227 -0
  36. package/v15-to-v16.d.ts +633 -0
  37. package/v15-to-v16.js +2944 -0
  38. package/v16-to-v17.d.ts +638 -0
  39. package/v16-to-v17.js +1492 -0
  40. package/src/index.ts +0 -27
  41. package/src/v16-to-v17.ts +0 -1897
  42. package/tsconfig.esm.json +0 -8
  43. package/tsconfig.json +0 -26
@@ -2,8 +2,7 @@
2
2
  * Auto-generated file with types stripped for better tree-shaking
3
3
  * DO NOT EDIT - Generated by strip-deparser-types.ts
4
4
  */
5
-
6
- import { DeparserContext, DeparserVisitor } from './visitors/base';
5
+ import { DeparserContext } from './visitors/base';
7
6
  import { SqlFormatter } from './utils/sql-formatter';
8
7
  import { QuoteUtils } from './utils/quote-utils';
9
8
  import { ListUtils } from './utils/list-utils';
@@ -56,27 +55,15 @@ const pgCatalogTypes = [
56
55
  * but not present in pg_catalog.pg_type. These are resolved to
57
56
  * real types during parsing and never appear in introspection.
58
57
  */
59
- const pgCatalogTypeAliases: [
60
- string,
61
- string[]
62
- ][] = [
58
+ const pgCatalogTypeAliases = [
63
59
  ['numeric', ['decimal', 'dec']],
64
60
  ['int4', ['int', 'integer']],
65
61
  ['float8', ['float']],
66
62
  ['bpchar', ['character']],
67
63
  ['varchar', ['character varying']]
68
64
  ];
69
- export interface DeparserOptions {
70
- newline?: string;
71
- tab?: string;
72
- // Function body delimiter options
73
- functionDelimiter?: string; // Default: '$$'
74
- // Alternative delimiter when the default is found in the body
75
- functionDelimiterFallback?: string; // Default: '$EOFCODE$'
76
- pretty?: boolean; // Default: true
77
- }
78
65
  // Type guards for better type safety
79
- function isParseResult(obj: any): obj is any {
66
+ function isParseResult(obj) {
80
67
  // A ParseResult is an object that could have stmts (but not required)
81
68
  // and is not already wrapped as a Node
82
69
  // IMPORTANT: ParseResult.stmts is "repeated RawStmt" in protobuf, meaning
@@ -89,9 +76,7 @@ function isParseResult(obj: any): obj is any {
89
76
  // Check if it looks like a ParseResult (has stmts or version)
90
77
  ('stmts' in obj || 'version' in obj);
91
78
  }
92
- function isWrappedParseResult(obj: any): obj is {
93
- ParseResult: any;
94
- } {
79
+ function isWrappedParseResult(obj) {
95
80
  return obj && typeof obj === 'object' && 'ParseResult' in obj;
96
81
  }
97
82
  /**
@@ -119,10 +104,10 @@ function isWrappedParseResult(obj: any): obj is {
119
104
  * The deparser automatically detects bare ParseResult objects for backward
120
105
  * compatibility and wraps them internally for consistent processing.
121
106
  */
122
- export class Deparser implements DeparserVisitor {
123
- private tree: any[];
124
- private options: DeparserOptions;
125
- constructor(tree: any | any[] | any, opts: DeparserOptions = {}) {
107
+ export class Deparser {
108
+ tree;
109
+ options;
110
+ constructor(tree, opts = {}) {
126
111
  // Set default options
127
112
  this.options = {
128
113
  functionDelimiter: '$$',
@@ -155,10 +140,10 @@ export class Deparser implements DeparserVisitor {
155
140
  * @param opts - Deparser options for formatting
156
141
  * @returns The deparsed SQL string
157
142
  */
158
- static deparse(query: any | any[] | any, opts: DeparserOptions = {}): string {
143
+ static deparse(query, opts = {}) {
159
144
  return new Deparser(query, opts).deparseQuery();
160
145
  }
161
- deparseQuery(): string {
146
+ deparseQuery() {
162
147
  const formatter = new SqlFormatter(this.options.newline, this.options.tab, this.options.pretty);
163
148
  const context = new DeparserContext({ formatter, prettyMode: this.options.pretty });
164
149
  return this.tree
@@ -176,14 +161,128 @@ export class Deparser implements DeparserVisitor {
176
161
  * @param body The function body to check
177
162
  * @returns The delimiter to use
178
163
  */
179
- private getFunctionDelimiter(body: string): string {
164
+ getFunctionDelimiter(body) {
180
165
  const delimiter = this.options.functionDelimiter || '$$';
181
166
  if (body.includes(delimiter)) {
182
167
  return this.options.functionDelimiterFallback || '$EOFCODE$';
183
168
  }
184
169
  return delimiter;
185
170
  }
186
- deparse(node: any, context?: DeparserContext): string | null {
171
+ /**
172
+ * Maps ObjectType enum values to their corresponding SQL keywords
173
+ * Used by AlterOwnerStmt, AlterObjectSchemaStmt, and other statements that need object type keywords
174
+ */
175
+ getObjectTypeKeyword(objectType) {
176
+ switch (objectType) {
177
+ case 'OBJECT_TABLE':
178
+ return 'TABLE';
179
+ case 'OBJECT_VIEW':
180
+ return 'VIEW';
181
+ case 'OBJECT_INDEX':
182
+ return 'INDEX';
183
+ case 'OBJECT_SEQUENCE':
184
+ return 'SEQUENCE';
185
+ case 'OBJECT_FUNCTION':
186
+ return 'FUNCTION';
187
+ case 'OBJECT_PROCEDURE':
188
+ return 'PROCEDURE';
189
+ case 'OBJECT_SCHEMA':
190
+ return 'SCHEMA';
191
+ case 'OBJECT_DATABASE':
192
+ return 'DATABASE';
193
+ case 'OBJECT_DOMAIN':
194
+ return 'DOMAIN';
195
+ case 'OBJECT_AGGREGATE':
196
+ return 'AGGREGATE';
197
+ case 'OBJECT_CONVERSION':
198
+ return 'CONVERSION';
199
+ case 'OBJECT_LANGUAGE':
200
+ return 'LANGUAGE';
201
+ case 'OBJECT_OPERATOR':
202
+ return 'OPERATOR';
203
+ case 'OBJECT_OPFAMILY':
204
+ return 'OPERATOR FAMILY';
205
+ case 'OBJECT_OPCLASS':
206
+ return 'OPERATOR CLASS';
207
+ case 'OBJECT_TSDICTIONARY':
208
+ return 'TEXT SEARCH DICTIONARY';
209
+ case 'OBJECT_TSCONFIGURATION':
210
+ return 'TEXT SEARCH CONFIGURATION';
211
+ case 'OBJECT_EVENT_TRIGGER':
212
+ return 'EVENT TRIGGER';
213
+ case 'OBJECT_FDW':
214
+ return 'FOREIGN DATA WRAPPER';
215
+ case 'OBJECT_FOREIGN_SERVER':
216
+ return 'SERVER';
217
+ case 'OBJECT_TYPE':
218
+ return 'TYPE';
219
+ case 'OBJECT_COLLATION':
220
+ return 'COLLATION';
221
+ case 'OBJECT_PUBLICATION':
222
+ return 'PUBLICATION';
223
+ case 'OBJECT_ACCESS_METHOD':
224
+ return 'ACCESS METHOD';
225
+ case 'OBJECT_AMOP':
226
+ return 'OPERATOR CLASS';
227
+ case 'OBJECT_AMPROC':
228
+ return 'OPERATOR CLASS';
229
+ case 'OBJECT_ATTRIBUTE':
230
+ return 'ATTRIBUTE';
231
+ case 'OBJECT_CAST':
232
+ return 'CAST';
233
+ case 'OBJECT_COLUMN':
234
+ return 'COLUMN';
235
+ case 'OBJECT_DEFAULT':
236
+ return 'DEFAULT';
237
+ case 'OBJECT_DEFACL':
238
+ return 'DEFAULT PRIVILEGES';
239
+ case 'OBJECT_DOMCONSTRAINT':
240
+ return 'DOMAIN';
241
+ case 'OBJECT_EXTENSION':
242
+ return 'EXTENSION';
243
+ case 'OBJECT_FOREIGN_TABLE':
244
+ return 'FOREIGN TABLE';
245
+ case 'OBJECT_LARGEOBJECT':
246
+ return 'LARGE OBJECT';
247
+ case 'OBJECT_MATVIEW':
248
+ return 'MATERIALIZED VIEW';
249
+ case 'OBJECT_PARAMETER_ACL':
250
+ return 'PARAMETER';
251
+ case 'OBJECT_POLICY':
252
+ return 'POLICY';
253
+ case 'OBJECT_PUBLICATION_NAMESPACE':
254
+ return 'PUBLICATION';
255
+ case 'OBJECT_PUBLICATION_REL':
256
+ return 'PUBLICATION';
257
+ case 'OBJECT_ROLE':
258
+ return 'ROLE';
259
+ case 'OBJECT_ROUTINE':
260
+ return 'ROUTINE';
261
+ case 'OBJECT_RULE':
262
+ return 'RULE';
263
+ case 'OBJECT_STATISTIC_EXT':
264
+ return 'STATISTICS';
265
+ case 'OBJECT_SUBSCRIPTION':
266
+ return 'SUBSCRIPTION';
267
+ case 'OBJECT_TABCONSTRAINT':
268
+ return 'CONSTRAINT';
269
+ case 'OBJECT_TABLESPACE':
270
+ return 'TABLESPACE';
271
+ case 'OBJECT_TRANSFORM':
272
+ return 'TRANSFORM';
273
+ case 'OBJECT_TRIGGER':
274
+ return 'TRIGGER';
275
+ case 'OBJECT_TSPARSER':
276
+ return 'TEXT SEARCH PARSER';
277
+ case 'OBJECT_TSTEMPLATE':
278
+ return 'TEXT SEARCH TEMPLATE';
279
+ case 'OBJECT_USER_MAPPING':
280
+ return 'USER MAPPING';
281
+ default:
282
+ throw new Error(`Unsupported objectType: ${objectType}`);
283
+ }
284
+ }
285
+ deparse(node, context) {
187
286
  if (node == null) {
188
287
  return null;
189
288
  }
@@ -199,10 +298,10 @@ export class Deparser implements DeparserVisitor {
199
298
  }
200
299
  catch (error) {
201
300
  const nodeType = Object.keys(node)[0];
202
- throw new Error(`Error deparsing ${nodeType}: ${(error as Error).message}`);
301
+ throw new Error(`Error deparsing ${nodeType}: ${error.message}`);
203
302
  }
204
303
  }
205
- visit(node: any, context?: DeparserContext): string {
304
+ visit(node, context) {
206
305
  if (!context) {
207
306
  const formatter = new SqlFormatter(this.options.newline, this.options.tab, this.options.pretty);
208
307
  context = new DeparserContext({ formatter, prettyMode: this.options.pretty });
@@ -213,24 +312,24 @@ export class Deparser implements DeparserVisitor {
213
312
  return '';
214
313
  }
215
314
  const nodeData = this.getNodeData(node);
216
- const methodName = nodeType as keyof this;
315
+ const methodName = nodeType;
217
316
  if (typeof this[methodName] === 'function') {
218
- const result = (this[methodName] as any)(nodeData, context);
317
+ const result = this[methodName](nodeData, context);
219
318
  return result;
220
319
  }
221
320
  throw new Error(`Deparser does not handle node type: ${nodeType}`);
222
321
  }
223
- getNodeType(node: any): string {
322
+ getNodeType(node) {
224
323
  return Object.keys(node)[0];
225
324
  }
226
- getNodeData(node: any): any {
325
+ getNodeData(node) {
227
326
  const keys = Object.keys(node);
228
- if (keys.length === 1 && typeof (node as any)[keys[0]] === 'object') {
229
- return (node as any)[keys[0]];
327
+ if (keys.length === 1 && typeof node[keys[0]] === 'object') {
328
+ return node[keys[0]];
230
329
  }
231
330
  return node;
232
331
  }
233
- ParseResult(node: any, context: DeparserContext): string {
332
+ ParseResult(node, context) {
234
333
  if (!node.stmts || node.stmts.length === 0) {
235
334
  return '';
236
335
  }
@@ -238,12 +337,12 @@ export class Deparser implements DeparserVisitor {
238
337
  // Note: node.stmts is "repeated RawStmt" so contains RawStmt objects inline
239
338
  // Each element has structure: { stmt: Node, stmt_len?: number, stmt_location?: number }
240
339
  return node.stmts
241
- .filter((rawStmt: any) => rawStmt != null)
242
- .map((rawStmt: any) => this.RawStmt(rawStmt, context))
243
- .filter((result: string) => result !== '')
340
+ .filter((rawStmt) => rawStmt != null)
341
+ .map((rawStmt) => this.RawStmt(rawStmt, context))
342
+ .filter((result) => result !== '')
244
343
  .join(context.newline() + context.newline());
245
344
  }
246
- RawStmt(node: any, context: DeparserContext): string {
345
+ RawStmt(node, context) {
247
346
  if (!node.stmt) {
248
347
  return '';
249
348
  }
@@ -254,8 +353,8 @@ export class Deparser implements DeparserVisitor {
254
353
  }
255
354
  return deparsedStmt;
256
355
  }
257
- SelectStmt(node: any, context: DeparserContext): string {
258
- const output: string[] = [];
356
+ SelectStmt(node, context) {
357
+ const output = [];
259
358
  if (node.withClause) {
260
359
  output.push(this.WithClause(node.withClause, context));
261
360
  }
@@ -518,8 +617,8 @@ export class Deparser implements DeparserVisitor {
518
617
  }
519
618
  return output.join(' ');
520
619
  }
521
- A_Expr(node: any, context: DeparserContext): string {
522
- const kind = node.kind as string;
620
+ A_Expr(node, context) {
621
+ const kind = node.kind;
523
622
  const name = ListUtils.unwrapList(node.name);
524
623
  const lexpr = node.lexpr;
525
624
  const rexpr = node.rexpr;
@@ -670,11 +769,11 @@ export class Deparser implements DeparserVisitor {
670
769
  }
671
770
  case 'AEXPR_SIMILAR':
672
771
  const similarOp = this.deparseOperatorName(name, context);
673
- let rightExpr: string;
772
+ let rightExpr;
674
773
  if (rexpr && 'FuncCall' in rexpr &&
675
774
  rexpr.FuncCall?.funcname?.length === 2 &&
676
- (rexpr.FuncCall.funcname[0] as any)?.String?.sval === 'pg_catalog' &&
677
- (rexpr.FuncCall.funcname[1] as any)?.String?.sval === 'similar_to_escape') {
775
+ rexpr.FuncCall.funcname[0]?.String?.sval === 'pg_catalog' &&
776
+ rexpr.FuncCall.funcname[1]?.String?.sval === 'similar_to_escape') {
678
777
  const args = rexpr.FuncCall.args || [];
679
778
  rightExpr = this.visit(args[0], context);
680
779
  if (args.length > 1) {
@@ -725,11 +824,11 @@ export class Deparser implements DeparserVisitor {
725
824
  }
726
825
  throw new Error(`Unhandled A_Expr kind: ${kind}`);
727
826
  }
728
- deparseOperatorName(name: any, context: DeparserContext): string {
827
+ deparseOperatorName(name, context) {
729
828
  if (!name || name.length === 0) {
730
829
  return '';
731
830
  }
732
- const parts = name.map((n: any) => {
831
+ const parts = name.map((n) => {
733
832
  if (n.String) {
734
833
  return n.String.sval || n.String.str;
735
834
  }
@@ -740,10 +839,8 @@ export class Deparser implements DeparserVisitor {
740
839
  }
741
840
  return parts.join('.');
742
841
  }
743
- private getOperatorPrecedence(operator: string): number {
744
- const precedence: {
745
- [key: string]: number;
746
- } = {
842
+ getOperatorPrecedence(operator) {
843
+ const precedence = {
747
844
  '||': 1, // string concatenation
748
845
  'OR': 2, // logical OR
749
846
  'AND': 3, // logical AND
@@ -776,7 +873,7 @@ export class Deparser implements DeparserVisitor {
776
873
  };
777
874
  return precedence[operator] || 0;
778
875
  }
779
- private needsParentheses(childOp: string, parentOp: string, position: 'left' | 'right'): boolean {
876
+ needsParentheses(childOp, parentOp, position) {
780
877
  const childPrec = this.getOperatorPrecedence(childOp);
781
878
  const parentPrec = this.getOperatorPrecedence(parentOp);
782
879
  if (childPrec < parentPrec) {
@@ -789,7 +886,7 @@ export class Deparser implements DeparserVisitor {
789
886
  }
790
887
  return false;
791
888
  }
792
- private isComplexExpression(node: any): boolean {
889
+ isComplexExpression(node) {
793
890
  return !!(node.NullTest ||
794
891
  node.BooleanTest ||
795
892
  node.BoolExpr ||
@@ -798,7 +895,7 @@ export class Deparser implements DeparserVisitor {
798
895
  node.SubLink ||
799
896
  node.A_Expr);
800
897
  }
801
- private isComplexSelectTarget(node: any): boolean {
898
+ isComplexSelectTarget(node) {
802
899
  if (!node)
803
900
  return false;
804
901
  if (node.ResTarget?.val) {
@@ -856,15 +953,15 @@ export class Deparser implements DeparserVisitor {
856
953
  }
857
954
  return false;
858
955
  }
859
- visitBetweenRange(rexpr: any, context: DeparserContext): string {
956
+ visitBetweenRange(rexpr, context) {
860
957
  if (rexpr && 'List' in rexpr && rexpr.List?.items) {
861
- const items = rexpr.List.items.map((item: any) => this.visit(item, context));
958
+ const items = rexpr.List.items.map((item) => this.visit(item, context));
862
959
  return items.join(' AND ');
863
960
  }
864
961
  return this.visit(rexpr, context);
865
962
  }
866
- InsertStmt(node: any, context: DeparserContext): string {
867
- const output: string[] = [];
963
+ InsertStmt(node, context) {
964
+ const output = [];
868
965
  if (node.withClause) {
869
966
  output.push(this.WithClause(node.withClause, context));
870
967
  }
@@ -945,8 +1042,8 @@ export class Deparser implements DeparserVisitor {
945
1042
  }
946
1043
  return output.join(' ');
947
1044
  }
948
- UpdateStmt(node: any, context: DeparserContext): string {
949
- const output: string[] = [];
1045
+ UpdateStmt(node, context) {
1046
+ const output = [];
950
1047
  if (node.withClause) {
951
1048
  output.push(this.WithClause(node.withClause, context));
952
1049
  }
@@ -1004,9 +1101,9 @@ export class Deparser implements DeparserVisitor {
1004
1101
  }
1005
1102
  return output.join(' ');
1006
1103
  }
1007
- DeleteStmt(node: any, context: DeparserContext): string {
1104
+ DeleteStmt(node, context) {
1008
1105
  try {
1009
- const output: string[] = [];
1106
+ const output = [];
1010
1107
  if (node.withClause) {
1011
1108
  try {
1012
1109
  output.push(this.WithClause(node.withClause, context));
@@ -1067,8 +1164,8 @@ export class Deparser implements DeparserVisitor {
1067
1164
  throw new Error(`Error deparsing DeleteStmt: ${error instanceof Error ? error.message : String(error)}`);
1068
1165
  }
1069
1166
  }
1070
- WithClause(node: any, context: DeparserContext): string {
1071
- const output: string[] = ['WITH'];
1167
+ WithClause(node, context) {
1168
+ const output = ['WITH'];
1072
1169
  if (node.recursive) {
1073
1170
  output.push('RECURSIVE');
1074
1171
  }
@@ -1092,8 +1189,8 @@ export class Deparser implements DeparserVisitor {
1092
1189
  }
1093
1190
  return output.join(' ');
1094
1191
  }
1095
- ResTarget(node: any, context: DeparserContext): string {
1096
- const output: string[] = [];
1192
+ ResTarget(node, context) {
1193
+ const output = [];
1097
1194
  if (context.update && node.name) {
1098
1195
  output.push(QuoteUtils.quote(node.name));
1099
1196
  // Handle indirection (array indexing, field access, etc.)
@@ -1135,14 +1232,14 @@ export class Deparser implements DeparserVisitor {
1135
1232
  }
1136
1233
  return output.join(' ');
1137
1234
  }
1138
- deparseReturningList(list: any, context: DeparserContext): string {
1235
+ deparseReturningList(list, context) {
1139
1236
  return ListUtils.unwrapList(list)
1140
1237
  .filter(item => item != null && this.getNodeType(item) !== 'undefined')
1141
1238
  .map(item => {
1142
1239
  try {
1143
1240
  // Handle ResTarget wrapper
1144
1241
  if (this.getNodeType(item) === 'ResTarget') {
1145
- const resTarget = this.getNodeData(item) as any;
1242
+ const resTarget = this.getNodeData(item);
1146
1243
  const val = resTarget.val ? this.visit(resTarget.val, context) : '';
1147
1244
  const alias = resTarget.name ? ` AS ${QuoteUtils.quote(resTarget.name)}` : '';
1148
1245
  return val + alias;
@@ -1160,8 +1257,8 @@ export class Deparser implements DeparserVisitor {
1160
1257
  .filter(item => item && item.trim())
1161
1258
  .join(', ');
1162
1259
  }
1163
- BoolExpr(node: any, context: DeparserContext): string {
1164
- const boolop = node.boolop as string;
1260
+ BoolExpr(node, context) {
1261
+ const boolop = node.boolop;
1165
1262
  const args = ListUtils.unwrapList(node.args);
1166
1263
  let formatStr = '%s';
1167
1264
  if (context.bool) {
@@ -1196,7 +1293,7 @@ export class Deparser implements DeparserVisitor {
1196
1293
  throw new Error(`Unhandled BoolExpr boolop: ${boolop}`);
1197
1294
  }
1198
1295
  }
1199
- FuncCall(node: any, context: DeparserContext): string {
1296
+ FuncCall(node, context) {
1200
1297
  const funcname = ListUtils.unwrapList(node.funcname);
1201
1298
  const args = ListUtils.unwrapList(node.args);
1202
1299
  const name = funcname.map(n => this.visit(n, context)).join('.');
@@ -1321,7 +1418,7 @@ export class Deparser implements DeparserVisitor {
1321
1418
  }
1322
1419
  return `${timestamp} AT TIME ZONE ${timezone}`;
1323
1420
  }
1324
- const params: string[] = [];
1421
+ const params = [];
1325
1422
  if (node.agg_star) {
1326
1423
  if (node.agg_distinct) {
1327
1424
  params.push('DISTINCT *');
@@ -1374,7 +1471,7 @@ export class Deparser implements DeparserVisitor {
1374
1471
  result += ` OVER ${node.over.name}`;
1375
1472
  }
1376
1473
  else {
1377
- const windowParts: string[] = [];
1474
+ const windowParts = [];
1378
1475
  if (node.over.partitionClause) {
1379
1476
  const partitions = ListUtils.unwrapList(node.over.partitionClause);
1380
1477
  const partitionStrs = partitions.map(p => this.visit(p, context));
@@ -1406,13 +1503,13 @@ export class Deparser implements DeparserVisitor {
1406
1503
  }
1407
1504
  return result;
1408
1505
  }
1409
- FuncExpr(node: any, context: DeparserContext): string {
1506
+ FuncExpr(node, context) {
1410
1507
  const funcName = `func_${node.funcid}`;
1411
1508
  const args = node.args ? ListUtils.unwrapList(node.args).map(arg => this.visit(arg, context)).join(', ') : '';
1412
1509
  return `${funcName}(${args})`;
1413
1510
  }
1414
- A_Const(node: any, context: DeparserContext): string {
1415
- const nodeAny = node as any;
1511
+ A_Const(node, context) {
1512
+ const nodeAny = node;
1416
1513
  if (nodeAny.ival !== undefined) {
1417
1514
  if (typeof nodeAny.ival === 'object' && nodeAny.ival !== null) {
1418
1515
  if (nodeAny.ival.ival !== undefined) {
@@ -1577,7 +1674,7 @@ export class Deparser implements DeparserVisitor {
1577
1674
  }
1578
1675
  return 'NULL';
1579
1676
  }
1580
- ColumnRef(node: any, context: DeparserContext): string {
1677
+ ColumnRef(node, context) {
1581
1678
  const fields = ListUtils.unwrapList(node.fields);
1582
1679
  return fields.map(field => {
1583
1680
  if (field.String) {
@@ -1589,16 +1686,16 @@ export class Deparser implements DeparserVisitor {
1589
1686
  return this.visit(field, context);
1590
1687
  }).join('.');
1591
1688
  }
1592
- TypeName(node: any, context: DeparserContext): string {
1689
+ TypeName(node, context) {
1593
1690
  if (!node.names) {
1594
1691
  return '';
1595
1692
  }
1596
- const output: string[] = [];
1693
+ const output = [];
1597
1694
  // Handle SETOF keyword
1598
1695
  if (node.setof) {
1599
1696
  output.push('SETOF');
1600
1697
  }
1601
- const names = node.names.map((name: any) => {
1698
+ const names = node.names.map((name) => {
1602
1699
  if (name.String) {
1603
1700
  return name.String.sval || name.String.str;
1604
1701
  }
@@ -1607,9 +1704,9 @@ export class Deparser implements DeparserVisitor {
1607
1704
  if (names.length === 0) {
1608
1705
  return '';
1609
1706
  }
1610
- let args: string | null = null;
1707
+ let args = null;
1611
1708
  if (node.typmods) {
1612
- const isInterval = names.some((name: any) => {
1709
+ const isInterval = names.some((name) => {
1613
1710
  const nameStr = typeof name === 'string' ? name : (name.String?.sval || name.String?.str);
1614
1711
  return nameStr === 'interval';
1615
1712
  });
@@ -1624,7 +1721,7 @@ export class Deparser implements DeparserVisitor {
1624
1721
  else if (node.typemod && node.typemod !== -1) {
1625
1722
  args = this.formatSingleTypeMod(node.typemod, names[0]);
1626
1723
  }
1627
- const mods = (name: string, size: string | null) => {
1724
+ const mods = (name, size) => {
1628
1725
  if (size != null) {
1629
1726
  // For interval types, use space separation for fields in all contexts
1630
1727
  if (name === 'interval') {
@@ -1639,7 +1736,7 @@ export class Deparser implements DeparserVisitor {
1639
1736
  }
1640
1737
  return name;
1641
1738
  };
1642
- const formatArrayBounds = (arrayBounds: any[]): string => {
1739
+ const formatArrayBounds = (arrayBounds) => {
1643
1740
  return arrayBounds.map(bound => {
1644
1741
  if (bound.Integer && bound.Integer.ival !== undefined && bound.Integer.ival !== -1) {
1645
1742
  return `[${bound.Integer.ival}]`;
@@ -1755,7 +1852,7 @@ export class Deparser implements DeparserVisitor {
1755
1852
  return output.join(' ');
1756
1853
  }
1757
1854
  }
1758
- const quotedNames = names.map((name: string) => QuoteUtils.quote(name));
1855
+ const quotedNames = names.map((name) => QuoteUtils.quote(name));
1759
1856
  let result = mods(quotedNames.join('.'), args);
1760
1857
  if (node.arrayBounds && node.arrayBounds.length > 0) {
1761
1858
  result += formatArrayBounds(node.arrayBounds);
@@ -1763,9 +1860,9 @@ export class Deparser implements DeparserVisitor {
1763
1860
  output.push(result);
1764
1861
  return output.join(' ');
1765
1862
  }
1766
- Alias(node: any, context: DeparserContext): string {
1863
+ Alias(node, context) {
1767
1864
  const name = node.aliasname;
1768
- const output: string[] = [];
1865
+ const output = [];
1769
1866
  if (node.colnames) {
1770
1867
  const colnames = ListUtils.unwrapList(node.colnames);
1771
1868
  const quotedColnames = colnames.map(col => {
@@ -1783,8 +1880,8 @@ export class Deparser implements DeparserVisitor {
1783
1880
  }
1784
1881
  return output.join(' ');
1785
1882
  }
1786
- RangeVar(node: any, context: DeparserContext): string {
1787
- const output: string[] = [];
1883
+ RangeVar(node, context) {
1884
+ const output = [];
1788
1885
  // Handle ONLY keyword for inheritance control (but not for type definitions, ALTER TYPE, or CREATE FOREIGN TABLE)
1789
1886
  if (node && (!('inh' in node) || node.inh === undefined) &&
1790
1887
  !context.parentNodeTypes.includes('CompositeTypeStmt') &&
@@ -1814,14 +1911,12 @@ export class Deparser implements DeparserVisitor {
1814
1911
  const result = output.join(' ');
1815
1912
  return result;
1816
1913
  }
1817
- formatIntervalTypeMods(typmods: any, context: DeparserContext): string | null {
1914
+ formatIntervalTypeMods(typmods, context) {
1818
1915
  if (!typmods || typmods.length === 0) {
1819
1916
  return null;
1820
1917
  }
1821
1918
  const mods = ListUtils.unwrapList(typmods);
1822
- const intervalFields: {
1823
- [key: number]: string;
1824
- } = {
1919
+ const intervalFields = {
1825
1920
  4: 'year',
1826
1921
  2: 'month',
1827
1922
  8: 'day',
@@ -1840,7 +1935,7 @@ export class Deparser implements DeparserVisitor {
1840
1935
  if (mods.length === 1) {
1841
1936
  const mod = mods[0];
1842
1937
  if (mod && typeof mod === 'object') {
1843
- const aConst = (mod as any).A_Const;
1938
+ const aConst = mod.A_Const;
1844
1939
  if (aConst && aConst.ival !== undefined) {
1845
1940
  const ivalValue = typeof aConst.ival === 'object' ? aConst.ival.ival : aConst.ival;
1846
1941
  if (ivalValue !== undefined) {
@@ -1858,12 +1953,12 @@ export class Deparser implements DeparserVisitor {
1858
1953
  const firstMod = mods[0];
1859
1954
  const secondMod = mods[1];
1860
1955
  if (firstMod && typeof firstMod === 'object') {
1861
- const firstConst = (firstMod as any).A_Const;
1956
+ const firstConst = firstMod.A_Const;
1862
1957
  if (firstConst && firstConst.ival !== undefined) {
1863
1958
  const firstValue = typeof firstConst.ival === 'object' ? firstConst.ival.ival : firstConst.ival;
1864
1959
  // Check if second mod is precision (empty ival object or specific precision value)
1865
1960
  if (secondMod && typeof secondMod === 'object') {
1866
- const secondConst = (secondMod as any).A_Const;
1961
+ const secondConst = secondMod.A_Const;
1867
1962
  if (secondConst && secondConst.ival !== undefined) {
1868
1963
  const secondValue = typeof secondConst.ival === 'object' ?
1869
1964
  (secondConst.ival.ival !== undefined ? secondConst.ival.ival : 0) :
@@ -1881,7 +1976,7 @@ export class Deparser implements DeparserVisitor {
1881
1976
  }
1882
1977
  const fieldSpecs = mods.map(mod => {
1883
1978
  if (mod && typeof mod === 'object') {
1884
- const aConst = (mod as any).A_Const;
1979
+ const aConst = mod.A_Const;
1885
1980
  if (aConst && aConst.ival !== undefined) {
1886
1981
  const ivalValue = typeof aConst.ival === 'object' ? aConst.ival.ival : aConst.ival;
1887
1982
  if (ivalValue !== undefined) {
@@ -1894,14 +1989,14 @@ export class Deparser implements DeparserVisitor {
1894
1989
  }).filter(Boolean);
1895
1990
  return fieldSpecs.length > 0 ? fieldSpecs.join(' ') : null;
1896
1991
  }
1897
- formatTypeMods(typmods: any, context: DeparserContext): string | null {
1992
+ formatTypeMods(typmods, context) {
1898
1993
  if (!typmods || typmods.length === 0) {
1899
1994
  return null;
1900
1995
  }
1901
1996
  const mods = ListUtils.unwrapList(typmods);
1902
1997
  const filteredMods = mods.filter(mod => {
1903
1998
  if (mod && typeof mod === 'object') {
1904
- const aConst = (mod as any).A_Const;
1999
+ const aConst = mod.A_Const;
1905
2000
  if (aConst && aConst.ival) {
1906
2001
  // Handle both direct number and nested object structures
1907
2002
  const ivalValue = typeof aConst.ival === 'object' ? aConst.ival.ival : aConst.ival;
@@ -1919,7 +2014,7 @@ export class Deparser implements DeparserVisitor {
1919
2014
  return this.deparse(mod, context);
1920
2015
  }).join(', ');
1921
2016
  }
1922
- formatSingleTypeMod(typemod: number, typeName: string): string | null {
2017
+ formatSingleTypeMod(typemod, typeName) {
1923
2018
  switch (typeName) {
1924
2019
  case 'varchar':
1925
2020
  case 'bpchar':
@@ -1954,7 +2049,7 @@ export class Deparser implements DeparserVisitor {
1954
2049
  }
1955
2050
  return null;
1956
2051
  }
1957
- getPgCatalogTypeName(typeName: string, size: string | null): string {
2052
+ getPgCatalogTypeName(typeName, size) {
1958
2053
  switch (typeName) {
1959
2054
  case 'bpchar':
1960
2055
  if (size != null) {
@@ -1987,7 +2082,7 @@ export class Deparser implements DeparserVisitor {
1987
2082
  return `pg_catalog.${typeName}`;
1988
2083
  }
1989
2084
  }
1990
- isPgCatalogType(typeName: string): boolean {
2085
+ isPgCatalogType(typeName) {
1991
2086
  const cleanTypeName = typeName.replace(/^pg_catalog\./, '');
1992
2087
  if (pgCatalogTypes.includes(cleanTypeName)) {
1993
2088
  return true;
@@ -1999,13 +2094,13 @@ export class Deparser implements DeparserVisitor {
1999
2094
  }
2000
2095
  return false;
2001
2096
  }
2002
- A_ArrayExpr(node: any, context: DeparserContext): string {
2097
+ A_ArrayExpr(node, context) {
2003
2098
  const elements = ListUtils.unwrapList(node.elements);
2004
2099
  const elementStrs = elements.map(el => this.visit(el, context));
2005
2100
  return `ARRAY[${elementStrs.join(', ')}]`;
2006
2101
  }
2007
- A_Indices(node: any, context: DeparserContext): string {
2008
- const output: string[] = [];
2102
+ A_Indices(node, context) {
2103
+ const output = [];
2009
2104
  if (node.is_slice) {
2010
2105
  if (node.lidx) {
2011
2106
  output.push(this.visit(node.lidx, context));
@@ -2022,7 +2117,7 @@ export class Deparser implements DeparserVisitor {
2022
2117
  }
2023
2118
  return `[${output.join('')}]`;
2024
2119
  }
2025
- A_Indirection(node: any, context: DeparserContext): string {
2120
+ A_Indirection(node, context) {
2026
2121
  let argStr = this.visit(node.arg, context);
2027
2122
  const argType = this.getNodeType(node.arg);
2028
2123
  if (argType === 'TypeCast' || argType === 'SubLink' || argType === 'A_Expr' || argType === 'FuncCall' || argType === 'A_Indirection' || argType === 'ColumnRef' || argType === 'RowExpr') {
@@ -2041,11 +2136,11 @@ export class Deparser implements DeparserVisitor {
2041
2136
  }
2042
2137
  return output.join('');
2043
2138
  }
2044
- A_Star(node: any, context: DeparserContext): string {
2139
+ A_Star(node, context) {
2045
2140
  return '*';
2046
2141
  }
2047
- CaseExpr(node: any, context: DeparserContext): string {
2048
- const output: string[] = ['CASE'];
2142
+ CaseExpr(node, context) {
2143
+ const output = ['CASE'];
2049
2144
  if (node.arg) {
2050
2145
  output.push(this.visit(node.arg, context));
2051
2146
  }
@@ -2084,20 +2179,20 @@ export class Deparser implements DeparserVisitor {
2084
2179
  return output.join(' ');
2085
2180
  }
2086
2181
  }
2087
- CoalesceExpr(node: any, context: DeparserContext): string {
2182
+ CoalesceExpr(node, context) {
2088
2183
  const args = ListUtils.unwrapList(node.args);
2089
2184
  const argStrs = args.map(arg => this.visit(arg, context));
2090
2185
  return `COALESCE(${argStrs.join(', ')})`;
2091
2186
  }
2092
- TypeCast(node: any, context: DeparserContext): string {
2187
+ TypeCast(node, context) {
2093
2188
  const arg = this.visit(node.arg, context);
2094
2189
  const typeName = this.TypeName(node.typeName, context);
2095
2190
  // Check if this is a bpchar typecast that should preserve original syntax for AST consistency
2096
2191
  if (typeName === 'bpchar' || typeName === 'pg_catalog.bpchar') {
2097
2192
  const names = node.typeName?.names;
2098
2193
  const isQualifiedBpchar = names && names.length === 2 &&
2099
- (names[0] as any)?.String?.sval === 'pg_catalog' &&
2100
- (names[1] as any)?.String?.sval === 'bpchar';
2194
+ names[0]?.String?.sval === 'pg_catalog' &&
2195
+ names[1]?.String?.sval === 'bpchar';
2101
2196
  if (isQualifiedBpchar) {
2102
2197
  return `CAST(${arg} AS ${typeName})`;
2103
2198
  }
@@ -2108,18 +2203,21 @@ export class Deparser implements DeparserVisitor {
2108
2203
  const isFunctionCall = argType === 'FuncCall';
2109
2204
  if (isSimpleArgument || isFunctionCall) {
2110
2205
  // For simple arguments, avoid :: syntax if they have complex structure
2111
- if (isSimpleArgument && (arg.includes('(') || arg.startsWith('-'))) {
2112
- }
2113
- else {
2206
+ const shouldUseCastSyntax = isSimpleArgument && (arg.includes('(') || arg.startsWith('-'));
2207
+ if (!shouldUseCastSyntax) {
2114
2208
  const cleanTypeName = typeName.replace('pg_catalog.', '');
2209
+ // Wrap FuncCall arguments in parentheses to prevent operator precedence issues
2210
+ if (isFunctionCall) {
2211
+ return `${context.parens(arg)}::${cleanTypeName}`;
2212
+ }
2115
2213
  return `${arg}::${cleanTypeName}`;
2116
2214
  }
2117
2215
  }
2118
2216
  }
2119
2217
  return `CAST(${arg} AS ${typeName})`;
2120
2218
  }
2121
- CollateClause(node: any, context: DeparserContext): string {
2122
- const output: string[] = [];
2219
+ CollateClause(node, context) {
2220
+ const output = [];
2123
2221
  if (node.arg) {
2124
2222
  let argStr = this.visit(node.arg, context);
2125
2223
  const argType = this.getNodeType(node.arg);
@@ -2135,11 +2233,11 @@ export class Deparser implements DeparserVisitor {
2135
2233
  }
2136
2234
  return output.join(' ');
2137
2235
  }
2138
- BooleanTest(node: any, context: DeparserContext): string {
2139
- const output: string[] = [];
2236
+ BooleanTest(node, context) {
2237
+ const output = [];
2140
2238
  const boolContext = context.spawn('BooleanTest', { bool: true });
2141
2239
  output.push(this.visit(node.arg, boolContext));
2142
- switch (node.booltesttype as string) {
2240
+ switch (node.booltesttype) {
2143
2241
  case 'IS_TRUE':
2144
2242
  output.push('IS TRUE');
2145
2243
  break;
@@ -2161,10 +2259,10 @@ export class Deparser implements DeparserVisitor {
2161
2259
  }
2162
2260
  return output.join(' ');
2163
2261
  }
2164
- NullTest(node: any, context: DeparserContext): string {
2165
- const output: string[] = [];
2262
+ NullTest(node, context) {
2263
+ const output = [];
2166
2264
  output.push(this.visit(node.arg, context));
2167
- switch (node.nulltesttype as string) {
2265
+ switch (node.nulltesttype) {
2168
2266
  case 'IS_NULL':
2169
2267
  output.push('IS NULL');
2170
2268
  break;
@@ -2174,7 +2272,7 @@ export class Deparser implements DeparserVisitor {
2174
2272
  }
2175
2273
  return output.join(' ');
2176
2274
  }
2177
- private static readonly RESERVED_WORDS = new Set([
2275
+ static RESERVED_WORDS = new Set([
2178
2276
  'all', 'analyse', 'analyze', 'and', 'any', 'array', 'as', 'asc', 'asymmetric', 'both',
2179
2277
  'case', 'cast', 'check', 'collate', 'column', 'constraint', 'create', 'current_catalog',
2180
2278
  'current_date', 'current_role', 'current_time', 'current_timestamp', 'current_user',
@@ -2186,7 +2284,7 @@ export class Deparser implements DeparserVisitor {
2186
2284
  'then', 'to', 'trailing', 'true', 'union', 'unique', 'user', 'using', 'variadic',
2187
2285
  'when', 'where', 'window', 'with'
2188
2286
  ]);
2189
- private static needsQuotes(value: string): boolean {
2287
+ static needsQuotes(value) {
2190
2288
  if (!value)
2191
2289
  return false;
2192
2290
  const needsQuotesRegex = /[a-z]+[\W\w]*[A-Z]+|[A-Z]+[\W\w]*[a-z]+|\W/;
@@ -2195,16 +2293,14 @@ export class Deparser implements DeparserVisitor {
2195
2293
  Deparser.RESERVED_WORDS.has(value.toLowerCase()) ||
2196
2294
  isAllUppercase;
2197
2295
  }
2198
- quoteIfNeeded(value: string): string {
2296
+ quoteIfNeeded(value) {
2199
2297
  if (Deparser.needsQuotes(value)) {
2200
2298
  return `"${value}"`;
2201
2299
  }
2202
2300
  return value;
2203
2301
  }
2204
- preserveOperatorDefElemCase(defName: string): string {
2205
- const caseMap: {
2206
- [key: string]: string;
2207
- } = {
2302
+ preserveOperatorDefElemCase(defName) {
2303
+ const caseMap = {
2208
2304
  'leftarg': 'Leftarg',
2209
2305
  'rightarg': 'Rightarg',
2210
2306
  'procedure': 'Procedure',
@@ -2218,7 +2314,7 @@ export class Deparser implements DeparserVisitor {
2218
2314
  };
2219
2315
  return caseMap[defName.toLowerCase()] || defName;
2220
2316
  }
2221
- String(node: any, context: DeparserContext): string {
2317
+ String(node, context) {
2222
2318
  if (context.isStringLiteral || context.isEnumValue) {
2223
2319
  return QuoteUtils.formatEString(node.sval || '');
2224
2320
  }
@@ -2236,16 +2332,16 @@ export class Deparser implements DeparserVisitor {
2236
2332
  }
2237
2333
  return Deparser.needsQuotes(value) ? `"${value}"` : value;
2238
2334
  }
2239
- Integer(node: any, context: DeparserContext): string {
2335
+ Integer(node, context) {
2240
2336
  return node.ival?.toString() || '0';
2241
2337
  }
2242
- Float(node: any, context: DeparserContext): string {
2338
+ Float(node, context) {
2243
2339
  return node.fval || '0.0';
2244
2340
  }
2245
- Boolean(node: any, context: DeparserContext): string {
2341
+ Boolean(node, context) {
2246
2342
  return node.boolval ? 'true' : 'false';
2247
2343
  }
2248
- BitString(node: any, context: DeparserContext): string {
2344
+ BitString(node, context) {
2249
2345
  // Check if this is a hexadecimal bit string (starts with x)
2250
2346
  if (node.bsval.startsWith('x')) {
2251
2347
  return `x'${node.bsval.substring(1)}'`;
@@ -2256,17 +2352,17 @@ export class Deparser implements DeparserVisitor {
2256
2352
  // Fallback for raw values without prefix
2257
2353
  return `b'${node.bsval}'`;
2258
2354
  }
2259
- Null(node: any, context: DeparserContext): string {
2355
+ Null(node, context) {
2260
2356
  return 'NULL';
2261
2357
  }
2262
- List(node: any, context: DeparserContext): string {
2358
+ List(node, context) {
2263
2359
  if (!node.items || node.items.length === 0) {
2264
2360
  return '';
2265
2361
  }
2266
- return node.items.map((item: any) => this.visit(item, context)).join(', ');
2362
+ return node.items.map((item) => this.visit(item, context)).join(', ');
2267
2363
  }
2268
- CreateStmt(node: any, context: DeparserContext): string {
2269
- const output: string[] = ['CREATE'];
2364
+ CreateStmt(node, context) {
2365
+ const output = ['CREATE'];
2270
2366
  if (node.relation && node.relation.relpersistence === 't') {
2271
2367
  output.push('TEMPORARY');
2272
2368
  }
@@ -2396,7 +2492,7 @@ export class Deparser implements DeparserVisitor {
2396
2492
  // Handle table options like WITH (fillfactor=10)
2397
2493
  if (node.options && node.options.length > 0) {
2398
2494
  const createStmtContext = context.spawn('CreateStmt');
2399
- const optionStrs = node.options.map((option: any) => {
2495
+ const optionStrs = node.options.map((option) => {
2400
2496
  return this.deparse(option, createStmtContext);
2401
2497
  });
2402
2498
  output.push('WITH', `(${optionStrs.join(', ')})`);
@@ -2408,8 +2504,8 @@ export class Deparser implements DeparserVisitor {
2408
2504
  }
2409
2505
  return output.join(' ');
2410
2506
  }
2411
- ColumnDef(node: any, context: DeparserContext): string {
2412
- const output: string[] = [];
2507
+ ColumnDef(node, context) {
2508
+ const output = [];
2413
2509
  if (node.colname) {
2414
2510
  output.push(QuoteUtils.quote(node.colname));
2415
2511
  }
@@ -2447,8 +2543,8 @@ export class Deparser implements DeparserVisitor {
2447
2543
  }
2448
2544
  return output.join(' ');
2449
2545
  }
2450
- Constraint(node: any, context: DeparserContext): string {
2451
- const output: string[] = [];
2546
+ Constraint(node, context) {
2547
+ const output = [];
2452
2548
  // Handle constraint name if present
2453
2549
  if (node.conname && (node.contype === 'CONSTR_CHECK' || node.contype === 'CONSTR_UNIQUE' || node.contype === 'CONSTR_PRIMARY' || node.contype === 'CONSTR_FOREIGN')) {
2454
2550
  output.push('CONSTRAINT');
@@ -2845,7 +2941,7 @@ export class Deparser implements DeparserVisitor {
2845
2941
  }
2846
2942
  return output.join(' ');
2847
2943
  }
2848
- SubLink(node: any, context: DeparserContext): string {
2944
+ SubLink(node, context) {
2849
2945
  const subselect = context.parens(this.visit(node.subselect, context));
2850
2946
  switch (node.subLinkType) {
2851
2947
  case 'ANY_SUBLINK':
@@ -2875,8 +2971,8 @@ export class Deparser implements DeparserVisitor {
2875
2971
  return subselect;
2876
2972
  }
2877
2973
  }
2878
- CaseWhen(node: any, context: DeparserContext): string {
2879
- const output: string[] = ['WHEN'];
2974
+ CaseWhen(node, context) {
2975
+ const output = ['WHEN'];
2880
2976
  if (node.expr) {
2881
2977
  output.push(this.visit(node.expr, context));
2882
2978
  }
@@ -2886,12 +2982,12 @@ export class Deparser implements DeparserVisitor {
2886
2982
  }
2887
2983
  return output.join(' ');
2888
2984
  }
2889
- WindowDef(node: any, context: DeparserContext): string {
2890
- const output: string[] = [];
2985
+ WindowDef(node, context) {
2986
+ const output = [];
2891
2987
  if (node.name) {
2892
2988
  output.push(node.name);
2893
2989
  }
2894
- const windowParts: string[] = [];
2990
+ const windowParts = [];
2895
2991
  if (node.partitionClause) {
2896
2992
  const partitions = ListUtils.unwrapList(node.partitionClause);
2897
2993
  const partitionStrs = partitions.map(p => this.visit(p, context));
@@ -2924,11 +3020,11 @@ export class Deparser implements DeparserVisitor {
2924
3020
  }
2925
3021
  return output.join(' ');
2926
3022
  }
2927
- formatWindowFrame(node: any, context: DeparserContext): string | null {
3023
+ formatWindowFrame(node, context) {
2928
3024
  if (!node.frameOptions)
2929
3025
  return null;
2930
3026
  const frameOptions = node.frameOptions;
2931
- const frameParts: string[] = [];
3027
+ const frameParts = [];
2932
3028
  if (frameOptions & 0x01) { // FRAMEOPTION_NONDEFAULT
2933
3029
  if (frameOptions & 0x02) { // FRAMEOPTION_RANGE
2934
3030
  frameParts.push('RANGE');
@@ -2942,7 +3038,7 @@ export class Deparser implements DeparserVisitor {
2942
3038
  }
2943
3039
  if (frameParts.length === 0)
2944
3040
  return null;
2945
- const boundsParts: string[] = [];
3041
+ const boundsParts = [];
2946
3042
  // Handle specific frameOptions values that have known mappings
2947
3043
  if (frameOptions === 789) {
2948
3044
  boundsParts.push('CURRENT ROW');
@@ -3024,8 +3120,8 @@ export class Deparser implements DeparserVisitor {
3024
3120
  }
3025
3121
  return frameParts.join(' ');
3026
3122
  }
3027
- SortBy(node: any, context: DeparserContext): string {
3028
- const output: string[] = [];
3123
+ SortBy(node, context) {
3124
+ const output = [];
3029
3125
  if (node.node) {
3030
3126
  output.push(this.visit(node.node, context));
3031
3127
  }
@@ -3053,7 +3149,7 @@ export class Deparser implements DeparserVisitor {
3053
3149
  }
3054
3150
  return output.join(' ');
3055
3151
  }
3056
- GroupingSet(node: any, context: DeparserContext): string {
3152
+ GroupingSet(node, context) {
3057
3153
  switch (node.kind) {
3058
3154
  case 'GROUPING_SET_EMPTY':
3059
3155
  return '()';
@@ -3076,8 +3172,8 @@ export class Deparser implements DeparserVisitor {
3076
3172
  return '';
3077
3173
  }
3078
3174
  }
3079
- CommonTableExpr(node: any, context: DeparserContext): string {
3080
- const output: string[] = [];
3175
+ CommonTableExpr(node, context) {
3176
+ const output = [];
3081
3177
  if (node.ctename) {
3082
3178
  output.push(node.ctename);
3083
3179
  }
@@ -3100,11 +3196,11 @@ export class Deparser implements DeparserVisitor {
3100
3196
  }
3101
3197
  return output.join(' ');
3102
3198
  }
3103
- ParamRef(node: any, context: DeparserContext): string {
3199
+ ParamRef(node, context) {
3104
3200
  return `$${node.number}`;
3105
3201
  }
3106
- LockingClause(node: any, context: DeparserContext): string {
3107
- const output: string[] = [];
3202
+ LockingClause(node, context) {
3203
+ const output = [];
3108
3204
  switch (node.strength) {
3109
3205
  case 'LCS_FORUPDATE':
3110
3206
  output.push('FOR UPDATE');
@@ -3136,7 +3232,7 @@ export class Deparser implements DeparserVisitor {
3136
3232
  }
3137
3233
  return output.join(' ');
3138
3234
  }
3139
- MinMaxExpr(node: any, context: DeparserContext): string {
3235
+ MinMaxExpr(node, context) {
3140
3236
  const args = ListUtils.unwrapList(node.args);
3141
3237
  const argStrs = args.map(arg => this.visit(arg, context));
3142
3238
  if (node.op === 'IS_GREATEST') {
@@ -3146,7 +3242,7 @@ export class Deparser implements DeparserVisitor {
3146
3242
  return `LEAST(${argStrs.join(', ')})`;
3147
3243
  }
3148
3244
  }
3149
- RowExpr(node: any, context: DeparserContext): string {
3245
+ RowExpr(node, context) {
3150
3246
  const args = ListUtils.unwrapList(node.args);
3151
3247
  const argStrs = args.map(arg => this.visit(arg, context));
3152
3248
  if (node.row_format === 'COERCE_IMPLICIT_CAST') {
@@ -3154,7 +3250,7 @@ export class Deparser implements DeparserVisitor {
3154
3250
  }
3155
3251
  return `ROW(${argStrs.join(', ')})`;
3156
3252
  }
3157
- OpExpr(node: any, context: DeparserContext): string {
3253
+ OpExpr(node, context) {
3158
3254
  const args = ListUtils.unwrapList(node.args);
3159
3255
  if (args.length === 2) {
3160
3256
  const left = this.visit(args[0], context);
@@ -3169,7 +3265,7 @@ export class Deparser implements DeparserVisitor {
3169
3265
  }
3170
3266
  throw new Error(`Unsupported OpExpr with ${args.length} arguments`);
3171
3267
  }
3172
- DistinctExpr(node: any, context: DeparserContext): string {
3268
+ DistinctExpr(node, context) {
3173
3269
  const args = ListUtils.unwrapList(node.args);
3174
3270
  if (args.length === 2) {
3175
3271
  const literalContext = context.spawn('DistinctExpr', { isStringLiteral: true });
@@ -3179,7 +3275,7 @@ export class Deparser implements DeparserVisitor {
3179
3275
  }
3180
3276
  throw new Error(`DistinctExpr requires exactly 2 arguments, got ${args.length}`);
3181
3277
  }
3182
- NullIfExpr(node: any, context: DeparserContext): string {
3278
+ NullIfExpr(node, context) {
3183
3279
  const args = ListUtils.unwrapList(node.args);
3184
3280
  if (args.length === 2) {
3185
3281
  const literalContext = context.spawn('NullIfExpr', { isStringLiteral: true });
@@ -3189,7 +3285,7 @@ export class Deparser implements DeparserVisitor {
3189
3285
  }
3190
3286
  throw new Error(`NullIfExpr requires exactly 2 arguments, got ${args.length}`);
3191
3287
  }
3192
- ScalarArrayOpExpr(node: any, context: DeparserContext): string {
3288
+ ScalarArrayOpExpr(node, context) {
3193
3289
  const args = ListUtils.unwrapList(node.args);
3194
3290
  if (args.length === 2) {
3195
3291
  const left = this.visit(args[0], context);
@@ -3200,7 +3296,7 @@ export class Deparser implements DeparserVisitor {
3200
3296
  }
3201
3297
  throw new Error(`ScalarArrayOpExpr requires exactly 2 arguments, got ${args.length}`);
3202
3298
  }
3203
- Aggref(node: any, context: DeparserContext): string {
3299
+ Aggref(node, context) {
3204
3300
  const funcName = this.getAggFunctionName(node.aggfnoid);
3205
3301
  let result = funcName + '(';
3206
3302
  const hasDistinct = node.aggdistinct && node.aggdistinct.length > 0;
@@ -3231,7 +3327,7 @@ export class Deparser implements DeparserVisitor {
3231
3327
  }
3232
3328
  return result;
3233
3329
  }
3234
- WindowFunc(node: any, context: DeparserContext): string {
3330
+ WindowFunc(node, context) {
3235
3331
  const funcName = this.getWindowFunctionName(node.winfnoid);
3236
3332
  let result = funcName + '(';
3237
3333
  if (node.args && node.args.length > 0) {
@@ -3241,7 +3337,7 @@ export class Deparser implements DeparserVisitor {
3241
3337
  }
3242
3338
  result += ') OVER (';
3243
3339
  if (node.winref && typeof node.winref === 'object') {
3244
- result += this.visit(node.winref as any, context);
3340
+ result += this.visit(node.winref, context);
3245
3341
  }
3246
3342
  else if (node.winref) {
3247
3343
  result += 'ORDER BY created_at ASC';
@@ -3249,8 +3345,8 @@ export class Deparser implements DeparserVisitor {
3249
3345
  result += ')';
3250
3346
  return result;
3251
3347
  }
3252
- FieldSelect(node: any, context: DeparserContext): string {
3253
- const output: string[] = [];
3348
+ FieldSelect(node, context) {
3349
+ const output = [];
3254
3350
  if (node.arg) {
3255
3351
  output.push(this.visit(node.arg, context));
3256
3352
  }
@@ -3259,34 +3355,34 @@ export class Deparser implements DeparserVisitor {
3259
3355
  }
3260
3356
  return output.join('');
3261
3357
  }
3262
- RelabelType(node: any, context: DeparserContext): string {
3358
+ RelabelType(node, context) {
3263
3359
  if (node.arg) {
3264
3360
  const literalContext = context.spawn('RelabelType', { isStringLiteral: true });
3265
3361
  return this.visit(node.arg, literalContext);
3266
3362
  }
3267
3363
  return '';
3268
3364
  }
3269
- CoerceViaIO(node: any, context: DeparserContext): string {
3365
+ CoerceViaIO(node, context) {
3270
3366
  if (node.arg) {
3271
3367
  return this.visit(node.arg, context);
3272
3368
  }
3273
3369
  return '';
3274
3370
  }
3275
- ArrayCoerceExpr(node: any, context: DeparserContext): string {
3371
+ ArrayCoerceExpr(node, context) {
3276
3372
  if (node.arg) {
3277
3373
  return this.visit(node.arg, context);
3278
3374
  }
3279
3375
  return '';
3280
3376
  }
3281
- ConvertRowtypeExpr(node: any, context: DeparserContext): string {
3377
+ ConvertRowtypeExpr(node, context) {
3282
3378
  if (node.arg) {
3283
3379
  const literalContext = context.spawn('ConvertRowtypeExpr', { isStringLiteral: true });
3284
3380
  return this.visit(node.arg, literalContext);
3285
3381
  }
3286
3382
  return '';
3287
3383
  }
3288
- NamedArgExpr(node: any, context: DeparserContext): string {
3289
- const output: string[] = [];
3384
+ NamedArgExpr(node, context) {
3385
+ const output = [];
3290
3386
  if (node.name) {
3291
3387
  output.push(node.name);
3292
3388
  output.push('=>');
@@ -3296,8 +3392,8 @@ export class Deparser implements DeparserVisitor {
3296
3392
  }
3297
3393
  return output.join(' ');
3298
3394
  }
3299
- ViewStmt(node: any, context: DeparserContext): string {
3300
- const output: string[] = [];
3395
+ ViewStmt(node, context) {
3396
+ const output = [];
3301
3397
  output.push('CREATE');
3302
3398
  if (node.replace) {
3303
3399
  output.push('OR REPLACE');
@@ -3335,8 +3431,8 @@ export class Deparser implements DeparserVisitor {
3335
3431
  }
3336
3432
  return output.join(' ');
3337
3433
  }
3338
- IndexStmt(node: any, context: DeparserContext): string {
3339
- const output: string[] = [];
3434
+ IndexStmt(node, context) {
3435
+ const output = [];
3340
3436
  output.push('CREATE');
3341
3437
  if (node.unique) {
3342
3438
  output.push('UNIQUE');
@@ -3387,8 +3483,8 @@ export class Deparser implements DeparserVisitor {
3387
3483
  }
3388
3484
  return output.join(' ');
3389
3485
  }
3390
- IndexElem(node: any, context: DeparserContext): string {
3391
- const output: string[] = [];
3486
+ IndexElem(node, context) {
3487
+ const output = [];
3392
3488
  if (node.name) {
3393
3489
  output.push(QuoteUtils.quote(node.name));
3394
3490
  }
@@ -3438,8 +3534,8 @@ export class Deparser implements DeparserVisitor {
3438
3534
  }
3439
3535
  return output.join(' ');
3440
3536
  }
3441
- PartitionElem(node: any, context: DeparserContext): string {
3442
- const output: string[] = [];
3537
+ PartitionElem(node, context) {
3538
+ const output = [];
3443
3539
  if (node.name) {
3444
3540
  output.push(QuoteUtils.quote(node.name));
3445
3541
  }
@@ -3457,13 +3553,13 @@ export class Deparser implements DeparserVisitor {
3457
3553
  }
3458
3554
  return output.join(' ');
3459
3555
  }
3460
- PartitionCmd(node: any, context: DeparserContext): string {
3461
- const output: string[] = [];
3556
+ PartitionCmd(node, context) {
3557
+ const output = [];
3462
3558
  if (node.concurrent) {
3463
3559
  output.push('CONCURRENTLY');
3464
3560
  }
3465
3561
  if (node.name) {
3466
- output.push(this.visit(node.name as any, context));
3562
+ output.push(this.visit(node.name, context));
3467
3563
  }
3468
3564
  if (node.bound) {
3469
3565
  if (node.bound.strategy === 'l' && node.bound.listdatums) {
@@ -3499,10 +3595,8 @@ export class Deparser implements DeparserVisitor {
3499
3595
  }
3500
3596
  return output.join(' ');
3501
3597
  }
3502
- private getAggFunctionName(aggfnoid?: number): string {
3503
- const commonAggFunctions: {
3504
- [key: number]: string;
3505
- } = {
3598
+ getAggFunctionName(aggfnoid) {
3599
+ const commonAggFunctions = {
3506
3600
  2100: 'avg',
3507
3601
  2101: 'count',
3508
3602
  2102: 'max',
@@ -3515,10 +3609,8 @@ export class Deparser implements DeparserVisitor {
3515
3609
  };
3516
3610
  return commonAggFunctions[aggfnoid || 0] || 'unknown_agg';
3517
3611
  }
3518
- private getWindowFunctionName(winfnoid?: number): string {
3519
- const commonWindowFunctions: {
3520
- [key: number]: string;
3521
- } = {
3612
+ getWindowFunctionName(winfnoid) {
3613
+ const commonWindowFunctions = {
3522
3614
  3100: 'row_number',
3523
3615
  3101: 'rank',
3524
3616
  3102: 'dense_rank',
@@ -3532,10 +3624,8 @@ export class Deparser implements DeparserVisitor {
3532
3624
  };
3533
3625
  return commonWindowFunctions[winfnoid || 0] || 'unknown_window_func';
3534
3626
  }
3535
- private getOperatorName(opno?: number): string {
3536
- const commonOperators: {
3537
- [key: number]: string;
3538
- } = {
3627
+ getOperatorName(opno) {
3628
+ const commonOperators = {
3539
3629
  96: '=',
3540
3630
  518: '<>',
3541
3631
  97: '<',
@@ -3560,8 +3650,8 @@ export class Deparser implements DeparserVisitor {
3560
3650
  };
3561
3651
  return commonOperators[opno || 0] || '=';
3562
3652
  }
3563
- JoinExpr(node: any, context: DeparserContext): string {
3564
- const output: string[] = [];
3653
+ JoinExpr(node, context) {
3654
+ const output = [];
3565
3655
  if (node.larg) {
3566
3656
  output.push(this.visit(node.larg, context));
3567
3657
  }
@@ -3670,7 +3760,7 @@ export class Deparser implements DeparserVisitor {
3670
3760
  }
3671
3761
  return result;
3672
3762
  }
3673
- FromExpr(node: any, context: DeparserContext): string {
3763
+ FromExpr(node, context) {
3674
3764
  const fromlist = ListUtils.unwrapList(node.fromlist);
3675
3765
  const fromStrs = fromlist.map(item => this.visit(item, context));
3676
3766
  let result = fromStrs.join(', ');
@@ -3679,8 +3769,8 @@ export class Deparser implements DeparserVisitor {
3679
3769
  }
3680
3770
  return result;
3681
3771
  }
3682
- TransactionStmt(node: any, context: DeparserContext): string {
3683
- const output: string[] = [];
3772
+ TransactionStmt(node, context) {
3773
+ const output = [];
3684
3774
  switch (node.kind) {
3685
3775
  case 'TRANS_STMT_BEGIN':
3686
3776
  output.push('BEGIN');
@@ -3790,7 +3880,7 @@ export class Deparser implements DeparserVisitor {
3790
3880
  }
3791
3881
  return output.join(' ');
3792
3882
  }
3793
- VariableSetStmt(node: any, context: DeparserContext): string {
3883
+ VariableSetStmt(node, context) {
3794
3884
  switch (node.kind) {
3795
3885
  case 'VAR_SET_VALUE':
3796
3886
  const localPrefix = node.is_local ? 'LOCAL ' : '';
@@ -3820,7 +3910,7 @@ export class Deparser implements DeparserVisitor {
3820
3910
  case 'VAR_SET_MULTI':
3821
3911
  if (node.name === 'TRANSACTION' || node.name === 'SESSION CHARACTERISTICS') {
3822
3912
  // Handle SET TRANSACTION statements specially
3823
- const transactionOptions: string[] = [];
3913
+ const transactionOptions = [];
3824
3914
  if (node.args) {
3825
3915
  const args = ListUtils.unwrapList(node.args);
3826
3916
  for (const arg of args) {
@@ -3897,14 +3987,14 @@ export class Deparser implements DeparserVisitor {
3897
3987
  throw new Error(`Unsupported VariableSetStmt kind: ${node.kind}`);
3898
3988
  }
3899
3989
  }
3900
- VariableShowStmt(node: any, context: DeparserContext): string {
3990
+ VariableShowStmt(node, context) {
3901
3991
  if (node.name === 'ALL') {
3902
3992
  return 'SHOW ALL';
3903
3993
  }
3904
3994
  return `SHOW ${node.name}`;
3905
3995
  }
3906
- CreateSchemaStmt(node: any, context: DeparserContext): string {
3907
- const output: string[] = ['CREATE SCHEMA'];
3996
+ CreateSchemaStmt(node, context) {
3997
+ const output = ['CREATE SCHEMA'];
3908
3998
  if (node.if_not_exists) {
3909
3999
  output.push('IF NOT EXISTS');
3910
4000
  }
@@ -3923,7 +4013,7 @@ export class Deparser implements DeparserVisitor {
3923
4013
  }
3924
4014
  return output.join(' ');
3925
4015
  }
3926
- RoleSpec(node: any, context: DeparserContext): string {
4016
+ RoleSpec(node, context) {
3927
4017
  if (node.rolename) {
3928
4018
  return this.quoteIfNeeded(node.rolename);
3929
4019
  }
@@ -3940,14 +4030,14 @@ export class Deparser implements DeparserVisitor {
3940
4030
  return 'PUBLIC';
3941
4031
  }
3942
4032
  }
3943
- roletype(node: any, context: DeparserContext): string {
4033
+ roletype(node, context) {
3944
4034
  if (node.rolename) {
3945
4035
  return node.rolename;
3946
4036
  }
3947
4037
  return '';
3948
4038
  }
3949
- DropStmt(node: any, context: DeparserContext): string {
3950
- const output: string[] = ['DROP'];
4039
+ DropStmt(node, context) {
4040
+ const output = ['DROP'];
3951
4041
  if (node.removeType) {
3952
4042
  switch (node.removeType) {
3953
4043
  case 'OBJECT_TABLE':
@@ -4113,8 +4203,8 @@ export class Deparser implements DeparserVisitor {
4113
4203
  if (node.objects && node.objects.length > 0) {
4114
4204
  if (node.removeType === 'OBJECT_POLICY') {
4115
4205
  const objList = node.objects[0];
4116
- if (objList && (objList as any).List && (objList as any).List.items) {
4117
- const items = (objList as any).List.items.map((item: any) => {
4206
+ if (objList && objList.List && objList.List.items) {
4207
+ const items = objList.List.items.map((item) => {
4118
4208
  if (item.String && item.String.sval) {
4119
4209
  return item.String.sval;
4120
4210
  }
@@ -4135,11 +4225,11 @@ export class Deparser implements DeparserVisitor {
4135
4225
  }
4136
4226
  }
4137
4227
  else if (node.removeType === 'OBJECT_CAST') {
4138
- const objects = node.objects.map((objList: any) => {
4228
+ const objects = node.objects.map((objList) => {
4139
4229
  if (objList && objList.List && objList.List.items) {
4140
- const items = objList.List.items.map((item: any) => {
4230
+ const items = objList.List.items.map((item) => {
4141
4231
  return this.visit(item, context);
4142
- }).filter((name: string) => name && name.trim());
4232
+ }).filter((name) => name && name.trim());
4143
4233
  if (items.length === 2) {
4144
4234
  const [sourceType, targetType] = items;
4145
4235
  return `(${sourceType} AS ${targetType})`;
@@ -4148,20 +4238,20 @@ export class Deparser implements DeparserVisitor {
4148
4238
  }
4149
4239
  const objName = this.visit(objList, context);
4150
4240
  return objName;
4151
- }).filter((name: string) => name && name.trim()).join(', ');
4241
+ }).filter((name) => name && name.trim()).join(', ');
4152
4242
  if (objects) {
4153
4243
  output.push(objects);
4154
4244
  }
4155
4245
  }
4156
4246
  else if (node.removeType === 'OBJECT_TRIGGER' || node.removeType === 'OBJECT_RULE') {
4157
- const objects = node.objects.map((objList: any) => {
4247
+ const objects = node.objects.map((objList) => {
4158
4248
  if (objList && objList.List && objList.List.items) {
4159
- const items = objList.List.items.map((item: any) => {
4249
+ const items = objList.List.items.map((item) => {
4160
4250
  if (item.String && item.String.sval) {
4161
4251
  return QuoteUtils.quote(item.String.sval);
4162
4252
  }
4163
4253
  return this.visit(item, context);
4164
- }).filter((name: string) => name && name.trim());
4254
+ }).filter((name) => name && name.trim());
4165
4255
  if (items.length === 2) {
4166
4256
  const [tableName, triggerName] = items;
4167
4257
  return `${triggerName} ON ${tableName}`;
@@ -4174,21 +4264,21 @@ export class Deparser implements DeparserVisitor {
4174
4264
  }
4175
4265
  const objName = this.visit(objList, context);
4176
4266
  return objName;
4177
- }).filter((name: string) => name && name.trim()).join(', ');
4267
+ }).filter((name) => name && name.trim()).join(', ');
4178
4268
  if (objects) {
4179
4269
  output.push(objects);
4180
4270
  }
4181
4271
  }
4182
4272
  else if (node.removeType === 'OBJECT_OPFAMILY' || node.removeType === 'OBJECT_OPCLASS') {
4183
4273
  // Handle operator family and operator class objects specially to format name USING access_method correctly
4184
- const objects = node.objects.map((objList: any) => {
4274
+ const objects = node.objects.map((objList) => {
4185
4275
  if (objList && objList.List && objList.List.items) {
4186
- const items = objList.List.items.map((item: any) => {
4276
+ const items = objList.List.items.map((item) => {
4187
4277
  if (item.String && item.String.sval) {
4188
4278
  return item.String.sval;
4189
4279
  }
4190
4280
  return this.visit(item, context);
4191
- }).filter((name: string) => name && name.trim());
4281
+ }).filter((name) => name && name.trim());
4192
4282
  if (items.length === 2) {
4193
4283
  const accessMethod = items[0];
4194
4284
  const objectName = items[1];
@@ -4204,21 +4294,21 @@ export class Deparser implements DeparserVisitor {
4204
4294
  }
4205
4295
  const objName = this.visit(objList, context);
4206
4296
  return objName;
4207
- }).filter((name: string) => name && name.trim()).join(', ');
4297
+ }).filter((name) => name && name.trim()).join(', ');
4208
4298
  if (objects) {
4209
4299
  output.push(objects);
4210
4300
  }
4211
4301
  }
4212
4302
  else if (node.removeType === 'OBJECT_TRANSFORM') {
4213
4303
  // Handle TRANSFORM objects specially to format FOR type_name LANGUAGE language_name correctly
4214
- const objects = node.objects.map((objList: any) => {
4304
+ const objects = node.objects.map((objList) => {
4215
4305
  if (objList && objList.List && objList.List.items) {
4216
- const items = objList.List.items.map((item: any) => {
4306
+ const items = objList.List.items.map((item) => {
4217
4307
  if (item.String && item.String.sval) {
4218
4308
  return item.String.sval;
4219
4309
  }
4220
4310
  return this.visit(item, context);
4221
- }).filter((name: string) => name && name.trim());
4311
+ }).filter((name) => name && name.trim());
4222
4312
  if (items.length === 2) {
4223
4313
  const [typeName, languageName] = items;
4224
4314
  return `FOR ${typeName} LANGUAGE ${languageName}`;
@@ -4227,30 +4317,30 @@ export class Deparser implements DeparserVisitor {
4227
4317
  }
4228
4318
  const objName = this.visit(objList, context);
4229
4319
  return objName;
4230
- }).filter((name: string) => name && name.trim()).join(', ');
4320
+ }).filter((name) => name && name.trim()).join(', ');
4231
4321
  if (objects) {
4232
4322
  output.push(objects);
4233
4323
  }
4234
4324
  }
4235
4325
  else {
4236
- const objects = node.objects.map((objList: any) => {
4326
+ const objects = node.objects.map((objList) => {
4237
4327
  if (Array.isArray(objList)) {
4238
4328
  const objName = objList.map(obj => this.visit(obj, context)).filter(name => name && name.trim()).join('.');
4239
4329
  return objName;
4240
4330
  }
4241
4331
  if (objList && objList.List && objList.List.items) {
4242
- const items = objList.List.items.map((item: any) => {
4332
+ const items = objList.List.items.map((item) => {
4243
4333
  if (item.String && item.String.sval) {
4244
4334
  return QuoteUtils.quote(item.String.sval);
4245
4335
  }
4246
4336
  return this.visit(item, context);
4247
- }).filter((name: string) => name && name.trim());
4337
+ }).filter((name) => name && name.trim());
4248
4338
  return items.join('.');
4249
4339
  }
4250
4340
  const objContext = context.spawn('DropStmt', { objtype: node.removeType });
4251
4341
  const objName = this.visit(objList, objContext);
4252
4342
  return objName;
4253
- }).filter((name: string) => name && name.trim()).join(', ');
4343
+ }).filter((name) => name && name.trim()).join(', ');
4254
4344
  if (objects) {
4255
4345
  output.push(objects);
4256
4346
  }
@@ -4262,11 +4352,11 @@ export class Deparser implements DeparserVisitor {
4262
4352
  // Only add RESTRICT if it was explicitly specified in the original SQL
4263
4353
  return output.join(' ');
4264
4354
  }
4265
- TruncateStmt(node: any, context: DeparserContext): string {
4266
- const output: string[] = ['TRUNCATE'];
4355
+ TruncateStmt(node, context) {
4356
+ const output = ['TRUNCATE'];
4267
4357
  if (node.relations && node.relations.length > 0) {
4268
4358
  const relations = node.relations
4269
- .map((relation: any) => this.visit(relation, context))
4359
+ .map((relation) => this.visit(relation, context))
4270
4360
  .join(', ');
4271
4361
  output.push(relations);
4272
4362
  }
@@ -4278,21 +4368,21 @@ export class Deparser implements DeparserVisitor {
4278
4368
  }
4279
4369
  return output.join(' ');
4280
4370
  }
4281
- ReturnStmt(node: any, context: DeparserContext): string {
4282
- const output: string[] = ['RETURN'];
4371
+ ReturnStmt(node, context) {
4372
+ const output = ['RETURN'];
4283
4373
  if (node.returnval) {
4284
4374
  const returnValue = this.visit(node.returnval, context);
4285
4375
  output.push(returnValue);
4286
4376
  }
4287
4377
  return output.join(' ');
4288
4378
  }
4289
- PLAssignStmt(node: any, context: DeparserContext): string {
4290
- const output: string[] = [];
4379
+ PLAssignStmt(node, context) {
4380
+ const output = [];
4291
4381
  if (node.name) {
4292
4382
  let nameWithIndirection = QuoteUtils.quote(node.name);
4293
4383
  if (node.indirection && node.indirection.length > 0) {
4294
4384
  const indirectionStr = node.indirection
4295
- .map((ind: any) => this.visit(ind, context))
4385
+ .map((ind) => this.visit(ind, context))
4296
4386
  .join('');
4297
4387
  nameWithIndirection += indirectionStr;
4298
4388
  }
@@ -4300,21 +4390,21 @@ export class Deparser implements DeparserVisitor {
4300
4390
  }
4301
4391
  output.push(':=');
4302
4392
  if (node.val) {
4303
- const valAny = node.val as any;
4393
+ const valAny = node.val;
4304
4394
  if (valAny.targetList) {
4305
4395
  output.push('SELECT');
4306
4396
  const targets = this.targetList(valAny.targetList, context);
4307
4397
  output.push(targets);
4308
4398
  }
4309
4399
  else {
4310
- const valueStr = this.visit(node.val as any, context);
4400
+ const valueStr = this.visit(node.val, context);
4311
4401
  output.push(valueStr);
4312
4402
  }
4313
4403
  }
4314
4404
  return output.join(' ');
4315
4405
  }
4316
- CopyStmt(node: any, context: DeparserContext): string {
4317
- const output: string[] = ['COPY'];
4406
+ CopyStmt(node, context) {
4407
+ const output = ['COPY'];
4318
4408
  if (node.relation) {
4319
4409
  const relationStr = this.RangeVar(node.relation, context);
4320
4410
  output.push(relationStr);
@@ -4358,8 +4448,8 @@ export class Deparser implements DeparserVisitor {
4358
4448
  }
4359
4449
  return output.join(' ');
4360
4450
  }
4361
- AlterTableStmt(node: any, context: DeparserContext): string {
4362
- const output: string[] = ['ALTER'];
4451
+ AlterTableStmt(node, context) {
4452
+ const output = ['ALTER'];
4363
4453
  if (node.objtype) {
4364
4454
  switch (node.objtype) {
4365
4455
  case 'OBJECT_TABLE':
@@ -4418,8 +4508,8 @@ export class Deparser implements DeparserVisitor {
4418
4508
  }
4419
4509
  return output.join(' ');
4420
4510
  }
4421
- AlterTableCmd(node: any, context: DeparserContext): string {
4422
- const output: string[] = [];
4511
+ AlterTableCmd(node, context) {
4512
+ const output = [];
4423
4513
  if (node.subtype) {
4424
4514
  switch (node.subtype) {
4425
4515
  case 'AT_AddColumn':
@@ -4435,8 +4525,8 @@ export class Deparser implements DeparserVisitor {
4435
4525
  if (node.def) {
4436
4526
  const colDefData = this.getNodeData(node.def);
4437
4527
  if (context.isPretty()) {
4438
- const parts: string[] = [];
4439
- const indentedParts: string[] = [];
4528
+ const parts = [];
4529
+ const indentedParts = [];
4440
4530
  if (colDefData.colname) {
4441
4531
  parts.push(QuoteUtils.quote(colDefData.colname));
4442
4532
  }
@@ -4473,7 +4563,7 @@ export class Deparser implements DeparserVisitor {
4473
4563
  }
4474
4564
  });
4475
4565
  }
4476
- if (colDefData.raw_default && !colDefData.constraints?.some((c: any) => {
4566
+ if (colDefData.raw_default && !colDefData.constraints?.some((c) => {
4477
4567
  const constraintStr = this.visit(c, context.spawn('ColumnDef', { isColumnConstraint: true }));
4478
4568
  return constraintStr === 'UNIQUE';
4479
4569
  })) {
@@ -4494,7 +4584,7 @@ export class Deparser implements DeparserVisitor {
4494
4584
  output.push(result);
4495
4585
  }
4496
4586
  else {
4497
- const parts: string[] = [];
4587
+ const parts = [];
4498
4588
  if (colDefData.colname) {
4499
4589
  parts.push(QuoteUtils.quote(colDefData.colname));
4500
4590
  }
@@ -4953,7 +5043,7 @@ export class Deparser implements DeparserVisitor {
4953
5043
  case 'AT_AlterConstraint':
4954
5044
  output.push('ALTER CONSTRAINT');
4955
5045
  if (node.def && this.getNodeType(node.def) === 'Constraint') {
4956
- const constraintData = this.getNodeData(node.def) as any;
5046
+ const constraintData = this.getNodeData(node.def);
4957
5047
  if (constraintData.conname) {
4958
5048
  output.push(QuoteUtils.quote(constraintData.conname));
4959
5049
  if (constraintData.deferrable !== undefined) {
@@ -5082,8 +5172,8 @@ export class Deparser implements DeparserVisitor {
5082
5172
  }
5083
5173
  return output.join(' ');
5084
5174
  }
5085
- CreateFunctionStmt(node: any, context: DeparserContext): string {
5086
- const output: string[] = ['CREATE'];
5175
+ CreateFunctionStmt(node, context) {
5176
+ const output = ['CREATE'];
5087
5177
  if (node.replace) {
5088
5178
  output.push('OR REPLACE');
5089
5179
  }
@@ -5094,14 +5184,14 @@ export class Deparser implements DeparserVisitor {
5094
5184
  output.push('FUNCTION');
5095
5185
  }
5096
5186
  if (node.funcname && node.funcname.length > 0) {
5097
- const funcName = node.funcname.map((name: any) => this.visit(name, context)).join('.');
5187
+ const funcName = node.funcname.map((name) => this.visit(name, context)).join('.');
5098
5188
  if (node.parameters && node.parameters.length > 0) {
5099
5189
  const params = node.parameters
5100
- .filter((param: any) => {
5190
+ .filter((param) => {
5101
5191
  const paramData = this.getNodeData(param);
5102
5192
  return paramData.mode !== 'FUNC_PARAM_TABLE';
5103
5193
  })
5104
- .map((param: any) => this.visit(param, context));
5194
+ .map((param) => this.visit(param, context));
5105
5195
  if (params.length > 0) {
5106
5196
  output.push(funcName + '(' + params.join(', ') + ')');
5107
5197
  }
@@ -5113,28 +5203,28 @@ export class Deparser implements DeparserVisitor {
5113
5203
  output.push(funcName + '()');
5114
5204
  }
5115
5205
  }
5116
- const hasTableParams = node.parameters && node.parameters.some((param: any) => {
5206
+ const hasTableParams = node.parameters && node.parameters.some((param) => {
5117
5207
  const paramData = this.getNodeData(param);
5118
5208
  return paramData.mode === 'FUNC_PARAM_TABLE';
5119
5209
  });
5120
5210
  if (hasTableParams) {
5121
5211
  output.push('RETURNS TABLE (');
5122
5212
  const tableParams = node.parameters
5123
- .filter((param: any) => {
5213
+ .filter((param) => {
5124
5214
  const paramData = this.getNodeData(param);
5125
5215
  return paramData.mode === 'FUNC_PARAM_TABLE';
5126
5216
  })
5127
- .map((param: any) => this.visit(param, context));
5217
+ .map((param) => this.visit(param, context));
5128
5218
  output.push(tableParams.join(', '));
5129
5219
  output.push(')');
5130
5220
  }
5131
5221
  else if (node.returnType) {
5132
5222
  output.push('RETURNS');
5133
- output.push(this.TypeName(node.returnType as any, context));
5223
+ output.push(this.TypeName(node.returnType, context));
5134
5224
  }
5135
5225
  if (node.options && node.options.length > 0) {
5136
5226
  const funcContext = context.spawn('CreateFunctionStmt');
5137
- const options = node.options.map((opt: any) => this.visit(opt, funcContext));
5227
+ const options = node.options.map((opt) => this.visit(opt, funcContext));
5138
5228
  output.push(...options);
5139
5229
  }
5140
5230
  if (node.sql_body) {
@@ -5180,8 +5270,8 @@ export class Deparser implements DeparserVisitor {
5180
5270
  }
5181
5271
  return output.join(' ');
5182
5272
  }
5183
- FunctionParameter(node: any, context: DeparserContext): string {
5184
- const output: string[] = [];
5273
+ FunctionParameter(node, context) {
5274
+ const output = [];
5185
5275
  if (node.mode) {
5186
5276
  switch (node.mode) {
5187
5277
  case 'FUNC_PARAM_IN':
@@ -5202,7 +5292,7 @@ export class Deparser implements DeparserVisitor {
5202
5292
  output.push(QuoteUtils.quote(node.name));
5203
5293
  }
5204
5294
  if (node.argType) {
5205
- output.push(this.TypeName(node.argType as any, context));
5295
+ output.push(this.TypeName(node.argType, context));
5206
5296
  }
5207
5297
  if (node.defexpr) {
5208
5298
  output.push('DEFAULT');
@@ -5210,8 +5300,8 @@ export class Deparser implements DeparserVisitor {
5210
5300
  }
5211
5301
  return output.join(' ');
5212
5302
  }
5213
- CreateEnumStmt(node: any, context: DeparserContext): string {
5214
- const output: string[] = ['CREATE', 'TYPE'];
5303
+ CreateEnumStmt(node, context) {
5304
+ const output = ['CREATE', 'TYPE'];
5215
5305
  if (node.typeName) {
5216
5306
  const typeName = ListUtils.unwrapList(node.typeName)
5217
5307
  .map(name => this.visit(name, context))
@@ -5231,8 +5321,8 @@ export class Deparser implements DeparserVisitor {
5231
5321
  }
5232
5322
  return output.join(' ');
5233
5323
  }
5234
- CreateDomainStmt(node: any, context: DeparserContext): string {
5235
- const output: string[] = ['CREATE', 'DOMAIN'];
5324
+ CreateDomainStmt(node, context) {
5325
+ const output = ['CREATE', 'DOMAIN'];
5236
5326
  if (node.domainname) {
5237
5327
  const domainName = ListUtils.unwrapList(node.domainname)
5238
5328
  .map(name => this.visit(name, context))
@@ -5256,8 +5346,8 @@ export class Deparser implements DeparserVisitor {
5256
5346
  }
5257
5347
  return output.join(' ');
5258
5348
  }
5259
- CreateRoleStmt(node: any, context: DeparserContext): string {
5260
- const output: string[] = ['CREATE'];
5349
+ CreateRoleStmt(node, context) {
5350
+ const output = ['CREATE'];
5261
5351
  if (node.stmt_type === 'ROLESTMT_ROLE') {
5262
5352
  output.push('ROLE');
5263
5353
  }
@@ -5285,7 +5375,7 @@ export class Deparser implements DeparserVisitor {
5285
5375
  }
5286
5376
  return output.join(' ');
5287
5377
  }
5288
- DefElem(node: any, context: DeparserContext): string {
5378
+ DefElem(node, context) {
5289
5379
  if (!node.defname) {
5290
5380
  return '';
5291
5381
  }
@@ -5560,10 +5650,10 @@ export class Deparser implements DeparserVisitor {
5560
5650
  if (context.parentNodeTypes.includes('CreateFunctionStmt') || context.parentNodeTypes.includes('AlterFunctionStmt')) {
5561
5651
  if (node.defname === 'as') {
5562
5652
  // Handle List type (multiple function body strings)
5563
- if (node.arg && (node.arg as any).List) {
5564
- const listNode = (node.arg as any).List;
5653
+ if (node.arg && node.arg.List) {
5654
+ const listNode = node.arg.List;
5565
5655
  const listItems = listNode.items || [];
5566
- const bodyParts = listItems.map((item: any) => {
5656
+ const bodyParts = listItems.map((item) => {
5567
5657
  if (item.String) {
5568
5658
  return item.String.sval;
5569
5659
  }
@@ -5575,7 +5665,7 @@ export class Deparser implements DeparserVisitor {
5575
5665
  return `AS ${delimiter}${body}${delimiter}`;
5576
5666
  }
5577
5667
  else {
5578
- return `AS ${bodyParts.map((part: string) => {
5668
+ return `AS ${bodyParts.map((part) => {
5579
5669
  const delimiter = this.getFunctionDelimiter(part);
5580
5670
  return `${delimiter}${part}${delimiter}`;
5581
5671
  }).join(', ')}`;
@@ -5634,11 +5724,15 @@ export class Deparser implements DeparserVisitor {
5634
5724
  if (context.parentNodeTypes.includes('CreateExtensionStmt') || context.parentNodeTypes.includes('AlterExtensionStmt') || context.parentNodeTypes.includes('CreateFdwStmt') || context.parentNodeTypes.includes('AlterFdwStmt')) {
5635
5725
  // AlterExtensionStmt specific cases
5636
5726
  if (context.parentNodeTypes.includes('AlterExtensionStmt')) {
5637
- if (node.defname === 'to') {
5638
- return `TO ${argValue}`;
5727
+ if (node.defname === 'new_version') {
5728
+ // argValue is unquoted due to DefElem context, so we need to quote it
5729
+ const quotedValue = typeof argValue === 'string' && !argValue.startsWith("'")
5730
+ ? `'${argValue}'`
5731
+ : argValue;
5732
+ return `UPDATE TO ${quotedValue}`;
5639
5733
  }
5640
5734
  if (node.defname === 'schema') {
5641
- return `SCHEMA ${argValue}`;
5735
+ return `SET SCHEMA ${argValue}`;
5642
5736
  }
5643
5737
  }
5644
5738
  // CreateFdwStmt specific cases
@@ -5818,8 +5912,8 @@ export class Deparser implements DeparserVisitor {
5818
5912
  }
5819
5913
  return node.defname.toUpperCase();
5820
5914
  }
5821
- CreateTableSpaceStmt(node: any, context: DeparserContext): string {
5822
- const output: string[] = ['CREATE', 'TABLESPACE'];
5915
+ CreateTableSpaceStmt(node, context) {
5916
+ const output = ['CREATE', 'TABLESPACE'];
5823
5917
  if (node.tablespacename) {
5824
5918
  output.push(node.tablespacename);
5825
5919
  }
@@ -5841,8 +5935,8 @@ export class Deparser implements DeparserVisitor {
5841
5935
  }
5842
5936
  return output.join(' ');
5843
5937
  }
5844
- DropTableSpaceStmt(node: any, context: DeparserContext): string {
5845
- const output: string[] = ['DROP', 'TABLESPACE'];
5938
+ DropTableSpaceStmt(node, context) {
5939
+ const output = ['DROP', 'TABLESPACE'];
5846
5940
  if (node.missing_ok) {
5847
5941
  output.push('IF', 'EXISTS');
5848
5942
  }
@@ -5851,8 +5945,8 @@ export class Deparser implements DeparserVisitor {
5851
5945
  }
5852
5946
  return output.join(' ');
5853
5947
  }
5854
- AlterTableSpaceOptionsStmt(node: any, context: DeparserContext): string {
5855
- const output: string[] = ['ALTER', 'TABLESPACE'];
5948
+ AlterTableSpaceOptionsStmt(node, context) {
5949
+ const output = ['ALTER', 'TABLESPACE'];
5856
5950
  if (node.tablespacename) {
5857
5951
  output.push(node.tablespacename);
5858
5952
  }
@@ -5871,8 +5965,8 @@ export class Deparser implements DeparserVisitor {
5871
5965
  }
5872
5966
  return output.join(' ');
5873
5967
  }
5874
- CreateExtensionStmt(node: any, context: DeparserContext): string {
5875
- const output: string[] = ['CREATE', 'EXTENSION'];
5968
+ CreateExtensionStmt(node, context) {
5969
+ const output = ['CREATE', 'EXTENSION'];
5876
5970
  if (node.if_not_exists) {
5877
5971
  output.push('IF', 'NOT', 'EXISTS');
5878
5972
  }
@@ -5888,8 +5982,8 @@ export class Deparser implements DeparserVisitor {
5888
5982
  }
5889
5983
  return output.join(' ');
5890
5984
  }
5891
- AlterExtensionStmt(node: any, context: DeparserContext): string {
5892
- const output: string[] = ['ALTER', 'EXTENSION'];
5985
+ AlterExtensionStmt(node, context) {
5986
+ const output = ['ALTER', 'EXTENSION'];
5893
5987
  if (node.extname) {
5894
5988
  output.push(this.quoteIfNeeded(node.extname));
5895
5989
  }
@@ -5902,8 +5996,36 @@ export class Deparser implements DeparserVisitor {
5902
5996
  }
5903
5997
  return output.join(' ');
5904
5998
  }
5905
- CreateFdwStmt(node: any, context: DeparserContext): string {
5906
- const output: string[] = ['CREATE', 'FOREIGN', 'DATA', 'WRAPPER'];
5999
+ AlterExtensionContentsStmt(node, context) {
6000
+ const output = ['ALTER', 'EXTENSION'];
6001
+ if (node.extname) {
6002
+ output.push(this.quoteIfNeeded(node.extname));
6003
+ }
6004
+ // Handle action: 1 = ADD, -1 = DROP
6005
+ if (node.action === 1) {
6006
+ output.push('ADD');
6007
+ }
6008
+ else if (node.action === -1) {
6009
+ output.push('DROP');
6010
+ }
6011
+ // Add object type keyword
6012
+ if (node.objtype) {
6013
+ try {
6014
+ output.push(this.getObjectTypeKeyword(node.objtype));
6015
+ }
6016
+ catch {
6017
+ // Fallback to the raw objtype if not supported
6018
+ output.push(node.objtype.toString());
6019
+ }
6020
+ }
6021
+ // Add the object itself
6022
+ if (node.object) {
6023
+ output.push(this.visit(node.object, context));
6024
+ }
6025
+ return output.join(' ');
6026
+ }
6027
+ CreateFdwStmt(node, context) {
6028
+ const output = ['CREATE', 'FOREIGN', 'DATA', 'WRAPPER'];
5907
6029
  if (node.fdwname) {
5908
6030
  output.push(node.fdwname);
5909
6031
  }
@@ -5924,8 +6046,8 @@ export class Deparser implements DeparserVisitor {
5924
6046
  }
5925
6047
  return output.join(' ');
5926
6048
  }
5927
- SetOperationStmt(node: any, context: DeparserContext): string {
5928
- const output: string[] = [];
6049
+ SetOperationStmt(node, context) {
6050
+ const output = [];
5929
6051
  if (node.larg) {
5930
6052
  output.push(this.visit(node.larg, context));
5931
6053
  }
@@ -5949,8 +6071,8 @@ export class Deparser implements DeparserVisitor {
5949
6071
  }
5950
6072
  return output.join(' ');
5951
6073
  }
5952
- ReplicaIdentityStmt(node: any, context: DeparserContext): string {
5953
- const output: string[] = [];
6074
+ ReplicaIdentityStmt(node, context) {
6075
+ const output = [];
5954
6076
  if (node.identity_type) {
5955
6077
  switch (node.identity_type) {
5956
6078
  case 'd':
@@ -5978,8 +6100,8 @@ export class Deparser implements DeparserVisitor {
5978
6100
  }
5979
6101
  return output.join(' ');
5980
6102
  }
5981
- AlterCollationStmt(node: any, context: DeparserContext): string {
5982
- const output: string[] = ['ALTER', 'COLLATION'];
6103
+ AlterCollationStmt(node, context) {
6104
+ const output = ['ALTER', 'COLLATION'];
5983
6105
  if (node.collname && node.collname.length > 0) {
5984
6106
  const collationName = ListUtils.unwrapList(node.collname)
5985
6107
  .map(name => this.visit(name, context))
@@ -5989,8 +6111,8 @@ export class Deparser implements DeparserVisitor {
5989
6111
  output.push('REFRESH', 'VERSION');
5990
6112
  return output.join(' ');
5991
6113
  }
5992
- AlterDomainStmt(node: any, context: DeparserContext): string {
5993
- const output: string[] = ['ALTER', 'DOMAIN'];
6114
+ AlterDomainStmt(node, context) {
6115
+ const output = ['ALTER', 'DOMAIN'];
5994
6116
  if (node.typeName && node.typeName.length > 0) {
5995
6117
  const domainName = ListUtils.unwrapList(node.typeName)
5996
6118
  .map(name => this.visit(name, context))
@@ -6087,8 +6209,8 @@ export class Deparser implements DeparserVisitor {
6087
6209
  }
6088
6210
  return output.join(' ');
6089
6211
  }
6090
- PrepareStmt(node: any, context: DeparserContext): string {
6091
- const output: string[] = ['PREPARE'];
6212
+ PrepareStmt(node, context) {
6213
+ const output = ['PREPARE'];
6092
6214
  if (node.name) {
6093
6215
  output.push(node.name);
6094
6216
  }
@@ -6104,8 +6226,8 @@ export class Deparser implements DeparserVisitor {
6104
6226
  }
6105
6227
  return output.join(' ');
6106
6228
  }
6107
- ExecuteStmt(node: any, context: DeparserContext): string {
6108
- const output: string[] = ['EXECUTE'];
6229
+ ExecuteStmt(node, context) {
6230
+ const output = ['EXECUTE'];
6109
6231
  if (node.name) {
6110
6232
  output.push(node.name);
6111
6233
  }
@@ -6117,8 +6239,8 @@ export class Deparser implements DeparserVisitor {
6117
6239
  }
6118
6240
  return output.join(' ');
6119
6241
  }
6120
- DeallocateStmt(node: any, context: DeparserContext): string {
6121
- const output: string[] = ['DEALLOCATE'];
6242
+ DeallocateStmt(node, context) {
6243
+ const output = ['DEALLOCATE'];
6122
6244
  if (node.isall) {
6123
6245
  output.push('ALL');
6124
6246
  }
@@ -6127,8 +6249,8 @@ export class Deparser implements DeparserVisitor {
6127
6249
  }
6128
6250
  return output.join(' ');
6129
6251
  }
6130
- NotifyStmt(node: any, context: DeparserContext): string {
6131
- const output: string[] = ['NOTIFY'];
6252
+ NotifyStmt(node, context) {
6253
+ const output = ['NOTIFY'];
6132
6254
  if (node.conditionname) {
6133
6255
  output.push(node.conditionname);
6134
6256
  }
@@ -6138,15 +6260,15 @@ export class Deparser implements DeparserVisitor {
6138
6260
  }
6139
6261
  return output.join(' ');
6140
6262
  }
6141
- ListenStmt(node: any, context: DeparserContext): string {
6142
- const output: string[] = ['LISTEN'];
6263
+ ListenStmt(node, context) {
6264
+ const output = ['LISTEN'];
6143
6265
  if (node.conditionname) {
6144
6266
  output.push(node.conditionname);
6145
6267
  }
6146
6268
  return output.join(' ');
6147
6269
  }
6148
- UnlistenStmt(node: any, context: DeparserContext): string {
6149
- const output: string[] = ['UNLISTEN'];
6270
+ UnlistenStmt(node, context) {
6271
+ const output = ['UNLISTEN'];
6150
6272
  if (node.conditionname) {
6151
6273
  output.push(node.conditionname);
6152
6274
  }
@@ -6155,16 +6277,16 @@ export class Deparser implements DeparserVisitor {
6155
6277
  }
6156
6278
  return output.join(' ');
6157
6279
  }
6158
- CheckPointStmt(node: any, context: DeparserContext): string {
6280
+ CheckPointStmt(node, context) {
6159
6281
  return 'CHECKPOINT';
6160
6282
  }
6161
- LoadStmt(node: any, context: DeparserContext): string {
6283
+ LoadStmt(node, context) {
6162
6284
  if (!node.filename) {
6163
6285
  throw new Error('LoadStmt requires filename');
6164
6286
  }
6165
6287
  return `LOAD '${node.filename}'`;
6166
6288
  }
6167
- DiscardStmt(node: any, context: DeparserContext): string {
6289
+ DiscardStmt(node, context) {
6168
6290
  switch (node.target) {
6169
6291
  case 'DISCARD_ALL':
6170
6292
  return 'DISCARD ALL';
@@ -6178,8 +6300,8 @@ export class Deparser implements DeparserVisitor {
6178
6300
  throw new Error(`Unsupported DiscardStmt target: ${node.target}`);
6179
6301
  }
6180
6302
  }
6181
- CommentStmt(node: any, context: DeparserContext): string {
6182
- const output: string[] = ['COMMENT ON'];
6303
+ CommentStmt(node, context) {
6304
+ const output = ['COMMENT ON'];
6183
6305
  if (node.objtype) {
6184
6306
  switch (node.objtype) {
6185
6307
  case 'OBJECT_TABLE':
@@ -6310,16 +6432,16 @@ export class Deparser implements DeparserVisitor {
6310
6432
  else if (node.objtype === 'OBJECT_OPERATOR') {
6311
6433
  // Handle OPERATOR syntax: COMMENT ON OPERATOR -(NONE, integer) IS 'comment'
6312
6434
  // For operators, we need to handle ObjectWithArgs structure
6313
- if (node.object && (node.object as any).ObjectWithArgs) {
6314
- const objWithArgs = (node.object as any).ObjectWithArgs;
6435
+ if (node.object && node.object.ObjectWithArgs) {
6436
+ const objWithArgs = node.object.ObjectWithArgs;
6315
6437
  let operatorName = objWithArgs.objname && objWithArgs.objname[0] && objWithArgs.objname[0].String
6316
6438
  ? objWithArgs.objname[0].String.sval : 'unknown';
6317
6439
  if (operatorName.startsWith('"') && operatorName.endsWith('"')) {
6318
6440
  operatorName = operatorName.slice(1, -1);
6319
6441
  }
6320
- const args: string[] = [];
6442
+ const args = [];
6321
6443
  if (objWithArgs.objargs) {
6322
- objWithArgs.objargs.forEach((arg: any) => {
6444
+ objWithArgs.objargs.forEach((arg) => {
6323
6445
  if (!arg || Object.keys(arg).length === 0) {
6324
6446
  args.push('NONE');
6325
6447
  }
@@ -6379,18 +6501,18 @@ export class Deparser implements DeparserVisitor {
6379
6501
  }
6380
6502
  }
6381
6503
  }
6382
- else if (node.objtype === 'OBJECT_OPERATOR' && node.object && (node.object as any).ObjectWithArgs) {
6504
+ else if (node.objtype === 'OBJECT_OPERATOR' && node.object && node.object.ObjectWithArgs) {
6383
6505
  // Handle direct ObjectWithArgs for OPERATOR syntax: COMMENT ON OPERATOR -(NONE, integer) IS 'comment'
6384
- const objWithArgs = (node.object as any).ObjectWithArgs;
6506
+ const objWithArgs = node.object.ObjectWithArgs;
6385
6507
  let operatorName = objWithArgs.objname && objWithArgs.objname[0] && objWithArgs.objname[0].String
6386
6508
  ? objWithArgs.objname[0].String.sval : 'unknown';
6387
6509
  // Remove quotes from operator name if present
6388
6510
  if (operatorName.startsWith('"') && operatorName.endsWith('"')) {
6389
6511
  operatorName = operatorName.slice(1, -1);
6390
6512
  }
6391
- const args: string[] = [];
6513
+ const args = [];
6392
6514
  if (objWithArgs.objargs) {
6393
- objWithArgs.objargs.forEach((arg: any) => {
6515
+ objWithArgs.objargs.forEach((arg) => {
6394
6516
  if (!arg || Object.keys(arg).length === 0) {
6395
6517
  args.push('NONE');
6396
6518
  }
@@ -6419,8 +6541,8 @@ export class Deparser implements DeparserVisitor {
6419
6541
  }
6420
6542
  return output.join(' ');
6421
6543
  }
6422
- LockStmt(node: any, context: DeparserContext): string {
6423
- const output: string[] = ['LOCK', 'TABLE'];
6544
+ LockStmt(node, context) {
6545
+ const output = ['LOCK', 'TABLE'];
6424
6546
  if (node.relations && node.relations.length > 0) {
6425
6547
  const relations = ListUtils.unwrapList(node.relations)
6426
6548
  .map(rel => this.visit(rel, context))
@@ -6448,8 +6570,8 @@ export class Deparser implements DeparserVisitor {
6448
6570
  }
6449
6571
  return output.join(' ');
6450
6572
  }
6451
- CreatePolicyStmt(node: any, context: DeparserContext): string {
6452
- const output: string[] = [];
6573
+ CreatePolicyStmt(node, context) {
6574
+ const output = [];
6453
6575
  const initialParts = ['CREATE', 'POLICY'];
6454
6576
  if (node.policy_name) {
6455
6577
  initialParts.push(QuoteUtils.quote(node.policy_name));
@@ -6526,8 +6648,8 @@ export class Deparser implements DeparserVisitor {
6526
6648
  }
6527
6649
  return context.isPretty() ? output.join('') : output.join(' ');
6528
6650
  }
6529
- AlterPolicyStmt(node: any, context: DeparserContext): string {
6530
- const output: string[] = ['ALTER', 'POLICY'];
6651
+ AlterPolicyStmt(node, context) {
6652
+ const output = ['ALTER', 'POLICY'];
6531
6653
  if (node.policy_name) {
6532
6654
  output.push(QuoteUtils.quote(node.policy_name));
6533
6655
  }
@@ -6550,8 +6672,8 @@ export class Deparser implements DeparserVisitor {
6550
6672
  }
6551
6673
  return output.join(' ');
6552
6674
  }
6553
- CreateUserMappingStmt(node: any, context: DeparserContext): string {
6554
- const output: string[] = ['CREATE'];
6675
+ CreateUserMappingStmt(node, context) {
6676
+ const output = ['CREATE'];
6555
6677
  if (node.if_not_exists) {
6556
6678
  output.push('IF', 'NOT', 'EXISTS');
6557
6679
  }
@@ -6575,8 +6697,8 @@ export class Deparser implements DeparserVisitor {
6575
6697
  }
6576
6698
  return output.join(' ');
6577
6699
  }
6578
- CreateStatsStmt(node: any, context: DeparserContext): string {
6579
- const output: string[] = ['CREATE'];
6700
+ CreateStatsStmt(node, context) {
6701
+ const output = ['CREATE'];
6580
6702
  if (node.if_not_exists) {
6581
6703
  output.push('IF', 'NOT', 'EXISTS');
6582
6704
  }
@@ -6601,7 +6723,7 @@ export class Deparser implements DeparserVisitor {
6601
6723
  }
6602
6724
  return output.join(' ');
6603
6725
  }
6604
- StatsElem(node: any, context: DeparserContext): string {
6726
+ StatsElem(node, context) {
6605
6727
  if (node.name) {
6606
6728
  return this.quoteIfNeeded(node.name);
6607
6729
  }
@@ -6610,8 +6732,8 @@ export class Deparser implements DeparserVisitor {
6610
6732
  }
6611
6733
  return '';
6612
6734
  }
6613
- CreatePublicationStmt(node: any, context: DeparserContext): string {
6614
- const output: string[] = ['CREATE', 'PUBLICATION'];
6735
+ CreatePublicationStmt(node, context) {
6736
+ const output = ['CREATE', 'PUBLICATION'];
6615
6737
  if (node.pubname) {
6616
6738
  output.push(`"${node.pubname}"`);
6617
6739
  }
@@ -6630,8 +6752,8 @@ export class Deparser implements DeparserVisitor {
6630
6752
  }
6631
6753
  return output.join(' ');
6632
6754
  }
6633
- CreateSubscriptionStmt(node: any, context: DeparserContext): string {
6634
- const output: string[] = ['CREATE', 'SUBSCRIPTION'];
6755
+ CreateSubscriptionStmt(node, context) {
6756
+ const output = ['CREATE', 'SUBSCRIPTION'];
6635
6757
  if (node.subname) {
6636
6758
  output.push(`"${node.subname}"`);
6637
6759
  }
@@ -6651,8 +6773,8 @@ export class Deparser implements DeparserVisitor {
6651
6773
  }
6652
6774
  return output.join(' ');
6653
6775
  }
6654
- AlterPublicationStmt(node: any, context: DeparserContext): string {
6655
- const output: string[] = ['ALTER', 'PUBLICATION'];
6776
+ AlterPublicationStmt(node, context) {
6777
+ const output = ['ALTER', 'PUBLICATION'];
6656
6778
  if (node.pubname) {
6657
6779
  output.push(`"${node.pubname}"`);
6658
6780
  }
@@ -6686,8 +6808,8 @@ export class Deparser implements DeparserVisitor {
6686
6808
  }
6687
6809
  return output.join(' ');
6688
6810
  }
6689
- AlterSubscriptionStmt(node: any, context: DeparserContext): string {
6690
- const output: string[] = ['ALTER', 'SUBSCRIPTION'];
6811
+ AlterSubscriptionStmt(node, context) {
6812
+ const output = ['ALTER', 'SUBSCRIPTION'];
6691
6813
  if (node.subname) {
6692
6814
  output.push(`"${node.subname}"`);
6693
6815
  }
@@ -6729,8 +6851,8 @@ export class Deparser implements DeparserVisitor {
6729
6851
  }
6730
6852
  return output.join(' ');
6731
6853
  }
6732
- DropSubscriptionStmt(node: any, context: DeparserContext): string {
6733
- const output: string[] = ['DROP', 'SUBSCRIPTION'];
6854
+ DropSubscriptionStmt(node, context) {
6855
+ const output = ['DROP', 'SUBSCRIPTION'];
6734
6856
  if (node.missing_ok) {
6735
6857
  output.push('IF EXISTS');
6736
6858
  }
@@ -6749,16 +6871,16 @@ export class Deparser implements DeparserVisitor {
6749
6871
  }
6750
6872
  return output.join(' ');
6751
6873
  }
6752
- DoStmt(node: any, context: DeparserContext): string {
6753
- const output: string[] = ['DO'];
6874
+ DoStmt(node, context) {
6875
+ const output = ['DO'];
6754
6876
  if (node.args && node.args.length > 0) {
6755
6877
  const doContext = context.spawn('DoStmt');
6756
6878
  const args = ListUtils.unwrapList(node.args);
6757
- const processedArgs: string[] = [];
6879
+ const processedArgs = [];
6758
6880
  for (const arg of args) {
6759
6881
  const nodeType = this.getNodeType(arg);
6760
6882
  if (nodeType === 'DefElem') {
6761
- const defElem = this.getNodeData(arg) as any;
6883
+ const defElem = this.getNodeData(arg);
6762
6884
  if (defElem.defname === 'language') {
6763
6885
  const langValue = this.visit(defElem.arg, doContext);
6764
6886
  processedArgs.push(`LANGUAGE ${langValue}`);
@@ -6767,7 +6889,7 @@ export class Deparser implements DeparserVisitor {
6767
6889
  // Handle code block with configurable delimiter
6768
6890
  const argNodeType = this.getNodeType(defElem.arg);
6769
6891
  if (argNodeType === 'String') {
6770
- const stringNode = this.getNodeData(defElem.arg) as any;
6892
+ const stringNode = this.getNodeData(defElem.arg);
6771
6893
  const delimiter = this.getFunctionDelimiter(stringNode.sval);
6772
6894
  processedArgs.push(`${delimiter}${stringNode.sval}${delimiter}`);
6773
6895
  }
@@ -6781,7 +6903,7 @@ export class Deparser implements DeparserVisitor {
6781
6903
  }
6782
6904
  return output.join(' ');
6783
6905
  }
6784
- private generateUniqueDollarTag(content: string): string {
6906
+ generateUniqueDollarTag(content) {
6785
6907
  // Check if content contains nested dollar quotes
6786
6908
  const dollarQuotePattern = /\$[a-zA-Z0-9_]*\$/g;
6787
6909
  const matches = content.match(dollarQuotePattern) || [];
@@ -6801,7 +6923,7 @@ export class Deparser implements DeparserVisitor {
6801
6923
  }
6802
6924
  return '$$';
6803
6925
  }
6804
- InlineCodeBlock(node: any, context: DeparserContext): string {
6926
+ InlineCodeBlock(node, context) {
6805
6927
  if (node.source_text) {
6806
6928
  const delimiter = this.getFunctionDelimiter(node.source_text);
6807
6929
  return `${delimiter}${node.source_text}${delimiter}`;
@@ -6809,14 +6931,14 @@ export class Deparser implements DeparserVisitor {
6809
6931
  const delimiter = this.options.functionDelimiter || '$$';
6810
6932
  return `${delimiter}${delimiter}`;
6811
6933
  }
6812
- CallContext(node: any, context: DeparserContext): string {
6934
+ CallContext(node, context) {
6813
6935
  if (node.atomic !== undefined) {
6814
6936
  return node.atomic ? 'ATOMIC' : 'NOT ATOMIC';
6815
6937
  }
6816
6938
  return '';
6817
6939
  }
6818
- ConstraintsSetStmt(node: any, context: DeparserContext): string {
6819
- const output: string[] = ['SET', 'CONSTRAINTS'];
6940
+ ConstraintsSetStmt(node, context) {
6941
+ const output = ['SET', 'CONSTRAINTS'];
6820
6942
  if (node.constraints && node.constraints.length > 0) {
6821
6943
  const constraints = ListUtils.unwrapList(node.constraints).map(constraint => this.visit(constraint, context));
6822
6944
  output.push(constraints.join(', '));
@@ -6827,8 +6949,8 @@ export class Deparser implements DeparserVisitor {
6827
6949
  output.push(node.deferred ? 'DEFERRED' : 'IMMEDIATE');
6828
6950
  return output.join(' ');
6829
6951
  }
6830
- AlterSystemStmt(node: any, context: DeparserContext): string {
6831
- const output: string[] = ['ALTER', 'SYSTEM'];
6952
+ AlterSystemStmt(node, context) {
6953
+ const output = ['ALTER', 'SYSTEM'];
6832
6954
  if (node.setstmt) {
6833
6955
  const setStmt = this.VariableSetStmt(node.setstmt, context);
6834
6956
  const setStmtWithoutPrefix = setStmt.replace(/^SET\s+/, '');
@@ -6836,8 +6958,8 @@ export class Deparser implements DeparserVisitor {
6836
6958
  }
6837
6959
  return output.join(' ');
6838
6960
  }
6839
- VacuumRelation(node: any, context: DeparserContext): string {
6840
- const output: string[] = [];
6961
+ VacuumRelation(node, context) {
6962
+ const output = [];
6841
6963
  if (node.relation) {
6842
6964
  output.push(this.RangeVar(node.relation, context));
6843
6965
  }
@@ -6849,8 +6971,8 @@ export class Deparser implements DeparserVisitor {
6849
6971
  }
6850
6972
  return output.join(' ');
6851
6973
  }
6852
- DropOwnedStmt(node: any, context: DeparserContext): string {
6853
- const output: string[] = ['DROP', 'OWNED', 'BY'];
6974
+ DropOwnedStmt(node, context) {
6975
+ const output = ['DROP', 'OWNED', 'BY'];
6854
6976
  if (node.roles && node.roles.length > 0) {
6855
6977
  const roles = ListUtils.unwrapList(node.roles).map(role => this.visit(role, context));
6856
6978
  output.push(roles.join(', '));
@@ -6867,8 +6989,8 @@ export class Deparser implements DeparserVisitor {
6867
6989
  }
6868
6990
  return output.join(' ');
6869
6991
  }
6870
- ReassignOwnedStmt(node: any, context: DeparserContext): string {
6871
- const output: string[] = ['REASSIGN', 'OWNED', 'BY'];
6992
+ ReassignOwnedStmt(node, context) {
6993
+ const output = ['REASSIGN', 'OWNED', 'BY'];
6872
6994
  if (node.roles && node.roles.length > 0) {
6873
6995
  const roles = ListUtils.unwrapList(node.roles).map(role => this.visit(role, context));
6874
6996
  output.push(roles.join(', '));
@@ -6879,8 +7001,8 @@ export class Deparser implements DeparserVisitor {
6879
7001
  }
6880
7002
  return output.join(' ');
6881
7003
  }
6882
- AlterTSDictionaryStmt(node: any, context: DeparserContext): string {
6883
- const output: string[] = ['ALTER', 'TEXT', 'SEARCH', 'DICTIONARY'];
7004
+ AlterTSDictionaryStmt(node, context) {
7005
+ const output = ['ALTER', 'TEXT', 'SEARCH', 'DICTIONARY'];
6884
7006
  if (node.dictname && node.dictname.length > 0) {
6885
7007
  const dictName = ListUtils.unwrapList(node.dictname).map(name => this.visit(name, context));
6886
7008
  output.push(dictName.join('.'));
@@ -6893,8 +7015,8 @@ export class Deparser implements DeparserVisitor {
6893
7015
  }
6894
7016
  return output.join(' ');
6895
7017
  }
6896
- AlterTSConfigurationStmt(node: any, context: DeparserContext): string {
6897
- const output: string[] = ['ALTER', 'TEXT', 'SEARCH', 'CONFIGURATION'];
7018
+ AlterTSConfigurationStmt(node, context) {
7019
+ const output = ['ALTER', 'TEXT', 'SEARCH', 'CONFIGURATION'];
6898
7020
  if (node.cfgname && node.cfgname.length > 0) {
6899
7021
  const cfgName = ListUtils.unwrapList(node.cfgname).map(name => this.visit(name, context));
6900
7022
  output.push(cfgName.join('.'));
@@ -6977,8 +7099,8 @@ export class Deparser implements DeparserVisitor {
6977
7099
  }
6978
7100
  return output.join(' ');
6979
7101
  }
6980
- ClosePortalStmt(node: any, context: DeparserContext): string {
6981
- const output: string[] = ['CLOSE'];
7102
+ ClosePortalStmt(node, context) {
7103
+ const output = ['CLOSE'];
6982
7104
  if (node.portalname) {
6983
7105
  output.push(QuoteUtils.quote(node.portalname));
6984
7106
  }
@@ -6987,10 +7109,10 @@ export class Deparser implements DeparserVisitor {
6987
7109
  }
6988
7110
  return output.join(' ');
6989
7111
  }
6990
- FetchStmt(node: any, context: DeparserContext): string {
6991
- const output: string[] = [node.ismove ? 'MOVE' : 'FETCH'];
7112
+ FetchStmt(node, context) {
7113
+ const output = [node.ismove ? 'MOVE' : 'FETCH'];
6992
7114
  // Check if howMany represents "ALL" (PostgreSQL uses LONG_MAX as sentinel)
6993
- const isAll = (node.howMany as any) === 9223372036854776000;
7115
+ const isAll = node.howMany === 9223372036854776000;
6994
7116
  // Handle direction first, then check for ALL within each direction
6995
7117
  if (node.direction) {
6996
7118
  switch (node.direction) {
@@ -7042,8 +7164,8 @@ export class Deparser implements DeparserVisitor {
7042
7164
  }
7043
7165
  return output.join(' ');
7044
7166
  }
7045
- AlterStatsStmt(node: any, context: DeparserContext): string {
7046
- const output: string[] = ['ALTER', 'STATISTICS'];
7167
+ AlterStatsStmt(node, context) {
7168
+ const output = ['ALTER', 'STATISTICS'];
7047
7169
  if (node.defnames && node.defnames.length > 0) {
7048
7170
  const names = ListUtils.unwrapList(node.defnames).map(name => this.visit(name, context));
7049
7171
  output.push(names.join('.'));
@@ -7054,7 +7176,7 @@ export class Deparser implements DeparserVisitor {
7054
7176
  }
7055
7177
  return output.join(' ');
7056
7178
  }
7057
- ObjectWithArgs(node: any, context: DeparserContext): string {
7179
+ ObjectWithArgs(node, context) {
7058
7180
  let result = '';
7059
7181
  if (node.objname && node.objname.length > 0) {
7060
7182
  const objContext = context.spawn('ObjectWithArgs');
@@ -7092,8 +7214,8 @@ export class Deparser implements DeparserVisitor {
7092
7214
  }
7093
7215
  return result;
7094
7216
  }
7095
- AlterOperatorStmt(node: any, context: DeparserContext): string {
7096
- const output: string[] = ['ALTER', 'OPERATOR'];
7217
+ AlterOperatorStmt(node, context) {
7218
+ const output = ['ALTER', 'OPERATOR'];
7097
7219
  if (node.opername) {
7098
7220
  output.push(this.ObjectWithArgs(node.opername, context));
7099
7221
  }
@@ -7105,8 +7227,8 @@ export class Deparser implements DeparserVisitor {
7105
7227
  }
7106
7228
  return output.join(' ');
7107
7229
  }
7108
- AlterFdwStmt(node: any, context: DeparserContext): string {
7109
- const output: string[] = ['ALTER', 'FOREIGN', 'DATA', 'WRAPPER'];
7230
+ AlterFdwStmt(node, context) {
7231
+ const output = ['ALTER', 'FOREIGN', 'DATA', 'WRAPPER'];
7110
7232
  if (node.fdwname) {
7111
7233
  output.push(QuoteUtils.quote(node.fdwname));
7112
7234
  }
@@ -7123,8 +7245,8 @@ export class Deparser implements DeparserVisitor {
7123
7245
  }
7124
7246
  return output.join(' ');
7125
7247
  }
7126
- CreateForeignServerStmt(node: any, context: DeparserContext): string {
7127
- const output: string[] = ['CREATE', 'SERVER'];
7248
+ CreateForeignServerStmt(node, context) {
7249
+ const output = ['CREATE', 'SERVER'];
7128
7250
  if (node.if_not_exists) {
7129
7251
  output.push('IF', 'NOT', 'EXISTS');
7130
7252
  }
@@ -7150,8 +7272,8 @@ export class Deparser implements DeparserVisitor {
7150
7272
  }
7151
7273
  return output.join(' ');
7152
7274
  }
7153
- AlterForeignServerStmt(node: any, context: DeparserContext): string {
7154
- const output: string[] = ['ALTER', 'SERVER'];
7275
+ AlterForeignServerStmt(node, context) {
7276
+ const output = ['ALTER', 'SERVER'];
7155
7277
  if (node.servername) {
7156
7278
  output.push(QuoteUtils.quote(node.servername));
7157
7279
  }
@@ -7168,8 +7290,8 @@ export class Deparser implements DeparserVisitor {
7168
7290
  }
7169
7291
  return output.join(' ');
7170
7292
  }
7171
- AlterUserMappingStmt(node: any, context: DeparserContext): string {
7172
- const output: string[] = ['ALTER', 'USER', 'MAPPING', 'FOR'];
7293
+ AlterUserMappingStmt(node, context) {
7294
+ const output = ['ALTER', 'USER', 'MAPPING', 'FOR'];
7173
7295
  if (node.user) {
7174
7296
  output.push(this.RoleSpec(node.user, context));
7175
7297
  }
@@ -7188,8 +7310,8 @@ export class Deparser implements DeparserVisitor {
7188
7310
  }
7189
7311
  return output.join(' ');
7190
7312
  }
7191
- DropUserMappingStmt(node: any, context: DeparserContext): string {
7192
- const output: string[] = ['DROP', 'USER', 'MAPPING'];
7313
+ DropUserMappingStmt(node, context) {
7314
+ const output = ['DROP', 'USER', 'MAPPING'];
7193
7315
  if (node.missing_ok) {
7194
7316
  output.push('IF', 'EXISTS');
7195
7317
  }
@@ -7206,8 +7328,8 @@ export class Deparser implements DeparserVisitor {
7206
7328
  }
7207
7329
  return output.join(' ');
7208
7330
  }
7209
- ImportForeignSchemaStmt(node: any, context: DeparserContext): string {
7210
- const output: string[] = ['IMPORT', 'FOREIGN', 'SCHEMA'];
7331
+ ImportForeignSchemaStmt(node, context) {
7332
+ const output = ['IMPORT', 'FOREIGN', 'SCHEMA'];
7211
7333
  if (node.remote_schema) {
7212
7334
  output.push(QuoteUtils.quote(node.remote_schema));
7213
7335
  }
@@ -7248,8 +7370,8 @@ export class Deparser implements DeparserVisitor {
7248
7370
  }
7249
7371
  return output.join(' ');
7250
7372
  }
7251
- ClusterStmt(node: any, context: DeparserContext): string {
7252
- const output: string[] = ['CLUSTER'];
7373
+ ClusterStmt(node, context) {
7374
+ const output = ['CLUSTER'];
7253
7375
  if (node.relation) {
7254
7376
  output.push(this.RangeVar(node.relation, context));
7255
7377
  if (node.indexname) {
@@ -7262,8 +7384,8 @@ export class Deparser implements DeparserVisitor {
7262
7384
  }
7263
7385
  return output.join(' ');
7264
7386
  }
7265
- VacuumStmt(node: any, context: DeparserContext): string {
7266
- const output: string[] = [node.is_vacuumcmd ? 'VACUUM' : 'ANALYZE'];
7387
+ VacuumStmt(node, context) {
7388
+ const output = [node.is_vacuumcmd ? 'VACUUM' : 'ANALYZE'];
7267
7389
  if (node.options && node.options.length > 0) {
7268
7390
  const options = ListUtils.unwrapList(node.options).map(option => this.visit(option, context));
7269
7391
  output.push(`(${options.join(', ')})`);
@@ -7274,8 +7396,8 @@ export class Deparser implements DeparserVisitor {
7274
7396
  }
7275
7397
  return output.join(' ');
7276
7398
  }
7277
- ExplainStmt(node: any, context: DeparserContext): string {
7278
- const output: string[] = ['EXPLAIN'];
7399
+ ExplainStmt(node, context) {
7400
+ const output = ['EXPLAIN'];
7279
7401
  if (node.options && node.options.length > 0) {
7280
7402
  const explainContext = context.spawn('ExplainStmt');
7281
7403
  const options = ListUtils.unwrapList(node.options).map(option => this.visit(option, explainContext));
@@ -7286,8 +7408,8 @@ export class Deparser implements DeparserVisitor {
7286
7408
  }
7287
7409
  return output.join(' ');
7288
7410
  }
7289
- ReindexStmt(node: any, context: DeparserContext): string {
7290
- const output: string[] = ['REINDEX'];
7411
+ ReindexStmt(node, context) {
7412
+ const output = ['REINDEX'];
7291
7413
  if (node.params && node.params.length > 0) {
7292
7414
  const params = ListUtils.unwrapList(node.params).map(param => this.visit(param, context));
7293
7415
  output.push(`(${params.join(', ')})`);
@@ -7321,12 +7443,12 @@ export class Deparser implements DeparserVisitor {
7321
7443
  }
7322
7444
  return output.join(' ');
7323
7445
  }
7324
- CallStmt(node: any, context: DeparserContext): string {
7325
- const output: string[] = ['CALL'];
7446
+ CallStmt(node, context) {
7447
+ const output = ['CALL'];
7326
7448
  if (node.funccall) {
7327
- const funcCall = node.funccall as any;
7449
+ const funcCall = node.funccall;
7328
7450
  if (funcCall.funcname && funcCall.funcname.length > 0) {
7329
- const funcNameParts = funcCall.funcname.map((nameNode: any) => {
7451
+ const funcNameParts = funcCall.funcname.map((nameNode) => {
7330
7452
  if (nameNode.String) {
7331
7453
  return nameNode.String.sval;
7332
7454
  }
@@ -7335,7 +7457,7 @@ export class Deparser implements DeparserVisitor {
7335
7457
  const funcName = funcNameParts.join('.');
7336
7458
  let argsStr = '';
7337
7459
  if (funcCall.args && funcCall.args.length > 0) {
7338
- const argStrs = funcCall.args.map((arg: any) => this.visit(arg, context));
7460
+ const argStrs = funcCall.args.map((arg) => this.visit(arg, context));
7339
7461
  argsStr = `(${argStrs.join(', ')})`;
7340
7462
  }
7341
7463
  else {
@@ -7352,8 +7474,8 @@ export class Deparser implements DeparserVisitor {
7352
7474
  }
7353
7475
  return output.join(' ');
7354
7476
  }
7355
- CreatedbStmt(node: any, context: DeparserContext): string {
7356
- const output: string[] = ['CREATE DATABASE'];
7477
+ CreatedbStmt(node, context) {
7478
+ const output = ['CREATE DATABASE'];
7357
7479
  if (!node.dbname) {
7358
7480
  throw new Error('CreatedbStmt requires dbname');
7359
7481
  }
@@ -7366,8 +7488,8 @@ export class Deparser implements DeparserVisitor {
7366
7488
  }
7367
7489
  return output.join(' ');
7368
7490
  }
7369
- DropdbStmt(node: any, context: DeparserContext): string {
7370
- const output: string[] = ['DROP DATABASE'];
7491
+ DropdbStmt(node, context) {
7492
+ const output = ['DROP DATABASE'];
7371
7493
  if (node.missing_ok) {
7372
7494
  output.push('IF EXISTS');
7373
7495
  }
@@ -7383,8 +7505,8 @@ export class Deparser implements DeparserVisitor {
7383
7505
  }
7384
7506
  return output.join(' ');
7385
7507
  }
7386
- RenameStmt(node: any, context: DeparserContext): string {
7387
- const output: string[] = ['ALTER'];
7508
+ RenameStmt(node, context) {
7509
+ const output = ['ALTER'];
7388
7510
  if (!node.renameType) {
7389
7511
  throw new Error('RenameStmt requires renameType');
7390
7512
  }
@@ -7544,8 +7666,8 @@ export class Deparser implements DeparserVisitor {
7544
7666
  }
7545
7667
  else if (node.object) {
7546
7668
  // Handle operator family and operator class objects specially to format name USING access_method correctly
7547
- if ((node.renameType === 'OBJECT_OPFAMILY' || node.renameType === 'OBJECT_OPCLASS') && (node.object as any).List) {
7548
- const items = ListUtils.unwrapList(node.object as any);
7669
+ if ((node.renameType === 'OBJECT_OPFAMILY' || node.renameType === 'OBJECT_OPCLASS') && node.object.List) {
7670
+ const items = ListUtils.unwrapList(node.object);
7549
7671
  if (items.length === 2) {
7550
7672
  const accessMethod = items[0].String?.sval || '';
7551
7673
  const objectName = items[1].String?.sval || '';
@@ -7555,9 +7677,9 @@ export class Deparser implements DeparserVisitor {
7555
7677
  output.push(this.visit(node.object, context));
7556
7678
  }
7557
7679
  }
7558
- else if (node.renameType === 'OBJECT_SCHEMA' && (node.object as any).List) {
7680
+ else if (node.renameType === 'OBJECT_SCHEMA' && node.object.List) {
7559
7681
  // Handle schema names - extract from List structure
7560
- const items = ListUtils.unwrapList(node.object as any);
7682
+ const items = ListUtils.unwrapList(node.object);
7561
7683
  if (items.length > 0 && items[0].String) {
7562
7684
  output.push(this.quoteIfNeeded(items[0].String.sval));
7563
7685
  }
@@ -7603,88 +7725,19 @@ export class Deparser implements DeparserVisitor {
7603
7725
  }
7604
7726
  return output.join(' ');
7605
7727
  }
7606
- AlterOwnerStmt(node: any, context: DeparserContext): string {
7607
- const output: string[] = ['ALTER'];
7728
+ AlterOwnerStmt(node, context) {
7729
+ const output = ['ALTER'];
7608
7730
  if (!node.objectType) {
7609
7731
  throw new Error('AlterOwnerStmt requires objectType');
7610
7732
  }
7611
- switch (node.objectType) {
7612
- case 'OBJECT_TABLE':
7613
- output.push('TABLE');
7614
- break;
7615
- case 'OBJECT_VIEW':
7616
- output.push('VIEW');
7617
- break;
7618
- case 'OBJECT_INDEX':
7619
- output.push('INDEX');
7620
- break;
7621
- case 'OBJECT_SEQUENCE':
7622
- output.push('SEQUENCE');
7623
- break;
7624
- case 'OBJECT_FUNCTION':
7625
- output.push('FUNCTION');
7626
- break;
7627
- case 'OBJECT_PROCEDURE':
7628
- output.push('PROCEDURE');
7629
- break;
7630
- case 'OBJECT_SCHEMA':
7631
- output.push('SCHEMA');
7632
- break;
7633
- case 'OBJECT_DATABASE':
7634
- output.push('DATABASE');
7635
- break;
7636
- case 'OBJECT_DOMAIN':
7637
- output.push('DOMAIN');
7638
- break;
7639
- case 'OBJECT_AGGREGATE':
7640
- output.push('AGGREGATE');
7641
- break;
7642
- case 'OBJECT_CONVERSION':
7643
- output.push('CONVERSION');
7644
- break;
7645
- case 'OBJECT_LANGUAGE':
7646
- output.push('LANGUAGE');
7647
- break;
7648
- case 'OBJECT_OPERATOR':
7649
- output.push('OPERATOR');
7650
- break;
7651
- case 'OBJECT_OPFAMILY':
7652
- output.push('OPERATOR FAMILY');
7653
- break;
7654
- case 'OBJECT_OPCLASS':
7655
- output.push('OPERATOR CLASS');
7656
- break;
7657
- case 'OBJECT_TSDICTIONARY':
7658
- output.push('TEXT SEARCH DICTIONARY');
7659
- break;
7660
- case 'OBJECT_TSCONFIGURATION':
7661
- output.push('TEXT SEARCH CONFIGURATION');
7662
- break;
7663
- case 'OBJECT_EVENT_TRIGGER':
7664
- output.push('EVENT TRIGGER');
7665
- break;
7666
- case 'OBJECT_FDW':
7667
- output.push('FOREIGN DATA WRAPPER');
7668
- break;
7669
- case 'OBJECT_FOREIGN_SERVER':
7670
- output.push('SERVER');
7671
- break;
7672
- case 'OBJECT_TYPE':
7673
- output.push('TYPE');
7674
- break;
7675
- case 'OBJECT_COLLATION':
7676
- output.push('COLLATION');
7677
- break;
7678
- default:
7679
- throw new Error(`Unsupported AlterOwnerStmt objectType: ${node.objectType}`);
7680
- }
7733
+ output.push(this.getObjectTypeKeyword(node.objectType));
7681
7734
  if (node.relation) {
7682
7735
  output.push(this.RangeVar(node.relation, context));
7683
7736
  }
7684
7737
  else if (node.object) {
7685
7738
  // Handle operator family and operator class objects specially to format name USING access_method correctly
7686
- if ((node.objectType === 'OBJECT_OPFAMILY' || node.objectType === 'OBJECT_OPCLASS') && (node.object as any).List) {
7687
- const items = ListUtils.unwrapList(node.object as any);
7739
+ if ((node.objectType === 'OBJECT_OPFAMILY' || node.objectType === 'OBJECT_OPCLASS') && node.object.List) {
7740
+ const items = ListUtils.unwrapList(node.object);
7688
7741
  if (items.length === 2) {
7689
7742
  const accessMethod = items[0].String?.sval || '';
7690
7743
  const objectName = items[1].String?.sval || '';
@@ -7705,8 +7758,8 @@ export class Deparser implements DeparserVisitor {
7705
7758
  output.push(this.RoleSpec(node.newowner, context));
7706
7759
  return output.join(' ');
7707
7760
  }
7708
- GrantStmt(node: any, context: DeparserContext): string {
7709
- const output: string[] = [];
7761
+ GrantStmt(node, context) {
7762
+ const output = [];
7710
7763
  if (node.is_grant) {
7711
7764
  output.push('GRANT');
7712
7765
  }
@@ -7860,15 +7913,15 @@ export class Deparser implements DeparserVisitor {
7860
7913
  }
7861
7914
  return output.join(' ');
7862
7915
  }
7863
- GrantRoleStmt(node: any, context: DeparserContext): string {
7864
- const output: string[] = [];
7916
+ GrantRoleStmt(node, context) {
7917
+ const output = [];
7865
7918
  // Check for inherit, admin, and set options first to place them correctly
7866
7919
  let hasInheritOption = false;
7867
7920
  let hasAdminOption = false;
7868
7921
  let hasSetOption = false;
7869
- let inheritValue: boolean | undefined;
7870
- let adminValue: boolean | undefined;
7871
- let setValue: boolean | undefined;
7922
+ let inheritValue;
7923
+ let adminValue;
7924
+ let setValue;
7872
7925
  if (node.opt && node.opt.length > 0) {
7873
7926
  const options = ListUtils.unwrapList(node.opt);
7874
7927
  const inheritOption = options.find(opt => opt.DefElem && opt.DefElem.defname === 'inherit');
@@ -7921,7 +7974,7 @@ export class Deparser implements DeparserVisitor {
7921
7974
  output.push(grantees);
7922
7975
  }
7923
7976
  if (node.is_grant) {
7924
- const withOptions: string[] = [];
7977
+ const withOptions = [];
7925
7978
  if (hasAdminOption) {
7926
7979
  if (adminValue === true) {
7927
7980
  withOptions.push('ADMIN OPTION');
@@ -7955,8 +8008,8 @@ export class Deparser implements DeparserVisitor {
7955
8008
  }
7956
8009
  return output.join(' ');
7957
8010
  }
7958
- SecLabelStmt(node: any, context: DeparserContext): string {
7959
- const output: string[] = ['SECURITY LABEL'];
8011
+ SecLabelStmt(node, context) {
8012
+ const output = ['SECURITY LABEL'];
7960
8013
  if (node.provider) {
7961
8014
  output.push('FOR', `"${node.provider}"`);
7962
8015
  }
@@ -7997,8 +8050,8 @@ export class Deparser implements DeparserVisitor {
7997
8050
  }
7998
8051
  return output.join(' ');
7999
8052
  }
8000
- AlterDefaultPrivilegesStmt(node: any, context: DeparserContext): string {
8001
- const output: string[] = ['ALTER DEFAULT PRIVILEGES'];
8053
+ AlterDefaultPrivilegesStmt(node, context) {
8054
+ const output = ['ALTER DEFAULT PRIVILEGES'];
8002
8055
  if (node.options && node.options.length > 0) {
8003
8056
  const options = ListUtils.unwrapList(node.options);
8004
8057
  for (const option of options) {
@@ -8034,8 +8087,8 @@ export class Deparser implements DeparserVisitor {
8034
8087
  }
8035
8088
  return output.join(' ');
8036
8089
  }
8037
- CreateConversionStmt(node: any, context: DeparserContext): string {
8038
- const output: string[] = ['CREATE'];
8090
+ CreateConversionStmt(node, context) {
8091
+ const output = ['CREATE'];
8039
8092
  if (node.def) {
8040
8093
  output.push('DEFAULT');
8041
8094
  }
@@ -8061,8 +8114,8 @@ export class Deparser implements DeparserVisitor {
8061
8114
  }
8062
8115
  return output.join(' ');
8063
8116
  }
8064
- CreateCastStmt(node: any, context: DeparserContext): string {
8065
- const output: string[] = ['CREATE CAST'];
8117
+ CreateCastStmt(node, context) {
8118
+ const output = ['CREATE CAST'];
8066
8119
  output.push('(');
8067
8120
  if (node.sourcetype) {
8068
8121
  output.push(this.TypeName(node.sourcetype, context));
@@ -8101,8 +8154,8 @@ export class Deparser implements DeparserVisitor {
8101
8154
  }
8102
8155
  return output.join(' ');
8103
8156
  }
8104
- CreatePLangStmt(node: any, context: DeparserContext): string {
8105
- const output: string[] = ['CREATE'];
8157
+ CreatePLangStmt(node, context) {
8158
+ const output = ['CREATE'];
8106
8159
  if (node.replace) {
8107
8160
  output.push('OR REPLACE');
8108
8161
  }
@@ -8136,8 +8189,8 @@ export class Deparser implements DeparserVisitor {
8136
8189
  }
8137
8190
  return output.join(' ');
8138
8191
  }
8139
- CreateTransformStmt(node: any, context: DeparserContext): string {
8140
- const output: string[] = ['CREATE'];
8192
+ CreateTransformStmt(node, context) {
8193
+ const output = ['CREATE'];
8141
8194
  if (node.replace) {
8142
8195
  output.push('OR REPLACE');
8143
8196
  }
@@ -8150,23 +8203,23 @@ export class Deparser implements DeparserVisitor {
8150
8203
  output.push(QuoteUtils.quote(node.lang));
8151
8204
  }
8152
8205
  output.push('(');
8153
- const transforms: string[] = [];
8206
+ const transforms = [];
8154
8207
  if (node.fromsql) {
8155
8208
  // Handle ObjectWithArgs directly to avoid visitor routing issues
8156
- const fromSqlName = this.ObjectWithArgs(node.fromsql as any, context);
8209
+ const fromSqlName = this.ObjectWithArgs(node.fromsql, context);
8157
8210
  transforms.push(`FROM SQL WITH FUNCTION ${fromSqlName}`);
8158
8211
  }
8159
8212
  if (node.tosql) {
8160
8213
  // Handle ObjectWithArgs directly to avoid visitor routing issues
8161
- const toSqlName = this.ObjectWithArgs(node.tosql as any, context);
8214
+ const toSqlName = this.ObjectWithArgs(node.tosql, context);
8162
8215
  transforms.push(`TO SQL WITH FUNCTION ${toSqlName}`);
8163
8216
  }
8164
8217
  output.push(transforms.join(', '));
8165
8218
  output.push(')');
8166
8219
  return output.join(' ');
8167
8220
  }
8168
- CreateTrigStmt(node: any, context: DeparserContext): string {
8169
- const output: string[] = ['CREATE'];
8221
+ CreateTrigStmt(node, context) {
8222
+ const output = ['CREATE'];
8170
8223
  if (node.replace) {
8171
8224
  output.push('OR REPLACE');
8172
8225
  }
@@ -8178,15 +8231,15 @@ export class Deparser implements DeparserVisitor {
8178
8231
  output.push(QuoteUtils.quote(node.trigname));
8179
8232
  }
8180
8233
  if (context.isPretty()) {
8181
- const components: string[] = [];
8182
- const timing: string[] = [];
8234
+ const components = [];
8235
+ const timing = [];
8183
8236
  if (node.timing & 2)
8184
8237
  timing.push('BEFORE');
8185
8238
  else if (node.timing & 64)
8186
8239
  timing.push('INSTEAD OF');
8187
8240
  else
8188
8241
  timing.push('AFTER');
8189
- const events: string[] = [];
8242
+ const events = [];
8190
8243
  if (node.events & 4)
8191
8244
  events.push('INSERT');
8192
8245
  if (node.events & 8)
@@ -8250,7 +8303,7 @@ export class Deparser implements DeparserVisitor {
8250
8303
  return output.join(' ') + context.newline() + components.join(context.newline());
8251
8304
  }
8252
8305
  else {
8253
- const timing: string[] = [];
8306
+ const timing = [];
8254
8307
  if (node.timing & 2)
8255
8308
  timing.push('BEFORE');
8256
8309
  else if (node.timing & 64)
@@ -8258,7 +8311,7 @@ export class Deparser implements DeparserVisitor {
8258
8311
  else
8259
8312
  timing.push('AFTER');
8260
8313
  output.push(timing.join(' '));
8261
- const events: string[] = [];
8314
+ const events = [];
8262
8315
  if (node.events & 4)
8263
8316
  events.push('INSERT');
8264
8317
  if (node.events & 8)
@@ -8330,8 +8383,8 @@ export class Deparser implements DeparserVisitor {
8330
8383
  return output.join(' ');
8331
8384
  }
8332
8385
  }
8333
- TriggerTransition(node: any, context: DeparserContext): string {
8334
- const output: string[] = [];
8386
+ TriggerTransition(node, context) {
8387
+ const output = [];
8335
8388
  if (node.isNew) {
8336
8389
  output.push('NEW TABLE AS');
8337
8390
  }
@@ -8343,8 +8396,8 @@ export class Deparser implements DeparserVisitor {
8343
8396
  }
8344
8397
  return output.join(' ');
8345
8398
  }
8346
- CreateEventTrigStmt(node: any, context: DeparserContext): string {
8347
- const output: string[] = ['CREATE EVENT TRIGGER'];
8399
+ CreateEventTrigStmt(node, context) {
8400
+ const output = ['CREATE EVENT TRIGGER'];
8348
8401
  if (node.trigname) {
8349
8402
  output.push(QuoteUtils.quote(node.trigname));
8350
8403
  }
@@ -8369,8 +8422,8 @@ export class Deparser implements DeparserVisitor {
8369
8422
  }
8370
8423
  return output.join(' ');
8371
8424
  }
8372
- AlterEventTrigStmt(node: any, context: DeparserContext): string {
8373
- const output: string[] = ['ALTER EVENT TRIGGER'];
8425
+ AlterEventTrigStmt(node, context) {
8426
+ const output = ['ALTER EVENT TRIGGER'];
8374
8427
  if (node.trigname) {
8375
8428
  output.push(QuoteUtils.quote(node.trigname));
8376
8429
  }
@@ -8394,8 +8447,8 @@ export class Deparser implements DeparserVisitor {
8394
8447
  }
8395
8448
  return output.join(' ');
8396
8449
  }
8397
- CreateOpClassStmt(node: any, context: DeparserContext): string {
8398
- const output: string[] = ['CREATE OPERATOR CLASS'];
8450
+ CreateOpClassStmt(node, context) {
8451
+ const output = ['CREATE OPERATOR CLASS'];
8399
8452
  if (node.opclassname && node.opclassname.length > 0) {
8400
8453
  const className = ListUtils.unwrapList(node.opclassname)
8401
8454
  .map(name => this.visit(name, context))
@@ -8429,8 +8482,8 @@ export class Deparser implements DeparserVisitor {
8429
8482
  }
8430
8483
  return output.join(' ');
8431
8484
  }
8432
- CreateOpFamilyStmt(node: any, context: DeparserContext): string {
8433
- const output: string[] = ['CREATE OPERATOR FAMILY'];
8485
+ CreateOpFamilyStmt(node, context) {
8486
+ const output = ['CREATE OPERATOR FAMILY'];
8434
8487
  if (node.opfamilyname && node.opfamilyname.length > 0) {
8435
8488
  const familyName = ListUtils.unwrapList(node.opfamilyname)
8436
8489
  .map(name => this.visit(name, context))
@@ -8443,8 +8496,8 @@ export class Deparser implements DeparserVisitor {
8443
8496
  }
8444
8497
  return output.join(' ');
8445
8498
  }
8446
- AlterOpFamilyStmt(node: any, context: DeparserContext): string {
8447
- const output: string[] = ['ALTER OPERATOR FAMILY'];
8499
+ AlterOpFamilyStmt(node, context) {
8500
+ const output = ['ALTER OPERATOR FAMILY'];
8448
8501
  if (node.opfamilyname && node.opfamilyname.length > 0) {
8449
8502
  const familyName = ListUtils.unwrapList(node.opfamilyname)
8450
8503
  .map(name => this.visit(name, context))
@@ -8469,8 +8522,8 @@ export class Deparser implements DeparserVisitor {
8469
8522
  }
8470
8523
  return output.join(' ');
8471
8524
  }
8472
- MergeStmt(node: any, context: DeparserContext): string {
8473
- const output: string[] = [];
8525
+ MergeStmt(node, context) {
8526
+ const output = [];
8474
8527
  if (node.withClause) {
8475
8528
  output.push(this.WithClause(node.withClause, context));
8476
8529
  }
@@ -8494,8 +8547,8 @@ export class Deparser implements DeparserVisitor {
8494
8547
  }
8495
8548
  return output.join(' ');
8496
8549
  }
8497
- AlterTableMoveAllStmt(node: any, context: DeparserContext): string {
8498
- const output: string[] = ['ALTER'];
8550
+ AlterTableMoveAllStmt(node, context) {
8551
+ const output = ['ALTER'];
8499
8552
  if (node.objtype === 'OBJECT_TABLE') {
8500
8553
  output.push('TABLE');
8501
8554
  }
@@ -8518,11 +8571,11 @@ export class Deparser implements DeparserVisitor {
8518
8571
  }
8519
8572
  return output.join(' ');
8520
8573
  }
8521
- CreateSeqStmt(node: any, context: DeparserContext): string {
8522
- const output: string[] = ['CREATE'];
8574
+ CreateSeqStmt(node, context) {
8575
+ const output = ['CREATE'];
8523
8576
  // Check if this is a temporary sequence
8524
8577
  if (node.sequence) {
8525
- const seq = node.sequence as any;
8578
+ const seq = node.sequence;
8526
8579
  if (seq.relpersistence === 't') {
8527
8580
  output.push('TEMPORARY');
8528
8581
  }
@@ -8532,8 +8585,8 @@ export class Deparser implements DeparserVisitor {
8532
8585
  output.push('IF NOT EXISTS');
8533
8586
  }
8534
8587
  if (node.sequence) {
8535
- const sequenceName: string[] = [];
8536
- const seq = node.sequence as any;
8588
+ const sequenceName = [];
8589
+ const seq = node.sequence;
8537
8590
  if (seq.schemaname) {
8538
8591
  sequenceName.push(QuoteUtils.quote(seq.schemaname));
8539
8592
  }
@@ -8563,14 +8616,14 @@ export class Deparser implements DeparserVisitor {
8563
8616
  }
8564
8617
  return output.join(' ');
8565
8618
  }
8566
- AlterSeqStmt(node: any, context: DeparserContext): string {
8567
- const output: string[] = ['ALTER', 'SEQUENCE'];
8619
+ AlterSeqStmt(node, context) {
8620
+ const output = ['ALTER', 'SEQUENCE'];
8568
8621
  if (node.missing_ok) {
8569
8622
  output.push('IF EXISTS');
8570
8623
  }
8571
8624
  if (node.sequence) {
8572
- const sequenceName: string[] = [];
8573
- const seq = node.sequence as any;
8625
+ const sequenceName = [];
8626
+ const seq = node.sequence;
8574
8627
  if (seq.schemaname) {
8575
8628
  sequenceName.push(QuoteUtils.quote(seq.schemaname));
8576
8629
  }
@@ -8606,8 +8659,8 @@ export class Deparser implements DeparserVisitor {
8606
8659
  }
8607
8660
  return output.join(' ');
8608
8661
  }
8609
- CompositeTypeStmt(node: any, context: DeparserContext): string {
8610
- const output: string[] = ['CREATE', 'TYPE'];
8662
+ CompositeTypeStmt(node, context) {
8663
+ const output = ['CREATE', 'TYPE'];
8611
8664
  if (node.typevar) {
8612
8665
  const typeContext = context.spawn('CompositeTypeStmt');
8613
8666
  output.push(this.RangeVar(node.typevar, typeContext));
@@ -8625,8 +8678,8 @@ export class Deparser implements DeparserVisitor {
8625
8678
  }
8626
8679
  return output.join(' ');
8627
8680
  }
8628
- CreateRangeStmt(node: any, context: DeparserContext): string {
8629
- const output: string[] = ['CREATE', 'TYPE'];
8681
+ CreateRangeStmt(node, context) {
8682
+ const output = ['CREATE', 'TYPE'];
8630
8683
  if (node.typeName && node.typeName.length > 0) {
8631
8684
  const typeNameStr = ListUtils.unwrapList(node.typeName)
8632
8685
  .map(name => this.visit(name, context))
@@ -8647,8 +8700,8 @@ export class Deparser implements DeparserVisitor {
8647
8700
  }
8648
8701
  return output.join(' ');
8649
8702
  }
8650
- AlterEnumStmt(node: any, context: DeparserContext): string {
8651
- const output: string[] = ['ALTER', 'TYPE'];
8703
+ AlterEnumStmt(node, context) {
8704
+ const output = ['ALTER', 'TYPE'];
8652
8705
  if (node.typeName && node.typeName.length > 0) {
8653
8706
  const typeNameStr = ListUtils.unwrapList(node.typeName)
8654
8707
  .map(name => this.visit(name, context))
@@ -8679,8 +8732,8 @@ export class Deparser implements DeparserVisitor {
8679
8732
  }
8680
8733
  return output.join(' ');
8681
8734
  }
8682
- AlterTypeStmt(node: any, context: DeparserContext): string {
8683
- const output: string[] = ['ALTER', 'TYPE'];
8735
+ AlterTypeStmt(node, context) {
8736
+ const output = ['ALTER', 'TYPE'];
8684
8737
  if (node.typeName && node.typeName.length > 0) {
8685
8738
  const typeNameStr = ListUtils.unwrapList(node.typeName)
8686
8739
  .map(name => this.visit(name, context))
@@ -8701,11 +8754,11 @@ export class Deparser implements DeparserVisitor {
8701
8754
  }
8702
8755
  return output.join(' ');
8703
8756
  }
8704
- AlterRoleStmt(node: any, context: DeparserContext): string {
8757
+ AlterRoleStmt(node, context) {
8705
8758
  // Check if this is an ALTER GROUP statement by looking for rolemembers DefElem
8706
8759
  const isGroupStatement = node.options &&
8707
8760
  ListUtils.unwrapList(node.options).some(option => option.DefElem && option.DefElem.defname === 'rolemembers');
8708
- const output: string[] = ['ALTER', isGroupStatement ? 'GROUP' : 'ROLE'];
8761
+ const output = ['ALTER', isGroupStatement ? 'GROUP' : 'ROLE'];
8709
8762
  if (node.role) {
8710
8763
  output.push(this.RoleSpec(node.role, context));
8711
8764
  }
@@ -8736,8 +8789,8 @@ export class Deparser implements DeparserVisitor {
8736
8789
  }
8737
8790
  return output.join(' ');
8738
8791
  }
8739
- DropRoleStmt(node: any, context: DeparserContext): string {
8740
- const output: string[] = ['DROP', 'ROLE'];
8792
+ DropRoleStmt(node, context) {
8793
+ const output = ['DROP', 'ROLE'];
8741
8794
  if (node.missing_ok) {
8742
8795
  output.push('IF EXISTS');
8743
8796
  }
@@ -8749,14 +8802,14 @@ export class Deparser implements DeparserVisitor {
8749
8802
  }
8750
8803
  return output.join(' ');
8751
8804
  }
8752
- targetList(node: any, context: DeparserContext): string {
8805
+ targetList(node, context) {
8753
8806
  if (!node || !Array.isArray(node)) {
8754
8807
  return '';
8755
8808
  }
8756
- return node.map((target: any) => this.visit(target, context)).join(', ');
8809
+ return node.map((target) => this.visit(target, context)).join(', ');
8757
8810
  }
8758
- CreateAggregateStmt(node: any, context: DeparserContext): string {
8759
- const output: string[] = ['CREATE'];
8811
+ CreateAggregateStmt(node, context) {
8812
+ const output = ['CREATE'];
8760
8813
  if (node.replace) {
8761
8814
  output.push('OR REPLACE');
8762
8815
  }
@@ -8780,7 +8833,7 @@ export class Deparser implements DeparserVisitor {
8780
8833
  }
8781
8834
  output.push(')');
8782
8835
  output.push('(');
8783
- const options: string[] = [];
8836
+ const options = [];
8784
8837
  if (node.definition && node.definition.length > 0) {
8785
8838
  const optionStrs = ListUtils.unwrapList(node.definition)
8786
8839
  .map(option => {
@@ -8829,8 +8882,8 @@ export class Deparser implements DeparserVisitor {
8829
8882
  output.push(')');
8830
8883
  return output.join(' ');
8831
8884
  }
8832
- CreateTableAsStmt(node: any, context: DeparserContext): string {
8833
- const output: string[] = ['CREATE'];
8885
+ CreateTableAsStmt(node, context) {
8886
+ const output = ['CREATE'];
8834
8887
  if (node.objtype === 'OBJECT_MATVIEW') {
8835
8888
  output.push('MATERIALIZED VIEW');
8836
8889
  }
@@ -8876,7 +8929,7 @@ export class Deparser implements DeparserVisitor {
8876
8929
  }
8877
8930
  output.push('AS');
8878
8931
  if (node.query) {
8879
- output.push(this.visit(node.query as any, context));
8932
+ output.push(this.visit(node.query, context));
8880
8933
  }
8881
8934
  if (node.into && node.into.options && node.into.options.length > 0) {
8882
8935
  output.push('WITH');
@@ -8890,21 +8943,21 @@ export class Deparser implements DeparserVisitor {
8890
8943
  }
8891
8944
  return output.join(' ');
8892
8945
  }
8893
- RefreshMatViewStmt(node: any, context: DeparserContext): string {
8894
- const output: string[] = ['REFRESH', 'MATERIALIZED', 'VIEW'];
8946
+ RefreshMatViewStmt(node, context) {
8947
+ const output = ['REFRESH', 'MATERIALIZED', 'VIEW'];
8895
8948
  if (node.concurrent) {
8896
8949
  output.push('CONCURRENTLY');
8897
8950
  }
8898
8951
  if (node.relation) {
8899
- output.push(this.visit(node.relation as any, context));
8952
+ output.push(this.visit(node.relation, context));
8900
8953
  }
8901
8954
  if (node.skipData) {
8902
8955
  output.push('WITH NO DATA');
8903
8956
  }
8904
8957
  return output.join(' ');
8905
8958
  }
8906
- AccessPriv(node: any, context: DeparserContext): string {
8907
- const output: string[] = [];
8959
+ AccessPriv(node, context) {
8960
+ const output = [];
8908
8961
  if (node.priv_name) {
8909
8962
  output.push(node.priv_name.toUpperCase());
8910
8963
  }
@@ -8920,14 +8973,14 @@ export class Deparser implements DeparserVisitor {
8920
8973
  }
8921
8974
  return output.join(' ');
8922
8975
  }
8923
- aliasname(node: any, context: DeparserContext): string {
8976
+ aliasname(node, context) {
8924
8977
  if (typeof node === 'string') {
8925
8978
  return QuoteUtils.quote(node);
8926
8979
  }
8927
8980
  return this.visit(node, context);
8928
8981
  }
8929
- DefineStmt(node: any, context: DeparserContext): string {
8930
- const output: string[] = [];
8982
+ DefineStmt(node, context) {
8983
+ const output = [];
8931
8984
  if (!node.kind) {
8932
8985
  throw new Error('DefineStmt requires kind property');
8933
8986
  }
@@ -9273,8 +9326,8 @@ export class Deparser implements DeparserVisitor {
9273
9326
  }
9274
9327
  return output.join(' ');
9275
9328
  }
9276
- AlterDatabaseStmt(node: any, context: DeparserContext): string {
9277
- const output: string[] = ['ALTER', 'DATABASE'];
9329
+ AlterDatabaseStmt(node, context) {
9330
+ const output = ['ALTER', 'DATABASE'];
9278
9331
  if (node.dbname) {
9279
9332
  output.push(QuoteUtils.quote(node.dbname));
9280
9333
  }
@@ -9284,16 +9337,16 @@ export class Deparser implements DeparserVisitor {
9284
9337
  }
9285
9338
  return output.join(' ');
9286
9339
  }
9287
- AlterDatabaseRefreshCollStmt(node: any, context: DeparserContext): string {
9288
- const output: string[] = ['ALTER', 'DATABASE'];
9340
+ AlterDatabaseRefreshCollStmt(node, context) {
9341
+ const output = ['ALTER', 'DATABASE'];
9289
9342
  if (node.dbname) {
9290
9343
  output.push(QuoteUtils.quote(node.dbname));
9291
9344
  }
9292
9345
  output.push('REFRESH', 'COLLATION', 'VERSION');
9293
9346
  return output.join(' ');
9294
9347
  }
9295
- AlterDatabaseSetStmt(node: any, context: DeparserContext): string {
9296
- const output: string[] = ['ALTER', 'DATABASE'];
9348
+ AlterDatabaseSetStmt(node, context) {
9349
+ const output = ['ALTER', 'DATABASE'];
9297
9350
  if (node.dbname) {
9298
9351
  output.push(QuoteUtils.quote(node.dbname));
9299
9352
  }
@@ -9303,13 +9356,13 @@ export class Deparser implements DeparserVisitor {
9303
9356
  }
9304
9357
  return output.join(' ');
9305
9358
  }
9306
- DeclareCursorStmt(node: any, context: DeparserContext): string {
9307
- const output: string[] = ['DECLARE'];
9359
+ DeclareCursorStmt(node, context) {
9360
+ const output = ['DECLARE'];
9308
9361
  if (node.portalname) {
9309
9362
  output.push(QuoteUtils.quote(node.portalname));
9310
9363
  }
9311
9364
  // Handle cursor options before CURSOR keyword
9312
- const cursorOptions: string[] = [];
9365
+ const cursorOptions = [];
9313
9366
  if (node.options) {
9314
9367
  if (node.options & 2) {
9315
9368
  cursorOptions.push('SCROLL');
@@ -9337,8 +9390,8 @@ export class Deparser implements DeparserVisitor {
9337
9390
  }
9338
9391
  return output.join(' ');
9339
9392
  }
9340
- PublicationObjSpec(node: any, context: DeparserContext): string {
9341
- const output: string[] = [];
9393
+ PublicationObjSpec(node, context) {
9394
+ const output = [];
9342
9395
  if (node.pubobjtype === 'PUBLICATIONOBJ_TABLE') {
9343
9396
  output.push('TABLE');
9344
9397
  if (node.pubtable) {
@@ -9356,8 +9409,8 @@ export class Deparser implements DeparserVisitor {
9356
9409
  }
9357
9410
  return output.join(' ');
9358
9411
  }
9359
- PublicationTable(node: any, context: DeparserContext): string {
9360
- const output: string[] = [];
9412
+ PublicationTable(node, context) {
9413
+ const output = [];
9361
9414
  if (node.relation) {
9362
9415
  output.push(this.RangeVar(node.relation, context));
9363
9416
  }
@@ -9371,8 +9424,8 @@ export class Deparser implements DeparserVisitor {
9371
9424
  }
9372
9425
  return output.join(' ');
9373
9426
  }
9374
- CreateAmStmt(node: any, context: DeparserContext): string {
9375
- const output: string[] = ['CREATE', 'ACCESS', 'METHOD'];
9427
+ CreateAmStmt(node, context) {
9428
+ const output = ['CREATE', 'ACCESS', 'METHOD'];
9376
9429
  if (node.amname) {
9377
9430
  output.push(QuoteUtils.quote(node.amname));
9378
9431
  }
@@ -9398,8 +9451,8 @@ export class Deparser implements DeparserVisitor {
9398
9451
  }
9399
9452
  return output.join(' ');
9400
9453
  }
9401
- IntoClause(node: any, context: DeparserContext): string {
9402
- const output: string[] = [];
9454
+ IntoClause(node, context) {
9455
+ const output = [];
9403
9456
  if (node.rel) {
9404
9457
  output.push(this.RangeVar(node.rel, context));
9405
9458
  }
@@ -9438,8 +9491,8 @@ export class Deparser implements DeparserVisitor {
9438
9491
  }
9439
9492
  return output.join(' ');
9440
9493
  }
9441
- OnConflictExpr(node: any, context: DeparserContext): string {
9442
- const output: string[] = ['ON CONFLICT'];
9494
+ OnConflictExpr(node, context) {
9495
+ const output = ['ON CONFLICT'];
9443
9496
  if (node.arbiterElems && node.arbiterElems.length > 0) {
9444
9497
  const arbiters = ListUtils.unwrapList(node.arbiterElems)
9445
9498
  .map(elem => this.visit(elem, context))
@@ -9468,11 +9521,11 @@ export class Deparser implements DeparserVisitor {
9468
9521
  }
9469
9522
  return output.join(' ');
9470
9523
  }
9471
- ScanToken(node: any, context: DeparserContext): string {
9524
+ ScanToken(node, context) {
9472
9525
  return '';
9473
9526
  }
9474
- CreateOpClassItem(node: any, context: DeparserContext): string {
9475
- const output: string[] = [];
9527
+ CreateOpClassItem(node, context) {
9528
+ const output = [];
9476
9529
  if (node.itemtype === 1) {
9477
9530
  output.push('OPERATOR');
9478
9531
  // For operators, always include the number (default to 0 if undefined)
@@ -9514,14 +9567,14 @@ export class Deparser implements DeparserVisitor {
9514
9567
  }
9515
9568
  return output.join(' ');
9516
9569
  }
9517
- Var(node: any, context: DeparserContext): string {
9570
+ Var(node, context) {
9518
9571
  if (node.varno && node.varattno) {
9519
9572
  return `$${node.varno}.${node.varattno}`;
9520
9573
  }
9521
9574
  return '$var';
9522
9575
  }
9523
- TableFunc(node: any, context: DeparserContext): string {
9524
- const output: string[] = [];
9576
+ TableFunc(node, context) {
9577
+ const output = [];
9525
9578
  if (node.functype === 'TFT_XMLTABLE') {
9526
9579
  output.push('XMLTABLE');
9527
9580
  if (node.ns_names && node.ns_names.length > 0) {
@@ -9565,8 +9618,8 @@ export class Deparser implements DeparserVisitor {
9565
9618
  }
9566
9619
  return output.join(' ');
9567
9620
  }
9568
- RangeTableFunc(node: any, context: DeparserContext): string {
9569
- const output: string[] = [];
9621
+ RangeTableFunc(node, context) {
9622
+ const output = [];
9570
9623
  if (node.lateral) {
9571
9624
  output.push('LATERAL');
9572
9625
  }
@@ -9589,8 +9642,8 @@ export class Deparser implements DeparserVisitor {
9589
9642
  }
9590
9643
  return output.join(' ');
9591
9644
  }
9592
- RangeTableFuncCol(node: any, context: DeparserContext): string {
9593
- const output: string[] = [];
9645
+ RangeTableFuncCol(node, context) {
9646
+ const output = [];
9594
9647
  if (node.colname) {
9595
9648
  output.push(QuoteUtils.quote(node.colname));
9596
9649
  }
@@ -9610,8 +9663,8 @@ export class Deparser implements DeparserVisitor {
9610
9663
  }
9611
9664
  return output.join(' ');
9612
9665
  }
9613
- JsonArrayQueryConstructor(node: any, context: DeparserContext): string {
9614
- const output: string[] = ['JSON_ARRAYAGG'];
9666
+ JsonArrayQueryConstructor(node, context) {
9667
+ const output = ['JSON_ARRAYAGG'];
9615
9668
  if (node.query) {
9616
9669
  output.push(`(${this.visit(node.query, context)})`);
9617
9670
  }
@@ -9629,8 +9682,8 @@ export class Deparser implements DeparserVisitor {
9629
9682
  }
9630
9683
  return output.join(' ');
9631
9684
  }
9632
- RangeFunction(node: any, context: DeparserContext): string {
9633
- const output: string[] = [];
9685
+ RangeFunction(node, context) {
9686
+ const output = [];
9634
9687
  if (node.lateral) {
9635
9688
  output.push('LATERAL');
9636
9689
  }
@@ -9644,16 +9697,16 @@ export class Deparser implements DeparserVisitor {
9644
9697
  const nodeType = this.getNodeType(func);
9645
9698
  if (nodeType === 'List') {
9646
9699
  // Handle List containing [FuncCall, List of ColumnDefs]
9647
- const listData = this.getNodeData(func) as any;
9700
+ const listData = this.getNodeData(func);
9648
9701
  if (listData && listData.items && Array.isArray(listData.items)) {
9649
9702
  const items = listData.items;
9650
9703
  if (items.length >= 2) {
9651
9704
  const funcCall = this.visit(items[0], context);
9652
- const coldefList = this.getNodeData(items[1]) as any;
9705
+ const coldefList = this.getNodeData(items[1]);
9653
9706
  if (coldefList && coldefList.items && Array.isArray(coldefList.items)) {
9654
9707
  const coldefs = coldefList.items
9655
- .map((coldef: any) => this.visit(coldef, context))
9656
- .filter((str: string) => str && str.trim());
9708
+ .map((coldef) => this.visit(coldef, context))
9709
+ .filter((str) => str && str.trim());
9657
9710
  if (coldefs.length > 0) {
9658
9711
  return `${funcCall} AS (${coldefs.join(', ')})`;
9659
9712
  }
@@ -9687,7 +9740,7 @@ export class Deparser implements DeparserVisitor {
9687
9740
  const nodeType = this.getNodeType(func);
9688
9741
  if (nodeType === 'List') {
9689
9742
  // Handle List containing [FuncCall, potentially empty second item]
9690
- const listData = this.getNodeData(func) as any;
9743
+ const listData = this.getNodeData(func);
9691
9744
  if (listData && listData.items && Array.isArray(listData.items)) {
9692
9745
  const items = listData.items;
9693
9746
  if (items.length >= 1) {
@@ -9733,7 +9786,7 @@ export class Deparser implements DeparserVisitor {
9733
9786
  }
9734
9787
  return output.join(' ');
9735
9788
  }
9736
- XmlExpr(node: any, context: DeparserContext): string {
9789
+ XmlExpr(node, context) {
9737
9790
  // Handle XMLPI with special syntax: xmlpi(name target, content)
9738
9791
  if (node.op === 'IS_XMLPI') {
9739
9792
  if (node.name && node.args && node.args.length > 0) {
@@ -9747,14 +9800,14 @@ export class Deparser implements DeparserVisitor {
9747
9800
  return 'XMLPI()';
9748
9801
  }
9749
9802
  }
9750
- const output: string[] = [];
9803
+ const output = [];
9751
9804
  switch (node.op) {
9752
9805
  case 'IS_XMLCONCAT':
9753
9806
  output.push('XMLCONCAT');
9754
9807
  break;
9755
9808
  case 'IS_XMLELEMENT':
9756
9809
  output.push('XMLELEMENT');
9757
- const elementParts: string[] = [];
9810
+ const elementParts = [];
9758
9811
  if (node.name) {
9759
9812
  elementParts.push(`NAME ${QuoteUtils.quote(node.name)}`);
9760
9813
  }
@@ -9775,7 +9828,7 @@ export class Deparser implements DeparserVisitor {
9775
9828
  break;
9776
9829
  case 'IS_XMLPARSE':
9777
9830
  output.push('XMLPARSE');
9778
- const parseParts: string[] = [];
9831
+ const parseParts = [];
9779
9832
  if (node.xmloption) {
9780
9833
  if (node.xmloption === 'XMLOPTION_DOCUMENT') {
9781
9834
  parseParts.push('DOCUMENT');
@@ -9798,7 +9851,7 @@ export class Deparser implements DeparserVisitor {
9798
9851
  output.push('XMLROOT');
9799
9852
  if (node.args && node.args.length > 0) {
9800
9853
  const args = ListUtils.unwrapList(node.args);
9801
- const rootParts: string[] = [];
9854
+ const rootParts = [];
9802
9855
  if (args[0]) {
9803
9856
  rootParts.push(this.visit(args[0], context));
9804
9857
  }
@@ -9875,7 +9928,7 @@ export class Deparser implements DeparserVisitor {
9875
9928
  }
9876
9929
  return output.join(' ');
9877
9930
  }
9878
- schemaname(node: any, context: DeparserContext): string {
9931
+ schemaname(node, context) {
9879
9932
  if (typeof node === 'string') {
9880
9933
  return QuoteUtils.quote(node);
9881
9934
  }
@@ -9902,28 +9955,28 @@ export class Deparser implements DeparserVisitor {
9902
9955
  }
9903
9956
  return '';
9904
9957
  }
9905
- RangeTableSample(node: any, context: DeparserContext): string {
9906
- const output: string[] = [];
9958
+ RangeTableSample(node, context) {
9959
+ const output = [];
9907
9960
  if (node.relation) {
9908
- output.push(this.visit(node.relation as any, context));
9961
+ output.push(this.visit(node.relation, context));
9909
9962
  }
9910
9963
  output.push('TABLESAMPLE');
9911
9964
  if (node.method && node.method.length > 0) {
9912
- const methodParts = node.method.map((m: any) => this.visit(m, context));
9965
+ const methodParts = node.method.map((m) => this.visit(m, context));
9913
9966
  output.push(methodParts.join('.'));
9914
9967
  }
9915
9968
  if (node.args && node.args.length > 0) {
9916
- const argStrs = node.args.map((arg: any) => this.visit(arg, context));
9969
+ const argStrs = node.args.map((arg) => this.visit(arg, context));
9917
9970
  output.push(`(${argStrs.join(', ')})`);
9918
9971
  }
9919
9972
  if (node.repeatable) {
9920
9973
  output.push('REPEATABLE');
9921
- output.push(`(${this.visit(node.repeatable as any, context)})`);
9974
+ output.push(`(${this.visit(node.repeatable, context)})`);
9922
9975
  }
9923
9976
  return output.join(' ');
9924
9977
  }
9925
- XmlSerialize(node: any, context: DeparserContext): string {
9926
- const output: string[] = ['XMLSERIALIZE'];
9978
+ XmlSerialize(node, context) {
9979
+ const output = ['XMLSERIALIZE'];
9927
9980
  output.push('(');
9928
9981
  if (node.typeName) {
9929
9982
  if (node.xmloption === 'XMLOPTION_DOCUMENT') {
@@ -9932,18 +9985,18 @@ export class Deparser implements DeparserVisitor {
9932
9985
  else {
9933
9986
  output.push('CONTENT');
9934
9987
  }
9935
- output.push(this.visit(node.expr as any, context));
9988
+ output.push(this.visit(node.expr, context));
9936
9989
  output.push('AS');
9937
9990
  output.push(this.TypeName(node.typeName, context));
9938
9991
  }
9939
9992
  output.push(')');
9940
9993
  return output.join(' ');
9941
9994
  }
9942
- ctes(node: any, context: DeparserContext): string {
9995
+ ctes(node, context) {
9943
9996
  if (!node || !Array.isArray(node)) {
9944
9997
  return '';
9945
9998
  }
9946
- const output: string[] = ['WITH'];
9999
+ const output = ['WITH'];
9947
10000
  // Check if any CTE is recursive by examining the first CTE's structure
9948
10001
  if (node.length > 0 && node[0] && node[0].CommonTableExpr && node[0].CommonTableExpr.recursive) {
9949
10002
  output.push('RECURSIVE');
@@ -9952,8 +10005,8 @@ export class Deparser implements DeparserVisitor {
9952
10005
  output.push(cteStrs.join(', '));
9953
10006
  return output.join(' ');
9954
10007
  }
9955
- RuleStmt(node: any, context: DeparserContext): string {
9956
- const output: string[] = ['CREATE'];
10008
+ RuleStmt(node, context) {
10009
+ const output = ['CREATE'];
9957
10010
  if (node.replace) {
9958
10011
  output.push('OR REPLACE');
9959
10012
  }
@@ -9983,7 +10036,7 @@ export class Deparser implements DeparserVisitor {
9983
10036
  output.push('TO');
9984
10037
  if (node.relation) {
9985
10038
  // Handle relation node directly as RangeVar since it contains the RangeVar properties
9986
- output.push(this.RangeVar(node.relation as any, context));
10039
+ output.push(this.RangeVar(node.relation, context));
9987
10040
  }
9988
10041
  if (node.whereClause) {
9989
10042
  output.push('WHERE');
@@ -10009,8 +10062,8 @@ export class Deparser implements DeparserVisitor {
10009
10062
  }
10010
10063
  return output.join(' ');
10011
10064
  }
10012
- RangeSubselect(node: any, context: DeparserContext): string {
10013
- const output: string[] = [];
10065
+ RangeSubselect(node, context) {
10066
+ const output = [];
10014
10067
  if (node.lateral) {
10015
10068
  output.push('LATERAL');
10016
10069
  }
@@ -10024,7 +10077,7 @@ export class Deparser implements DeparserVisitor {
10024
10077
  }
10025
10078
  return output.join(' ');
10026
10079
  }
10027
- relname(node: any, context: DeparserContext): string {
10080
+ relname(node, context) {
10028
10081
  if (typeof node === 'string') {
10029
10082
  return QuoteUtils.quote(node);
10030
10083
  }
@@ -10036,7 +10089,7 @@ export class Deparser implements DeparserVisitor {
10036
10089
  }
10037
10090
  return this.visit(node, context);
10038
10091
  }
10039
- rel(node: any, context: DeparserContext): string {
10092
+ rel(node, context) {
10040
10093
  if (typeof node === 'string') {
10041
10094
  return QuoteUtils.quote(node);
10042
10095
  }
@@ -10051,7 +10104,7 @@ export class Deparser implements DeparserVisitor {
10051
10104
  }
10052
10105
  return this.visit(node, context);
10053
10106
  }
10054
- objname(node: any, context: DeparserContext): string {
10107
+ objname(node, context) {
10055
10108
  if (typeof node === 'string') {
10056
10109
  return QuoteUtils.quote(node);
10057
10110
  }
@@ -10069,7 +10122,7 @@ export class Deparser implements DeparserVisitor {
10069
10122
  }
10070
10123
  return this.visit(node, context);
10071
10124
  }
10072
- SQLValueFunction(node: any, context: DeparserContext): string {
10125
+ SQLValueFunction(node, context) {
10073
10126
  switch (node.op) {
10074
10127
  case 'SVFOP_CURRENT_DATE':
10075
10128
  return 'CURRENT_DATE';
@@ -10105,8 +10158,8 @@ export class Deparser implements DeparserVisitor {
10105
10158
  throw new Error(`Unsupported SQLValueFunction op: ${node.op}`);
10106
10159
  }
10107
10160
  }
10108
- GroupingFunc(node: any, context: DeparserContext): string {
10109
- const output: string[] = ['GROUPING'];
10161
+ GroupingFunc(node, context) {
10162
+ const output = ['GROUPING'];
10110
10163
  if (node.args && node.args.length > 0) {
10111
10164
  const argStrs = ListUtils.unwrapList(node.args).map(arg => this.visit(arg, context));
10112
10165
  output.push(`(${argStrs.join(', ')})`);
@@ -10116,8 +10169,8 @@ export class Deparser implements DeparserVisitor {
10116
10169
  }
10117
10170
  return output.join('');
10118
10171
  }
10119
- MultiAssignRef(node: any, context: DeparserContext): string {
10120
- const output: string[] = [];
10172
+ MultiAssignRef(node, context) {
10173
+ const output = [];
10121
10174
  if (node.source) {
10122
10175
  output.push(this.visit(node.source, context));
10123
10176
  }
@@ -10126,11 +10179,11 @@ export class Deparser implements DeparserVisitor {
10126
10179
  }
10127
10180
  return output.join('');
10128
10181
  }
10129
- SetToDefault(node: any, context: DeparserContext): string {
10182
+ SetToDefault(node, context) {
10130
10183
  return 'DEFAULT';
10131
10184
  }
10132
- CurrentOfExpr(node: any, context: DeparserContext): string {
10133
- const output: string[] = ['CURRENT OF'];
10185
+ CurrentOfExpr(node, context) {
10186
+ const output = ['CURRENT OF'];
10134
10187
  if (node.cursor_name) {
10135
10188
  output.push(QuoteUtils.quote(node.cursor_name));
10136
10189
  }
@@ -10139,10 +10192,10 @@ export class Deparser implements DeparserVisitor {
10139
10192
  }
10140
10193
  return output.join(' ');
10141
10194
  }
10142
- TableLikeClause(node: any, context: DeparserContext): string {
10143
- const output: string[] = ['LIKE'];
10195
+ TableLikeClause(node, context) {
10196
+ const output = ['LIKE'];
10144
10197
  if (node.relation) {
10145
- output.push(this.visit(node.relation as any, context));
10198
+ output.push(this.visit(node.relation, context));
10146
10199
  }
10147
10200
  if (node.options && typeof node.options === 'number') {
10148
10201
  // Handle special case for INCLUDING ALL (all bits set)
@@ -10150,7 +10203,7 @@ export class Deparser implements DeparserVisitor {
10150
10203
  output.push('INCLUDING ALL');
10151
10204
  }
10152
10205
  else {
10153
- const optionStrs: string[] = [];
10206
+ const optionStrs = [];
10154
10207
  // Handle bitfield options for CREATE TABLE LIKE
10155
10208
  if (node.options & 0x01)
10156
10209
  optionStrs.push('INCLUDING COMMENTS');
@@ -10175,8 +10228,8 @@ export class Deparser implements DeparserVisitor {
10175
10228
  }
10176
10229
  return output.join(' ');
10177
10230
  }
10178
- AlterFunctionStmt(node: any, context: DeparserContext): string {
10179
- const output: string[] = ['ALTER'];
10231
+ AlterFunctionStmt(node, context) {
10232
+ const output = ['ALTER'];
10180
10233
  if (node.objtype === 'OBJECT_PROCEDURE') {
10181
10234
  output.push('PROCEDURE');
10182
10235
  }
@@ -10193,68 +10246,14 @@ export class Deparser implements DeparserVisitor {
10193
10246
  }
10194
10247
  return output.join(' ');
10195
10248
  }
10196
- AlterObjectSchemaStmt(node: any, context: DeparserContext): string {
10197
- const output: string[] = ['ALTER'];
10198
- switch (node.objectType) {
10199
- case 'OBJECT_TABLE':
10200
- output.push('TABLE');
10201
- break;
10202
- case 'OBJECT_VIEW':
10203
- output.push('VIEW');
10204
- break;
10205
- case 'OBJECT_FUNCTION':
10206
- output.push('FUNCTION');
10207
- break;
10208
- case 'OBJECT_TYPE':
10209
- output.push('TYPE');
10210
- break;
10211
- case 'OBJECT_DOMAIN':
10212
- output.push('DOMAIN');
10213
- break;
10214
- case 'OBJECT_SEQUENCE':
10215
- output.push('SEQUENCE');
10216
- break;
10217
- case 'OBJECT_OPCLASS':
10218
- output.push('OPERATOR CLASS');
10219
- break;
10220
- case 'OBJECT_OPFAMILY':
10221
- output.push('OPERATOR FAMILY');
10222
- break;
10223
- case 'OBJECT_OPERATOR':
10224
- output.push('OPERATOR');
10225
- break;
10226
- case 'OBJECT_TYPE':
10227
- output.push('TYPE');
10228
- break;
10229
- case 'OBJECT_COLLATION':
10230
- output.push('COLLATION');
10231
- break;
10232
- case 'OBJECT_CONVERSION':
10233
- output.push('CONVERSION');
10234
- break;
10235
- case 'OBJECT_TSPARSER':
10236
- output.push('TEXT SEARCH PARSER');
10237
- break;
10238
- case 'OBJECT_TSCONFIGURATION':
10239
- output.push('TEXT SEARCH CONFIGURATION');
10240
- break;
10241
- case 'OBJECT_TSTEMPLATE':
10242
- output.push('TEXT SEARCH TEMPLATE');
10243
- break;
10244
- case 'OBJECT_TSDICTIONARY':
10245
- output.push('TEXT SEARCH DICTIONARY');
10246
- break;
10247
- case 'OBJECT_AGGREGATE':
10248
- output.push('AGGREGATE');
10249
- break;
10250
- case 'OBJECT_FOREIGN_TABLE':
10251
- output.push('FOREIGN TABLE');
10252
- break;
10253
- case 'OBJECT_MATVIEW':
10254
- output.push('MATERIALIZED VIEW');
10255
- break;
10256
- default:
10257
- output.push(node.objectType.toString());
10249
+ AlterObjectSchemaStmt(node, context) {
10250
+ const output = ['ALTER'];
10251
+ try {
10252
+ output.push(this.getObjectTypeKeyword(node.objectType));
10253
+ }
10254
+ catch {
10255
+ // Fallback to objectType string if not supported
10256
+ output.push(node.objectType.toString());
10258
10257
  }
10259
10258
  if (node.missing_ok) {
10260
10259
  output.push('IF EXISTS');
@@ -10264,92 +10263,92 @@ export class Deparser implements DeparserVisitor {
10264
10263
  }
10265
10264
  else if (node.object) {
10266
10265
  // Handle domain objects specially to format schema.domain correctly
10267
- if (node.objectType === 'OBJECT_DOMAIN' && (node.object as any).List) {
10268
- const items = ListUtils.unwrapList(node.object as any);
10266
+ if (node.objectType === 'OBJECT_DOMAIN' && node.object.List) {
10267
+ const items = ListUtils.unwrapList(node.object);
10269
10268
  if (items.length === 2) {
10270
10269
  const schemaName = items[0].String?.sval || '';
10271
10270
  const domainName = items[1].String?.sval || '';
10272
10271
  output.push(`${QuoteUtils.quote(schemaName)}.${QuoteUtils.quote(domainName)}`);
10273
10272
  }
10274
10273
  else {
10275
- output.push(this.visit(node.object as any, context));
10274
+ output.push(this.visit(node.object, context));
10276
10275
  }
10277
10276
  }
10278
- else if (node.objectType === 'OBJECT_TYPE' && (node.object as any).List) {
10277
+ else if (node.objectType === 'OBJECT_TYPE' && node.object.List) {
10279
10278
  // Handle type objects specially to format schema.type correctly
10280
- const items = ListUtils.unwrapList(node.object as any);
10279
+ const items = ListUtils.unwrapList(node.object);
10281
10280
  if (items.length === 2) {
10282
10281
  const schemaName = items[0].String?.sval || '';
10283
10282
  const typeName = items[1].String?.sval || '';
10284
10283
  output.push(`${QuoteUtils.quote(schemaName)}.${QuoteUtils.quote(typeName)}`);
10285
10284
  }
10286
10285
  else {
10287
- output.push(this.visit(node.object as any, context));
10286
+ output.push(this.visit(node.object, context));
10288
10287
  }
10289
10288
  }
10290
- else if (node.objectType === 'OBJECT_CONVERSION' && (node.object as any).List) {
10289
+ else if (node.objectType === 'OBJECT_CONVERSION' && node.object.List) {
10291
10290
  // Handle conversion objects specially to format schema.conversion correctly
10292
- const items = ListUtils.unwrapList(node.object as any);
10291
+ const items = ListUtils.unwrapList(node.object);
10293
10292
  if (items.length === 2) {
10294
10293
  const schemaName = items[0].String?.sval || '';
10295
10294
  const conversionName = items[1].String?.sval || '';
10296
10295
  output.push(`${QuoteUtils.quote(schemaName)}.${QuoteUtils.quote(conversionName)}`);
10297
10296
  }
10298
10297
  else {
10299
- output.push(this.visit(node.object as any, context));
10298
+ output.push(this.visit(node.object, context));
10300
10299
  }
10301
10300
  }
10302
- else if (node.objectType === 'OBJECT_TSPARSER' && (node.object as any).List) {
10301
+ else if (node.objectType === 'OBJECT_TSPARSER' && node.object.List) {
10303
10302
  // Handle text search parser objects specially to format schema.parser correctly
10304
- const items = ListUtils.unwrapList(node.object as any);
10303
+ const items = ListUtils.unwrapList(node.object);
10305
10304
  if (items.length === 2) {
10306
10305
  const schemaName = items[0].String?.sval || '';
10307
10306
  const parserName = items[1].String?.sval || '';
10308
10307
  output.push(`${QuoteUtils.quote(schemaName)}.${QuoteUtils.quote(parserName)}`);
10309
10308
  }
10310
10309
  else {
10311
- output.push(this.visit(node.object as any, context));
10310
+ output.push(this.visit(node.object, context));
10312
10311
  }
10313
10312
  }
10314
- else if (node.objectType === 'OBJECT_TSCONFIGURATION' && (node.object as any).List) {
10313
+ else if (node.objectType === 'OBJECT_TSCONFIGURATION' && node.object.List) {
10315
10314
  // Handle text search configuration objects specially to format schema.config correctly
10316
- const items = ListUtils.unwrapList(node.object as any);
10315
+ const items = ListUtils.unwrapList(node.object);
10317
10316
  if (items.length === 2) {
10318
10317
  const schemaName = items[0].String?.sval || '';
10319
10318
  const configName = items[1].String?.sval || '';
10320
10319
  output.push(`${QuoteUtils.quote(schemaName)}.${QuoteUtils.quote(configName)}`);
10321
10320
  }
10322
10321
  else {
10323
- output.push(this.visit(node.object as any, context));
10322
+ output.push(this.visit(node.object, context));
10324
10323
  }
10325
10324
  }
10326
- else if (node.objectType === 'OBJECT_TSTEMPLATE' && (node.object as any).List) {
10325
+ else if (node.objectType === 'OBJECT_TSTEMPLATE' && node.object.List) {
10327
10326
  // Handle text search template objects specially to format schema.template correctly
10328
- const items = ListUtils.unwrapList(node.object as any);
10327
+ const items = ListUtils.unwrapList(node.object);
10329
10328
  if (items.length === 2) {
10330
10329
  const schemaName = items[0].String?.sval || '';
10331
10330
  const templateName = items[1].String?.sval || '';
10332
10331
  output.push(`${QuoteUtils.quote(schemaName)}.${QuoteUtils.quote(templateName)}`);
10333
10332
  }
10334
10333
  else {
10335
- output.push(this.visit(node.object as any, context));
10334
+ output.push(this.visit(node.object, context));
10336
10335
  }
10337
10336
  }
10338
- else if (node.objectType === 'OBJECT_TSDICTIONARY' && (node.object as any).List) {
10337
+ else if (node.objectType === 'OBJECT_TSDICTIONARY' && node.object.List) {
10339
10338
  // Handle text search dictionary objects specially to format schema.dictionary correctly
10340
- const items = ListUtils.unwrapList(node.object as any);
10339
+ const items = ListUtils.unwrapList(node.object);
10341
10340
  if (items.length === 2) {
10342
10341
  const schemaName = items[0].String?.sval || '';
10343
10342
  const dictionaryName = items[1].String?.sval || '';
10344
10343
  output.push(`${QuoteUtils.quote(schemaName)}.${QuoteUtils.quote(dictionaryName)}`);
10345
10344
  }
10346
10345
  else {
10347
- output.push(this.visit(node.object as any, context));
10346
+ output.push(this.visit(node.object, context));
10348
10347
  }
10349
10348
  }
10350
- else if (node.objectType === 'OBJECT_OPCLASS' && (node.object as any).List) {
10349
+ else if (node.objectType === 'OBJECT_OPCLASS' && node.object.List) {
10351
10350
  // Handle operator class objects: ALTER OPERATOR CLASS name USING access_method
10352
- const items = ListUtils.unwrapList(node.object as any);
10351
+ const items = ListUtils.unwrapList(node.object);
10353
10352
  if (items.length === 2) {
10354
10353
  const accessMethod = items[0].String?.sval || '';
10355
10354
  const opClassName = items[1].String?.sval || '';
@@ -10362,12 +10361,12 @@ export class Deparser implements DeparserVisitor {
10362
10361
  output.push(`${QuoteUtils.quote(schemaName)}.${QuoteUtils.quote(opClassName)} USING ${accessMethod}`);
10363
10362
  }
10364
10363
  else {
10365
- output.push(this.visit(node.object as any, context));
10364
+ output.push(this.visit(node.object, context));
10366
10365
  }
10367
10366
  }
10368
- else if (node.objectType === 'OBJECT_OPFAMILY' && (node.object as any).List) {
10367
+ else if (node.objectType === 'OBJECT_OPFAMILY' && node.object.List) {
10369
10368
  // Handle operator family objects: ALTER OPERATOR FAMILY name USING access_method
10370
- const items = ListUtils.unwrapList(node.object as any);
10369
+ const items = ListUtils.unwrapList(node.object);
10371
10370
  if (items.length === 2) {
10372
10371
  const accessMethod = items[0].String?.sval || '';
10373
10372
  const opFamilyName = items[1].String?.sval || '';
@@ -10380,11 +10379,11 @@ export class Deparser implements DeparserVisitor {
10380
10379
  output.push(`${QuoteUtils.quote(schemaName)}.${QuoteUtils.quote(opFamilyName)} USING ${accessMethod}`);
10381
10380
  }
10382
10381
  else {
10383
- output.push(this.visit(node.object as any, context));
10382
+ output.push(this.visit(node.object, context));
10384
10383
  }
10385
10384
  }
10386
10385
  else {
10387
- output.push(this.visit(node.object as any, context));
10386
+ output.push(this.visit(node.object, context));
10388
10387
  }
10389
10388
  }
10390
10389
  output.push('SET SCHEMA');
@@ -10393,8 +10392,8 @@ export class Deparser implements DeparserVisitor {
10393
10392
  }
10394
10393
  return output.join(' ');
10395
10394
  }
10396
- AlterRoleSetStmt(node: any, context: DeparserContext): string {
10397
- const output: string[] = ['ALTER', 'ROLE'];
10395
+ AlterRoleSetStmt(node, context) {
10396
+ const output = ['ALTER', 'ROLE'];
10398
10397
  if (node.role) {
10399
10398
  output.push(this.RoleSpec(node.role, context));
10400
10399
  }
@@ -10428,12 +10427,12 @@ export class Deparser implements DeparserVisitor {
10428
10427
  }
10429
10428
  return output.join(' ');
10430
10429
  }
10431
- CreateForeignTableStmt(node: any, context: DeparserContext): string {
10432
- const output: string[] = ['CREATE FOREIGN TABLE'];
10430
+ CreateForeignTableStmt(node, context) {
10431
+ const output = ['CREATE FOREIGN TABLE'];
10433
10432
  if (node.base && node.base.relation) {
10434
10433
  const relationContext = context.spawn('CreateForeignTableStmt');
10435
10434
  // Handle relation node directly as RangeVar since it contains the RangeVar properties
10436
- output.push(this.RangeVar(node.base.relation as any, relationContext));
10435
+ output.push(this.RangeVar(node.base.relation, relationContext));
10437
10436
  }
10438
10437
  if (node.base && node.base.tableElts) {
10439
10438
  const elementStrs = ListUtils.unwrapList(node.base.tableElts).map(el => this.visit(el, context));
@@ -10467,7 +10466,7 @@ export class Deparser implements DeparserVisitor {
10467
10466
  }
10468
10467
  return output.join(' ');
10469
10468
  }
10470
- private containsMultilineStringLiteral(content: string): boolean {
10469
+ containsMultilineStringLiteral(content) {
10471
10470
  const stringLiteralRegex = /'[^']*\n[^']*'/g;
10472
10471
  return stringLiteralRegex.test(content);
10473
10472
  }