@pgsql/transform 17.6.2 → 17.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/13/enum-to-int.d.ts +7 -0
  2. package/13/enum-to-int.js +2165 -0
  3. package/13/enum-to-str.d.ts +7 -0
  4. package/13/enum-to-str.js +2165 -0
  5. package/13/enums.d.ts +15 -22
  6. package/13/runtime-schema.d.ts +17 -0
  7. package/13/runtime-schema.js +8419 -0
  8. package/13/types.d.ts +1079 -1304
  9. package/14/enum-to-int.d.ts +7 -0
  10. package/14/enum-to-int.js +2205 -0
  11. package/14/enum-to-str.d.ts +7 -0
  12. package/14/enum-to-str.js +2205 -0
  13. package/14/enums.d.ts +62 -0
  14. package/14/enums.js +2 -0
  15. package/14/runtime-schema.d.ts +17 -0
  16. package/14/runtime-schema.js +8695 -0
  17. package/14/types.d.ts +2164 -0
  18. package/14/types.js +2 -0
  19. package/15/enum-to-int.d.ts +7 -0
  20. package/15/enum-to-int.js +2255 -0
  21. package/15/enum-to-str.d.ts +7 -0
  22. package/15/enum-to-str.js +2255 -0
  23. package/15/enums.d.ts +64 -0
  24. package/15/enums.js +2 -0
  25. package/15/runtime-schema.d.ts +17 -0
  26. package/15/runtime-schema.js +8955 -0
  27. package/15/types.d.ts +2222 -0
  28. package/15/types.js +2 -0
  29. package/16/enum-to-int.d.ts +7 -0
  30. package/16/enum-to-int.js +2344 -0
  31. package/16/enum-to-str.d.ts +7 -0
  32. package/16/enum-to-str.js +2344 -0
  33. package/16/enums.d.ts +69 -0
  34. package/16/enums.js +2 -0
  35. package/16/runtime-schema.d.ts +17 -0
  36. package/16/runtime-schema.js +9339 -0
  37. package/16/types.d.ts +2328 -0
  38. package/16/types.js +2 -0
  39. package/17/enum-to-int.d.ts +7 -0
  40. package/17/enum-to-int.js +2501 -0
  41. package/17/enum-to-str.d.ts +7 -0
  42. package/17/enum-to-str.js +2501 -0
  43. package/17/enums.d.ts +1 -1
  44. package/17/runtime-schema.d.ts +17 -0
  45. package/17/runtime-schema.js +10010 -0
  46. package/17/types.d.ts +1 -1
  47. package/esm/13/enum-to-int.js +2161 -0
  48. package/esm/13/enum-to-str.js +2161 -0
  49. package/esm/13/runtime-schema.js +8416 -0
  50. package/esm/14/enum-to-int.js +2201 -0
  51. package/esm/14/enum-to-str.js +2201 -0
  52. package/esm/14/enums.js +1 -0
  53. package/esm/14/runtime-schema.js +8692 -0
  54. package/esm/14/types.js +1 -0
  55. package/esm/15/enum-to-int.js +2251 -0
  56. package/esm/15/enum-to-str.js +2251 -0
  57. package/esm/15/enums.js +1 -0
  58. package/esm/15/runtime-schema.js +8952 -0
  59. package/esm/15/types.js +1 -0
  60. package/esm/16/enum-to-int.js +2340 -0
  61. package/esm/16/enum-to-str.js +2340 -0
  62. package/esm/16/enums.js +1 -0
  63. package/esm/16/runtime-schema.js +9336 -0
  64. package/esm/16/types.js +1 -0
  65. package/esm/17/enum-to-int.js +2497 -0
  66. package/esm/17/enum-to-str.js +2497 -0
  67. package/esm/17/runtime-schema.js +10007 -0
  68. package/esm/index.js +15 -1309
  69. package/esm/multi-version-transformer.js +60 -0
  70. package/esm/transformers/context.js +1 -0
  71. package/esm/transformers/v13-to-v14.js +2745 -0
  72. package/esm/transformers/v14-to-v15.js +1215 -0
  73. package/esm/transformers/v15-to-v16.js +2876 -0
  74. package/esm/transformers/v16-to-v17.js +1483 -0
  75. package/esm/transformers-direct/index.js +8 -0
  76. package/esm/transformers-direct/v13-to-v17/index.js +74 -0
  77. package/esm/transformers-direct/v14-to-v17/index.js +63 -0
  78. package/esm/transformers-direct/v15-to-v17/index.js +53 -0
  79. package/esm/transformers-direct/v16-to-v17/index.js +40 -0
  80. package/index.d.ts +18 -5
  81. package/index.js +29 -1311
  82. package/multi-version-transformer.d.ts +9 -0
  83. package/multi-version-transformer.js +64 -0
  84. package/package.json +8 -4
  85. package/transformers/context.d.ts +4 -0
  86. package/transformers/context.js +2 -0
  87. package/transformers/v13-to-v14.d.ts +252 -0
  88. package/transformers/v13-to-v14.js +2749 -0
  89. package/transformers/v14-to-v15.d.ts +615 -0
  90. package/transformers/v14-to-v15.js +1219 -0
  91. package/transformers/v15-to-v16.d.ts +626 -0
  92. package/transformers/v15-to-v16.js +2880 -0
  93. package/transformers/v16-to-v17.d.ts +637 -0
  94. package/transformers/v16-to-v17.js +1487 -0
  95. package/transformers-direct/index.d.ts +8 -0
  96. package/transformers-direct/index.js +15 -0
  97. package/transformers-direct/v13-to-v17/index.d.ts +27 -0
  98. package/transformers-direct/v13-to-v17/index.js +78 -0
  99. package/transformers-direct/v14-to-v17/index.d.ts +26 -0
  100. package/transformers-direct/v14-to-v17/index.js +67 -0
  101. package/transformers-direct/v15-to-v17/index.d.ts +25 -0
  102. package/transformers-direct/v15-to-v17/index.js +57 -0
  103. package/transformers-direct/v16-to-v17/index.d.ts +24 -0
  104. package/transformers-direct/v16-to-v17/index.js +44 -0
@@ -0,0 +1,1483 @@
1
+ /**
2
+ * V16 to V17 AST Transformer
3
+ * Transforms PostgreSQL v16 AST nodes to v17 format
4
+ */
5
+ export class V16ToV17Transformer {
6
+ transform(node, context = { parentNodeTypes: [] }) {
7
+ if (node == null) {
8
+ return null;
9
+ }
10
+ if (typeof node === 'number' || node instanceof Number) {
11
+ return node;
12
+ }
13
+ if (typeof node === 'string') {
14
+ return node;
15
+ }
16
+ try {
17
+ return this.visit(node, context);
18
+ }
19
+ catch (error) {
20
+ const nodeType = Object.keys(node)[0];
21
+ throw new Error(`Error transforming ${nodeType}: ${error.message}`);
22
+ }
23
+ }
24
+ visit(node, context = { parentNodeTypes: [] }) {
25
+ const nodeType = this.getNodeType(node);
26
+ // Handle empty objects
27
+ if (!nodeType) {
28
+ return {};
29
+ }
30
+ const nodeData = this.getNodeData(node);
31
+ const methodName = nodeType;
32
+ if (typeof this[methodName] === 'function') {
33
+ const childContext = {
34
+ ...context,
35
+ parentNodeTypes: [...context.parentNodeTypes, nodeType]
36
+ };
37
+ const result = this[methodName](nodeData, childContext);
38
+ return result;
39
+ }
40
+ // If no specific method, return the node as-is
41
+ return node;
42
+ }
43
+ getNodeType(node) {
44
+ return Object.keys(node)[0];
45
+ }
46
+ getNodeData(node) {
47
+ const keys = Object.keys(node);
48
+ if (keys.length === 1 && typeof node[keys[0]] === 'object') {
49
+ return node[keys[0]];
50
+ }
51
+ return node;
52
+ }
53
+ ParseResult(node, context) {
54
+ if (node && typeof node === 'object' && 'version' in node && 'stmts' in node) {
55
+ return {
56
+ version: 170004, // PG17 version
57
+ stmts: node.stmts.map((stmt) => {
58
+ if (stmt && typeof stmt === 'object' && 'stmt' in stmt) {
59
+ return {
60
+ ...stmt,
61
+ stmt: this.transform(stmt.stmt, context)
62
+ };
63
+ }
64
+ return this.transform(stmt, context);
65
+ })
66
+ };
67
+ }
68
+ return node;
69
+ }
70
+ RawStmt(node, context) {
71
+ const result = {};
72
+ if (node.stmt !== undefined) {
73
+ result.stmt = this.transform(node.stmt, context);
74
+ }
75
+ if (node.stmt_location !== undefined) {
76
+ result.stmt_location = node.stmt_location;
77
+ }
78
+ if (node.stmt_len !== undefined) {
79
+ result.stmt_len = node.stmt_len;
80
+ }
81
+ return { RawStmt: result };
82
+ }
83
+ SelectStmt(node, context) {
84
+ const result = {};
85
+ if (node.distinctClause !== undefined) {
86
+ result.distinctClause = Array.isArray(node.distinctClause)
87
+ ? node.distinctClause.map(item => this.transform(item, context))
88
+ : this.transform(node.distinctClause, context);
89
+ }
90
+ if (node.intoClause !== undefined) {
91
+ result.intoClause = this.transform(node.intoClause, context);
92
+ }
93
+ if (node.targetList !== undefined) {
94
+ result.targetList = Array.isArray(node.targetList)
95
+ ? node.targetList.map(item => this.transform(item, context))
96
+ : this.transform(node.targetList, context);
97
+ }
98
+ if (node.fromClause !== undefined) {
99
+ result.fromClause = Array.isArray(node.fromClause)
100
+ ? node.fromClause.map(item => this.transform(item, context))
101
+ : this.transform(node.fromClause, context);
102
+ }
103
+ if (node.whereClause !== undefined) {
104
+ result.whereClause = this.transform(node.whereClause, context);
105
+ }
106
+ if (node.groupClause !== undefined) {
107
+ result.groupClause = Array.isArray(node.groupClause)
108
+ ? node.groupClause.map(item => this.transform(item, context))
109
+ : this.transform(node.groupClause, context);
110
+ }
111
+ if (node.groupDistinct !== undefined) {
112
+ result.groupDistinct = node.groupDistinct;
113
+ }
114
+ if (node.havingClause !== undefined) {
115
+ result.havingClause = this.transform(node.havingClause, context);
116
+ }
117
+ if (node.windowClause !== undefined) {
118
+ result.windowClause = Array.isArray(node.windowClause)
119
+ ? node.windowClause.map(item => this.transform(item, context))
120
+ : this.transform(node.windowClause, context);
121
+ }
122
+ if (node.valuesLists !== undefined) {
123
+ const valuesContext = {
124
+ ...context,
125
+ inValuesClause: true
126
+ };
127
+ result.valuesLists = Array.isArray(node.valuesLists)
128
+ ? node.valuesLists.map(item => Array.isArray(item)
129
+ ? item.map(subItem => this.transform(subItem, valuesContext))
130
+ : this.transform(item, valuesContext))
131
+ : this.transform(node.valuesLists, valuesContext);
132
+ }
133
+ if (node.sortClause !== undefined) {
134
+ result.sortClause = Array.isArray(node.sortClause)
135
+ ? node.sortClause.map(item => this.transform(item, context))
136
+ : this.transform(node.sortClause, context);
137
+ }
138
+ if (node.limitOffset !== undefined) {
139
+ result.limitOffset = this.transform(node.limitOffset, context);
140
+ }
141
+ if (node.limitCount !== undefined) {
142
+ result.limitCount = this.transform(node.limitCount, context);
143
+ }
144
+ if (node.limitOption !== undefined) {
145
+ result.limitOption = node.limitOption;
146
+ }
147
+ if (node.lockingClause !== undefined) {
148
+ result.lockingClause = Array.isArray(node.lockingClause)
149
+ ? node.lockingClause.map(item => this.transform(item, context))
150
+ : this.transform(node.lockingClause, context);
151
+ }
152
+ if (node.withClause !== undefined) {
153
+ result.withClause = this.transform(node.withClause, context);
154
+ }
155
+ if (node.op !== undefined) {
156
+ result.op = node.op;
157
+ }
158
+ if (node.all !== undefined) {
159
+ result.all = node.all;
160
+ }
161
+ if (node.larg !== undefined) {
162
+ result.larg = this.transform(node.larg, context);
163
+ }
164
+ if (node.rarg !== undefined) {
165
+ result.rarg = this.transform(node.rarg, context);
166
+ }
167
+ return { SelectStmt: result };
168
+ }
169
+ A_Expr(node, context) {
170
+ const result = {};
171
+ if (node.kind !== undefined) {
172
+ result.kind = node.kind;
173
+ }
174
+ if (node.name !== undefined) {
175
+ result.name = Array.isArray(node.name)
176
+ ? node.name.map(item => this.transform(item, context))
177
+ : this.transform(node.name, context);
178
+ }
179
+ if (node.lexpr !== undefined) {
180
+ result.lexpr = this.transform(node.lexpr, context);
181
+ }
182
+ if (node.rexpr !== undefined) {
183
+ result.rexpr = this.transform(node.rexpr, context);
184
+ }
185
+ if (node.location !== undefined) {
186
+ result.location = node.location;
187
+ }
188
+ return { A_Expr: result };
189
+ }
190
+ InsertStmt(node, context) {
191
+ const result = {};
192
+ if (node.relation !== undefined) {
193
+ result.relation = this.transform(node.relation, context);
194
+ }
195
+ if (node.cols !== undefined) {
196
+ result.cols = Array.isArray(node.cols)
197
+ ? node.cols.map(item => this.transform(item, context))
198
+ : this.transform(node.cols, context);
199
+ }
200
+ if (node.selectStmt !== undefined) {
201
+ result.selectStmt = this.transform(node.selectStmt, context);
202
+ }
203
+ if (node.onConflictClause !== undefined) {
204
+ result.onConflictClause = this.transform(node.onConflictClause, context);
205
+ }
206
+ if (node.returningList !== undefined) {
207
+ result.returningList = Array.isArray(node.returningList)
208
+ ? node.returningList.map(item => this.transform(item, context))
209
+ : this.transform(node.returningList, context);
210
+ }
211
+ if (node.withClause !== undefined) {
212
+ result.withClause = this.transform(node.withClause, context);
213
+ }
214
+ if (node.override !== undefined) {
215
+ result.override = node.override;
216
+ }
217
+ return { InsertStmt: result };
218
+ }
219
+ UpdateStmt(node, context) {
220
+ const result = {};
221
+ if (node.relation !== undefined) {
222
+ result.relation = this.transform(node.relation, context);
223
+ }
224
+ if (node.targetList !== undefined) {
225
+ result.targetList = Array.isArray(node.targetList)
226
+ ? node.targetList.map(item => this.transform(item, context))
227
+ : this.transform(node.targetList, context);
228
+ }
229
+ if (node.whereClause !== undefined) {
230
+ result.whereClause = this.transform(node.whereClause, context);
231
+ }
232
+ if (node.fromClause !== undefined) {
233
+ result.fromClause = Array.isArray(node.fromClause)
234
+ ? node.fromClause.map(item => this.transform(item, context))
235
+ : this.transform(node.fromClause, context);
236
+ }
237
+ if (node.returningList !== undefined) {
238
+ result.returningList = Array.isArray(node.returningList)
239
+ ? node.returningList.map(item => this.transform(item, context))
240
+ : this.transform(node.returningList, context);
241
+ }
242
+ if (node.withClause !== undefined) {
243
+ result.withClause = this.transform(node.withClause, context);
244
+ }
245
+ return { UpdateStmt: result };
246
+ }
247
+ DeleteStmt(node, context) {
248
+ const result = {};
249
+ if (node.relation !== undefined) {
250
+ result.relation = this.transform(node.relation, context);
251
+ }
252
+ if (node.usingClause !== undefined) {
253
+ result.usingClause = Array.isArray(node.usingClause)
254
+ ? node.usingClause.map(item => this.transform(item, context))
255
+ : this.transform(node.usingClause, context);
256
+ }
257
+ if (node.whereClause !== undefined) {
258
+ result.whereClause = this.transform(node.whereClause, context);
259
+ }
260
+ if (node.returningList !== undefined) {
261
+ result.returningList = Array.isArray(node.returningList)
262
+ ? node.returningList.map(item => this.transform(item, context))
263
+ : this.transform(node.returningList, context);
264
+ }
265
+ if (node.withClause !== undefined) {
266
+ result.withClause = this.transform(node.withClause, context);
267
+ }
268
+ return { DeleteStmt: result };
269
+ }
270
+ WithClause(node, context) {
271
+ const result = {};
272
+ if (node.ctes !== undefined) {
273
+ const cteContext = { ...context, inCTE: true };
274
+ result.ctes = Array.isArray(node.ctes)
275
+ ? node.ctes.map(item => this.transform(item, cteContext))
276
+ : this.transform(node.ctes, cteContext);
277
+ }
278
+ if (node.recursive !== undefined) {
279
+ result.recursive = node.recursive;
280
+ }
281
+ if (node.location !== undefined) {
282
+ result.location = node.location;
283
+ }
284
+ return { WithClause: result };
285
+ }
286
+ ResTarget(node, context) {
287
+ const result = {};
288
+ if (node.name !== undefined) {
289
+ result.name = node.name;
290
+ }
291
+ if (node.indirection !== undefined) {
292
+ result.indirection = Array.isArray(node.indirection)
293
+ ? node.indirection.map(item => this.transform(item, context))
294
+ : this.transform(node.indirection, context);
295
+ }
296
+ if (node.val !== undefined) {
297
+ result.val = this.transform(node.val, context);
298
+ }
299
+ if (node.location !== undefined) {
300
+ result.location = node.location;
301
+ }
302
+ return { ResTarget: result };
303
+ }
304
+ BoolExpr(node, context) {
305
+ const result = {};
306
+ if (node.boolop !== undefined) {
307
+ result.boolop = node.boolop;
308
+ }
309
+ if (node.args !== undefined) {
310
+ result.args = Array.isArray(node.args)
311
+ ? node.args.map(item => this.transform(item, context))
312
+ : this.transform(node.args, context);
313
+ }
314
+ if (node.location !== undefined) {
315
+ result.location = node.location;
316
+ }
317
+ return { BoolExpr: result };
318
+ }
319
+ FuncCall(node, context) {
320
+ const result = {};
321
+ if (node.funcname !== undefined) {
322
+ result.funcname = Array.isArray(node.funcname)
323
+ ? node.funcname.map(item => this.transform(item, context))
324
+ : this.transform(node.funcname, context);
325
+ }
326
+ if (node.args !== undefined) {
327
+ result.args = Array.isArray(node.args)
328
+ ? node.args.map(item => this.transform(item, context))
329
+ : this.transform(node.args, context);
330
+ }
331
+ if (node.agg_order !== undefined) {
332
+ result.agg_order = Array.isArray(node.agg_order)
333
+ ? node.agg_order.map(item => this.transform(item, context))
334
+ : this.transform(node.agg_order, context);
335
+ }
336
+ if (node.agg_filter !== undefined) {
337
+ result.agg_filter = this.transform(node.agg_filter, context);
338
+ }
339
+ if (node.agg_within_group !== undefined) {
340
+ result.agg_within_group = node.agg_within_group;
341
+ }
342
+ if (node.agg_star !== undefined) {
343
+ result.agg_star = node.agg_star;
344
+ }
345
+ if (node.agg_distinct !== undefined) {
346
+ result.agg_distinct = node.agg_distinct;
347
+ }
348
+ if (node.func_variadic !== undefined) {
349
+ result.func_variadic = node.func_variadic;
350
+ }
351
+ if (node.over !== undefined) {
352
+ result.over = this.transform(node.over, context);
353
+ }
354
+ if (node.location !== undefined) {
355
+ result.location = node.location;
356
+ }
357
+ const funcformatValue = this.getFuncformatValue(node, result.funcname, context);
358
+ result.funcformat = funcformatValue;
359
+ return { FuncCall: result };
360
+ }
361
+ FuncExpr(node, context) {
362
+ return { FuncExpr: node };
363
+ }
364
+ A_Const(node, context) {
365
+ return { A_Const: node };
366
+ }
367
+ ColumnRef(node, context) {
368
+ return { ColumnRef: node };
369
+ }
370
+ isInCreateDomainContext(context) {
371
+ return context.parentNodeTypes.includes('CreateDomainStmt');
372
+ }
373
+ isInTypeCastContext(context) {
374
+ return context.parentNodeTypes.includes('TypeCast');
375
+ }
376
+ isInCreateTableContext(context) {
377
+ return context.parentNodeTypes.includes('ColumnDef');
378
+ }
379
+ isInValuesContext(context) {
380
+ return context.inValuesClause === true;
381
+ }
382
+ isInSimpleSelectTypeCastContext(context) {
383
+ return context.parentNodeTypes.includes('TypeCast') &&
384
+ context.parentNodeTypes.includes('ResTarget') &&
385
+ !this.isInValuesContext(context);
386
+ }
387
+ shouldAddPgCatalogPrefix(context) {
388
+ const hasSelectStmt = context.parentNodeTypes.includes('SelectStmt');
389
+ const hasWithClause = context.parentNodeTypes.includes('WithClause');
390
+ const hasCommonTableExpr = context.parentNodeTypes.includes('CommonTableExpr');
391
+ return hasSelectStmt && !hasWithClause && !hasCommonTableExpr;
392
+ }
393
+ TypeName(node, context) {
394
+ const result = {};
395
+ if (node.names !== undefined) {
396
+ let names = Array.isArray(node.names)
397
+ ? node.names.map(item => this.transform(item, context))
398
+ : this.transform(node.names, context);
399
+ // Add pg_catalog prefix for JSON types in CREATE TABLE contexts
400
+ if (Array.isArray(names) && names.length === 1) {
401
+ const firstElement = names[0];
402
+ if (firstElement && typeof firstElement === 'object' && 'String' in firstElement) {
403
+ const typeNameStr = firstElement.String.str || firstElement.String.sval;
404
+ if (typeNameStr === 'json') {
405
+ const hasCreateStmt = context.parentNodeTypes.includes('CreateStmt');
406
+ const hasCompositeTypeStmt = context.parentNodeTypes.includes('CompositeTypeStmt');
407
+ const hasRangeFunction = context.parentNodeTypes.includes('RangeFunction');
408
+ const hasCreateDomainStmt = context.parentNodeTypes.includes('CreateDomainStmt');
409
+ const hasColumnDef = context.parentNodeTypes.includes('ColumnDef');
410
+ if ((hasCreateStmt || hasCompositeTypeStmt || hasRangeFunction) && hasColumnDef) {
411
+ const pgCatalogElement = {
412
+ String: {
413
+ sval: 'pg_catalog'
414
+ }
415
+ };
416
+ names = [pgCatalogElement, firstElement];
417
+ }
418
+ else if (hasCreateDomainStmt) {
419
+ const pgCatalogElement = {
420
+ String: {
421
+ sval: 'pg_catalog'
422
+ }
423
+ };
424
+ names = [pgCatalogElement, firstElement];
425
+ }
426
+ }
427
+ }
428
+ }
429
+ result.names = names;
430
+ }
431
+ if (node.typeOid !== undefined) {
432
+ result.typeOid = node.typeOid;
433
+ }
434
+ if (node.setof !== undefined) {
435
+ result.setof = node.setof;
436
+ }
437
+ if (node.pct_type !== undefined) {
438
+ result.pct_type = node.pct_type;
439
+ }
440
+ if (node.typmods !== undefined) {
441
+ result.typmods = Array.isArray(node.typmods)
442
+ ? node.typmods.map(item => this.transform(item, context))
443
+ : this.transform(node.typmods, context);
444
+ }
445
+ if (node.typemod !== undefined) {
446
+ result.typemod = node.typemod;
447
+ }
448
+ if (node.arrayBounds !== undefined) {
449
+ result.arrayBounds = Array.isArray(node.arrayBounds)
450
+ ? node.arrayBounds.map(item => this.transform(item, context))
451
+ : this.transform(node.arrayBounds, context);
452
+ }
453
+ if (node.location !== undefined) {
454
+ result.location = node.location;
455
+ }
456
+ return { TypeName: result };
457
+ }
458
+ Alias(node, context) {
459
+ return { Alias: node };
460
+ }
461
+ RangeVar(node, context) {
462
+ const result = {};
463
+ if (node.catalogname !== undefined) {
464
+ result.catalogname = node.catalogname;
465
+ }
466
+ if (node.schemaname !== undefined) {
467
+ result.schemaname = node.schemaname;
468
+ }
469
+ if (node.relname !== undefined) {
470
+ result.relname = node.relname;
471
+ }
472
+ if (node.inh !== undefined) {
473
+ result.inh = node.inh;
474
+ }
475
+ if (node.relpersistence !== undefined) {
476
+ result.relpersistence = node.relpersistence;
477
+ }
478
+ if (node.alias !== undefined) {
479
+ result.alias = this.transform(node.alias, context);
480
+ }
481
+ if (node.location !== undefined) {
482
+ result.location = node.location;
483
+ }
484
+ return { RangeVar: result };
485
+ }
486
+ A_ArrayExpr(node, context) {
487
+ return { A_ArrayExpr: node };
488
+ }
489
+ A_Indices(node, context) {
490
+ return { A_Indices: node };
491
+ }
492
+ A_Indirection(node, context) {
493
+ return { A_Indirection: node };
494
+ }
495
+ A_Star(node, context) {
496
+ return { A_Star: node };
497
+ }
498
+ CaseExpr(node, context) {
499
+ return { CaseExpr: node };
500
+ }
501
+ CoalesceExpr(node, context) {
502
+ return { CoalesceExpr: node };
503
+ }
504
+ TypeCast(node, context) {
505
+ const result = {};
506
+ if (node.arg !== undefined) {
507
+ result.arg = this.transform(node.arg, context);
508
+ }
509
+ if (node.typeName !== undefined) {
510
+ let typeName = this.transform(node.typeName, context);
511
+ // Add pg_catalog prefix for JSON types in simple SELECT contexts, but NOT in WITH clauses
512
+ if (typeName && typeName.names && Array.isArray(typeName.names) && typeName.names.length === 1) {
513
+ const firstElement = typeName.names[0];
514
+ if (firstElement && typeof firstElement === 'object' && 'String' in firstElement) {
515
+ const typeNameStr = firstElement.String.str || firstElement.String.sval;
516
+ if (typeNameStr === 'json') {
517
+ const hasSelectStmt = context.parentNodeTypes.includes('SelectStmt');
518
+ const hasResTarget = context.parentNodeTypes.includes('ResTarget');
519
+ const hasList = context.parentNodeTypes.includes('List');
520
+ const hasA_Expr = context.parentNodeTypes.includes('A_Expr');
521
+ const hasWithClause = context.parentNodeTypes.includes('WithClause');
522
+ const hasCommonTableExpr = context.parentNodeTypes.includes('CommonTableExpr');
523
+ if (((hasSelectStmt && hasResTarget) || (hasSelectStmt && hasList) || hasA_Expr) && !hasWithClause && !hasCommonTableExpr) {
524
+ const pgCatalogElement = {
525
+ String: {
526
+ sval: 'pg_catalog'
527
+ }
528
+ };
529
+ typeName.names = [pgCatalogElement, firstElement];
530
+ }
531
+ }
532
+ }
533
+ }
534
+ result.typeName = typeName;
535
+ }
536
+ if (node.location !== undefined) {
537
+ result.location = node.location;
538
+ }
539
+ return { TypeCast: result };
540
+ }
541
+ CollateClause(node, context) {
542
+ return { CollateClause: node };
543
+ }
544
+ BooleanTest(node, context) {
545
+ return { BooleanTest: node };
546
+ }
547
+ NullTest(node, context) {
548
+ return { NullTest: node };
549
+ }
550
+ String(node, context) {
551
+ return { String: node };
552
+ }
553
+ Integer(node, context) {
554
+ return { Integer: node };
555
+ }
556
+ Float(node, context) {
557
+ return { Float: node };
558
+ }
559
+ Boolean(node, context) {
560
+ return { Boolean: node };
561
+ }
562
+ BitString(node, context) {
563
+ return { BitString: node };
564
+ }
565
+ // NOTE: there is no Null type in PG17
566
+ Null(node, context) {
567
+ return { Null: node };
568
+ }
569
+ List(node, context) {
570
+ const result = {};
571
+ if (node.items !== undefined) {
572
+ result.items = Array.isArray(node.items)
573
+ ? node.items.map(item => this.transform(item, context))
574
+ : this.transform(node.items, context);
575
+ }
576
+ return { List: result };
577
+ }
578
+ CreateStmt(node, context) {
579
+ const result = {};
580
+ if (node.relation !== undefined) {
581
+ result.relation = this.transform(node.relation, context);
582
+ }
583
+ if (node.tableElts !== undefined) {
584
+ result.tableElts = Array.isArray(node.tableElts)
585
+ ? node.tableElts.map(item => this.transform(item, context))
586
+ : this.transform(node.tableElts, context);
587
+ }
588
+ if (node.inhRelations !== undefined) {
589
+ result.inhRelations = Array.isArray(node.inhRelations)
590
+ ? node.inhRelations.map(item => this.transform(item, context))
591
+ : this.transform(node.inhRelations, context);
592
+ }
593
+ if (node.partbound !== undefined) {
594
+ result.partbound = this.transform(node.partbound, context);
595
+ }
596
+ if (node.partspec !== undefined) {
597
+ result.partspec = this.transform(node.partspec, context);
598
+ }
599
+ if (node.ofTypename !== undefined) {
600
+ result.ofTypename = this.transform(node.ofTypename, context);
601
+ }
602
+ if (node.constraints !== undefined) {
603
+ result.constraints = Array.isArray(node.constraints)
604
+ ? node.constraints.map(item => this.transform(item, context))
605
+ : this.transform(node.constraints, context);
606
+ }
607
+ if (node.options !== undefined) {
608
+ result.options = Array.isArray(node.options)
609
+ ? node.options.map(item => this.transform(item, context))
610
+ : this.transform(node.options, context);
611
+ }
612
+ if (node.oncommit !== undefined) {
613
+ result.oncommit = node.oncommit;
614
+ }
615
+ if (node.tablespacename !== undefined) {
616
+ result.tablespacename = node.tablespacename;
617
+ }
618
+ if (node.accessMethod !== undefined) {
619
+ result.accessMethod = node.accessMethod;
620
+ }
621
+ if (node.if_not_exists !== undefined) {
622
+ result.if_not_exists = node.if_not_exists;
623
+ }
624
+ return { CreateStmt: result };
625
+ }
626
+ ColumnDef(node, context) {
627
+ const result = {};
628
+ if (node.colname !== undefined) {
629
+ result.colname = node.colname;
630
+ }
631
+ if (node.typeName !== undefined) {
632
+ const transformedTypeName = this.TypeName(node.typeName, context);
633
+ result.typeName = transformedTypeName.TypeName;
634
+ }
635
+ if (node.inhcount !== undefined) {
636
+ result.inhcount = node.inhcount;
637
+ }
638
+ if (node.is_local !== undefined) {
639
+ result.is_local = node.is_local;
640
+ }
641
+ if (node.is_not_null !== undefined) {
642
+ result.is_not_null = node.is_not_null;
643
+ }
644
+ if (node.is_from_type !== undefined) {
645
+ result.is_from_type = node.is_from_type;
646
+ }
647
+ if (node.storage !== undefined) {
648
+ result.storage = node.storage;
649
+ }
650
+ if (node.raw_default !== undefined) {
651
+ result.raw_default = this.transform(node.raw_default, context);
652
+ }
653
+ if (node.cooked_default !== undefined) {
654
+ result.cooked_default = this.transform(node.cooked_default, context);
655
+ }
656
+ if (node.identity !== undefined) {
657
+ result.identity = node.identity;
658
+ }
659
+ if (node.identitySequence !== undefined) {
660
+ result.identitySequence = this.transform(node.identitySequence, context);
661
+ }
662
+ if (node.generated !== undefined) {
663
+ result.generated = node.generated;
664
+ }
665
+ if (node.collClause !== undefined) {
666
+ result.collClause = this.transform(node.collClause, context);
667
+ }
668
+ if (node.collOid !== undefined) {
669
+ result.collOid = node.collOid;
670
+ }
671
+ if (node.constraints !== undefined) {
672
+ result.constraints = Array.isArray(node.constraints)
673
+ ? node.constraints.map(item => this.transform(item, context))
674
+ : this.transform(node.constraints, context);
675
+ }
676
+ if (node.fdwoptions !== undefined) {
677
+ result.fdwoptions = Array.isArray(node.fdwoptions)
678
+ ? node.fdwoptions.map(item => this.transform(item, context))
679
+ : this.transform(node.fdwoptions, context);
680
+ }
681
+ if (node.location !== undefined) {
682
+ result.location = node.location;
683
+ }
684
+ return { ColumnDef: result };
685
+ }
686
+ Constraint(node, context) {
687
+ return { Constraint: node };
688
+ }
689
+ SubLink(node, context) {
690
+ return { SubLink: node };
691
+ }
692
+ CaseWhen(node, context) {
693
+ return { CaseWhen: node };
694
+ }
695
+ WindowDef(node, context) {
696
+ return { WindowDef: node };
697
+ }
698
+ SortBy(node, context) {
699
+ return { SortBy: node };
700
+ }
701
+ GroupingSet(node, context) {
702
+ return { GroupingSet: node };
703
+ }
704
+ CommonTableExpr(node, context) {
705
+ const result = {};
706
+ if (node.ctename !== undefined) {
707
+ result.ctename = node.ctename;
708
+ }
709
+ if (node.aliascolnames !== undefined) {
710
+ result.aliascolnames = Array.isArray(node.aliascolnames)
711
+ ? node.aliascolnames.map(item => this.transform(item, context))
712
+ : this.transform(node.aliascolnames, context);
713
+ }
714
+ if (node.ctematerialized !== undefined) {
715
+ result.ctematerialized = node.ctematerialized;
716
+ }
717
+ if (node.ctequery !== undefined) {
718
+ result.ctequery = this.transform(node.ctequery, context);
719
+ }
720
+ if (node.search_clause !== undefined) {
721
+ result.search_clause = this.transform(node.search_clause, context);
722
+ }
723
+ if (node.cycle_clause !== undefined) {
724
+ result.cycle_clause = this.transform(node.cycle_clause, context);
725
+ }
726
+ if (node.location !== undefined) {
727
+ result.location = node.location;
728
+ }
729
+ return { CommonTableExpr: result };
730
+ }
731
+ ParamRef(node, context) {
732
+ return { ParamRef: node };
733
+ }
734
+ LockingClause(node, context) {
735
+ return { LockingClause: node };
736
+ }
737
+ MinMaxExpr(node, context) {
738
+ return { MinMaxExpr: node };
739
+ }
740
+ RowExpr(node, context) {
741
+ return { RowExpr: node };
742
+ }
743
+ OpExpr(node, context) {
744
+ return { OpExpr: node };
745
+ }
746
+ DistinctExpr(node, context) {
747
+ return { DistinctExpr: node };
748
+ }
749
+ NullIfExpr(node, context) {
750
+ return { NullIfExpr: node };
751
+ }
752
+ ScalarArrayOpExpr(node, context) {
753
+ return { ScalarArrayOpExpr: node };
754
+ }
755
+ Aggref(node, context) {
756
+ return { Aggref: node };
757
+ }
758
+ WindowFunc(node, context) {
759
+ return { WindowFunc: node };
760
+ }
761
+ FieldSelect(node, context) {
762
+ return { FieldSelect: node };
763
+ }
764
+ RelabelType(node, context) {
765
+ return { RelabelType: node };
766
+ }
767
+ CoerceViaIO(node, context) {
768
+ return { CoerceViaIO: node };
769
+ }
770
+ ArrayCoerceExpr(node, context) {
771
+ return { ArrayCoerceExpr: node };
772
+ }
773
+ ConvertRowtypeExpr(node, context) {
774
+ return { ConvertRowtypeExpr: node };
775
+ }
776
+ NamedArgExpr(node, context) {
777
+ return { NamedArgExpr: node };
778
+ }
779
+ ViewStmt(node, context) {
780
+ return { ViewStmt: node };
781
+ }
782
+ IndexStmt(node, context) {
783
+ return { IndexStmt: node };
784
+ }
785
+ IndexElem(node, context) {
786
+ return { IndexElem: node };
787
+ }
788
+ PartitionElem(node, context) {
789
+ return { PartitionElem: node };
790
+ }
791
+ PartitionCmd(node, context) {
792
+ return { PartitionCmd: node };
793
+ }
794
+ JoinExpr(node, context) {
795
+ return { JoinExpr: node };
796
+ }
797
+ FromExpr(node, context) {
798
+ return { FromExpr: node };
799
+ }
800
+ TransactionStmt(node, context) {
801
+ return { TransactionStmt: node };
802
+ }
803
+ VariableSetStmt(node, context) {
804
+ return { VariableSetStmt: node };
805
+ }
806
+ VariableShowStmt(node, context) {
807
+ return { VariableShowStmt: node };
808
+ }
809
+ CreateSchemaStmt(node, context) {
810
+ return { CreateSchemaStmt: node };
811
+ }
812
+ RoleSpec(node, context) {
813
+ return { RoleSpec: node };
814
+ }
815
+ DropStmt(node, context) {
816
+ return { DropStmt: node };
817
+ }
818
+ TruncateStmt(node, context) {
819
+ return { TruncateStmt: node };
820
+ }
821
+ ReturnStmt(node, context) {
822
+ return { ReturnStmt: node };
823
+ }
824
+ PLAssignStmt(node, context) {
825
+ return { PLAssignStmt: node };
826
+ }
827
+ CopyStmt(node, context) {
828
+ return { CopyStmt: node };
829
+ }
830
+ AlterTableStmt(node, context) {
831
+ return { AlterTableStmt: node };
832
+ }
833
+ AlterTableCmd(node, context) {
834
+ return { AlterTableCmd: node };
835
+ }
836
+ CreateFunctionStmt(node, context) {
837
+ return { CreateFunctionStmt: node };
838
+ }
839
+ FunctionParameter(node, context) {
840
+ return { FunctionParameter: node };
841
+ }
842
+ CreateEnumStmt(node, context) {
843
+ return { CreateEnumStmt: node };
844
+ }
845
+ CreateDomainStmt(node, context) {
846
+ const result = {};
847
+ if (node.domainname !== undefined) {
848
+ result.domainname = Array.isArray(node.domainname)
849
+ ? node.domainname.map(item => this.transform(item, context))
850
+ : this.transform(node.domainname, context);
851
+ }
852
+ if (node.typeName !== undefined) {
853
+ const transformedTypeName = this.TypeName(node.typeName, context);
854
+ result.typeName = transformedTypeName.TypeName;
855
+ }
856
+ if (node.collClause !== undefined) {
857
+ result.collClause = this.transform(node.collClause, context);
858
+ }
859
+ if (node.constraints !== undefined) {
860
+ result.constraints = Array.isArray(node.constraints)
861
+ ? node.constraints.map(item => this.transform(item, context))
862
+ : this.transform(node.constraints, context);
863
+ }
864
+ return { CreateDomainStmt: result };
865
+ }
866
+ CreateRoleStmt(node, context) {
867
+ return { CreateRoleStmt: node };
868
+ }
869
+ DefElem(node, context) {
870
+ return { DefElem: node };
871
+ }
872
+ CreateTableSpaceStmt(node, context) {
873
+ return { CreateTableSpaceStmt: node };
874
+ }
875
+ DropTableSpaceStmt(node, context) {
876
+ return { DropTableSpaceStmt: node };
877
+ }
878
+ AlterTableSpaceOptionsStmt(node, context) {
879
+ return { AlterTableSpaceOptionsStmt: node };
880
+ }
881
+ CreateExtensionStmt(node, context) {
882
+ return { CreateExtensionStmt: node };
883
+ }
884
+ AlterExtensionStmt(node, context) {
885
+ return { AlterExtensionStmt: node };
886
+ }
887
+ CreateFdwStmt(node, context) {
888
+ return { CreateFdwStmt: node };
889
+ }
890
+ SetOperationStmt(node, context) {
891
+ return { SetOperationStmt: node };
892
+ }
893
+ ReplicaIdentityStmt(node, context) {
894
+ return { ReplicaIdentityStmt: node };
895
+ }
896
+ AlterCollationStmt(node, context) {
897
+ return { AlterCollationStmt: node };
898
+ }
899
+ AlterDomainStmt(node, context) {
900
+ return { AlterDomainStmt: node };
901
+ }
902
+ PrepareStmt(node, context) {
903
+ return { PrepareStmt: node };
904
+ }
905
+ ExecuteStmt(node, context) {
906
+ return { ExecuteStmt: node };
907
+ }
908
+ DeallocateStmt(node, context) {
909
+ const result = {};
910
+ if (node.name !== undefined) {
911
+ result.name = node.name;
912
+ }
913
+ if (node.name === undefined || node.name === null) {
914
+ result.isall = true;
915
+ }
916
+ return { DeallocateStmt: result };
917
+ }
918
+ NotifyStmt(node, context) {
919
+ return { NotifyStmt: node };
920
+ }
921
+ ListenStmt(node, context) {
922
+ return { ListenStmt: node };
923
+ }
924
+ UnlistenStmt(node, context) {
925
+ return { UnlistenStmt: node };
926
+ }
927
+ CheckPointStmt(node, context) {
928
+ return { CheckPointStmt: node };
929
+ }
930
+ LoadStmt(node, context) {
931
+ return { LoadStmt: node };
932
+ }
933
+ DiscardStmt(node, context) {
934
+ return { DiscardStmt: node };
935
+ }
936
+ CommentStmt(node, context) {
937
+ return { CommentStmt: node };
938
+ }
939
+ LockStmt(node, context) {
940
+ return { LockStmt: node };
941
+ }
942
+ CreatePolicyStmt(node, context) {
943
+ return { CreatePolicyStmt: node };
944
+ }
945
+ AlterPolicyStmt(node, context) {
946
+ return { AlterPolicyStmt: node };
947
+ }
948
+ CreateUserMappingStmt(node, context) {
949
+ return { CreateUserMappingStmt: node };
950
+ }
951
+ CreateStatsStmt(node, context) {
952
+ return { CreateStatsStmt: node };
953
+ }
954
+ StatsElem(node, context) {
955
+ return { StatsElem: node };
956
+ }
957
+ CreatePublicationStmt(node, context) {
958
+ return { CreatePublicationStmt: node };
959
+ }
960
+ CreateSubscriptionStmt(node, context) {
961
+ return { CreateSubscriptionStmt: node };
962
+ }
963
+ AlterPublicationStmt(node, context) {
964
+ return { AlterPublicationStmt: node };
965
+ }
966
+ AlterSubscriptionStmt(node, context) {
967
+ return { AlterSubscriptionStmt: node };
968
+ }
969
+ DropSubscriptionStmt(node, context) {
970
+ return { DropSubscriptionStmt: node };
971
+ }
972
+ DoStmt(node, context) {
973
+ return { DoStmt: node };
974
+ }
975
+ InlineCodeBlock(node, context) {
976
+ return { InlineCodeBlock: node };
977
+ }
978
+ CallContext(node, context) {
979
+ return { CallContext: node };
980
+ }
981
+ ConstraintsSetStmt(node, context) {
982
+ return { ConstraintsSetStmt: node };
983
+ }
984
+ AlterSystemStmt(node, context) {
985
+ return { AlterSystemStmt: node };
986
+ }
987
+ VacuumRelation(node, context) {
988
+ return { VacuumRelation: node };
989
+ }
990
+ DropOwnedStmt(node, context) {
991
+ return { DropOwnedStmt: node };
992
+ }
993
+ ReassignOwnedStmt(node, context) {
994
+ return { ReassignOwnedStmt: node };
995
+ }
996
+ AlterTSDictionaryStmt(node, context) {
997
+ return { AlterTSDictionaryStmt: node };
998
+ }
999
+ AlterTSConfigurationStmt(node, context) {
1000
+ return { AlterTSConfigurationStmt: node };
1001
+ }
1002
+ ClosePortalStmt(node, context) {
1003
+ return { ClosePortalStmt: node };
1004
+ }
1005
+ FetchStmt(node, context) {
1006
+ return { FetchStmt: node };
1007
+ }
1008
+ AlterStatsStmt(node, context) {
1009
+ return { AlterStatsStmt: node };
1010
+ }
1011
+ ObjectWithArgs(node, context) {
1012
+ return { ObjectWithArgs: node };
1013
+ }
1014
+ AlterOperatorStmt(node, context) {
1015
+ return { AlterOperatorStmt: node };
1016
+ }
1017
+ AlterFdwStmt(node, context) {
1018
+ return { AlterFdwStmt: node };
1019
+ }
1020
+ CreateForeignServerStmt(node, context) {
1021
+ return { CreateForeignServerStmt: node };
1022
+ }
1023
+ AlterForeignServerStmt(node, context) {
1024
+ return { AlterForeignServerStmt: node };
1025
+ }
1026
+ AlterUserMappingStmt(node, context) {
1027
+ return { AlterUserMappingStmt: node };
1028
+ }
1029
+ DropUserMappingStmt(node, context) {
1030
+ return { DropUserMappingStmt: node };
1031
+ }
1032
+ ImportForeignSchemaStmt(node, context) {
1033
+ return { ImportForeignSchemaStmt: node };
1034
+ }
1035
+ ClusterStmt(node, context) {
1036
+ return { ClusterStmt: node };
1037
+ }
1038
+ VacuumStmt(node, context) {
1039
+ return { VacuumStmt: node };
1040
+ }
1041
+ ExplainStmt(node, context) {
1042
+ return { ExplainStmt: node };
1043
+ }
1044
+ ReindexStmt(node, context) {
1045
+ return { ReindexStmt: node };
1046
+ }
1047
+ CallStmt(node, context) {
1048
+ return { CallStmt: node };
1049
+ }
1050
+ CreatedbStmt(node, context) {
1051
+ return { CreatedbStmt: node };
1052
+ }
1053
+ DropdbStmt(node, context) {
1054
+ return { DropdbStmt: node };
1055
+ }
1056
+ RenameStmt(node, context) {
1057
+ return { RenameStmt: node };
1058
+ }
1059
+ AlterOwnerStmt(node, context) {
1060
+ return { AlterOwnerStmt: node };
1061
+ }
1062
+ GrantStmt(node, context) {
1063
+ return { GrantStmt: node };
1064
+ }
1065
+ GrantRoleStmt(node, context) {
1066
+ return { GrantRoleStmt: node };
1067
+ }
1068
+ SecLabelStmt(node, context) {
1069
+ return { SecLabelStmt: node };
1070
+ }
1071
+ AlterDefaultPrivilegesStmt(node, context) {
1072
+ return { AlterDefaultPrivilegesStmt: node };
1073
+ }
1074
+ CreateConversionStmt(node, context) {
1075
+ return { CreateConversionStmt: node };
1076
+ }
1077
+ CreateCastStmt(node, context) {
1078
+ return { CreateCastStmt: node };
1079
+ }
1080
+ CreatePLangStmt(node, context) {
1081
+ return { CreatePLangStmt: node };
1082
+ }
1083
+ CreateTransformStmt(node, context) {
1084
+ return { CreateTransformStmt: node };
1085
+ }
1086
+ CreateTrigStmt(node, context) {
1087
+ return { CreateTrigStmt: node };
1088
+ }
1089
+ TriggerTransition(node, context) {
1090
+ return { TriggerTransition: node };
1091
+ }
1092
+ CreateEventTrigStmt(node, context) {
1093
+ return { CreateEventTrigStmt: node };
1094
+ }
1095
+ AlterEventTrigStmt(node, context) {
1096
+ return { AlterEventTrigStmt: node };
1097
+ }
1098
+ CreateOpClassStmt(node, context) {
1099
+ return { CreateOpClassStmt: node };
1100
+ }
1101
+ CreateOpFamilyStmt(node, context) {
1102
+ return { CreateOpFamilyStmt: node };
1103
+ }
1104
+ AlterOpFamilyStmt(node, context) {
1105
+ return { AlterOpFamilyStmt: node };
1106
+ }
1107
+ MergeStmt(node, context) {
1108
+ return { MergeStmt: node };
1109
+ }
1110
+ AlterTableMoveAllStmt(node, context) {
1111
+ return { AlterTableMoveAllStmt: node };
1112
+ }
1113
+ CreateSeqStmt(node, context) {
1114
+ return { CreateSeqStmt: node };
1115
+ }
1116
+ AlterSeqStmt(node, context) {
1117
+ return { AlterSeqStmt: node };
1118
+ }
1119
+ CompositeTypeStmt(node, context) {
1120
+ const result = {};
1121
+ if (node.typevar !== undefined) {
1122
+ result.typevar = this.transform(node.typevar, context);
1123
+ }
1124
+ if (node.coldeflist !== undefined) {
1125
+ result.coldeflist = Array.isArray(node.coldeflist)
1126
+ ? node.coldeflist.map(item => this.transform(item, context))
1127
+ : this.transform(node.coldeflist, context);
1128
+ }
1129
+ return { CompositeTypeStmt: result };
1130
+ }
1131
+ CreateRangeStmt(node, context) {
1132
+ return { CreateRangeStmt: node };
1133
+ }
1134
+ AlterEnumStmt(node, context) {
1135
+ return { AlterEnumStmt: node };
1136
+ }
1137
+ AlterTypeStmt(node, context) {
1138
+ return { AlterTypeStmt: node };
1139
+ }
1140
+ AlterRoleStmt(node, context) {
1141
+ return { AlterRoleStmt: node };
1142
+ }
1143
+ DropRoleStmt(node, context) {
1144
+ return { DropRoleStmt: node };
1145
+ }
1146
+ // NOTE PG 17 has a no CreateAggregateStmt?
1147
+ // In PostgreSQL 17, the CreateAggregateStmt has been removed from the backend parser infrastructure and replaced by CreateFunctionStmt with a kind = OBJECT_AGGREGATE variant.
1148
+ CreateAggregateStmt(node, context) {
1149
+ return { CreateAggregateStmt: node };
1150
+ }
1151
+ CreateTableAsStmt(node, context) {
1152
+ return { CreateTableAsStmt: node };
1153
+ }
1154
+ RefreshMatViewStmt(node, context) {
1155
+ return { RefreshMatViewStmt: node };
1156
+ }
1157
+ AccessPriv(node, context) {
1158
+ return { AccessPriv: node };
1159
+ }
1160
+ DefineStmt(node, context) {
1161
+ return { DefineStmt: node };
1162
+ }
1163
+ AlterDatabaseStmt(node, context) {
1164
+ return { AlterDatabaseStmt: node };
1165
+ }
1166
+ AlterDatabaseRefreshCollStmt(node, context) {
1167
+ return { AlterDatabaseRefreshCollStmt: node };
1168
+ }
1169
+ AlterDatabaseSetStmt(node, context) {
1170
+ return { AlterDatabaseSetStmt: node };
1171
+ }
1172
+ DeclareCursorStmt(node, context) {
1173
+ return { DeclareCursorStmt: node };
1174
+ }
1175
+ PublicationObjSpec(node, context) {
1176
+ return { PublicationObjSpec: node };
1177
+ }
1178
+ PublicationTable(node, context) {
1179
+ return { PublicationTable: node };
1180
+ }
1181
+ CreateAmStmt(node, context) {
1182
+ return { CreateAmStmt: node };
1183
+ }
1184
+ IntoClause(node, context) {
1185
+ return { IntoClause: node };
1186
+ }
1187
+ OnConflictExpr(node, context) {
1188
+ return { OnConflictExpr: node };
1189
+ }
1190
+ ScanToken(node, context) {
1191
+ return { ScanToken: node };
1192
+ }
1193
+ CreateOpClassItem(node, context) {
1194
+ return { CreateOpClassItem: node };
1195
+ }
1196
+ Var(node, context) {
1197
+ return { Var: node };
1198
+ }
1199
+ TableFunc(node, context) {
1200
+ return { TableFunc: node };
1201
+ }
1202
+ RangeTableFunc(node, context) {
1203
+ return { RangeTableFunc: node };
1204
+ }
1205
+ RangeTableFuncCol(node, context) {
1206
+ return { RangeTableFuncCol: node };
1207
+ }
1208
+ JsonArrayQueryConstructor(node, context) {
1209
+ return { JsonArrayQueryConstructor: node };
1210
+ }
1211
+ RangeFunction(node, context) {
1212
+ const result = {};
1213
+ if (node.lateral !== undefined) {
1214
+ result.lateral = node.lateral;
1215
+ }
1216
+ if (node.ordinality !== undefined) {
1217
+ result.ordinality = node.ordinality;
1218
+ }
1219
+ if (node.is_rowsfrom !== undefined) {
1220
+ result.is_rowsfrom = node.is_rowsfrom;
1221
+ }
1222
+ if (node.functions !== undefined) {
1223
+ result.functions = Array.isArray(node.functions)
1224
+ ? node.functions.map(item => this.transform(item, context))
1225
+ : this.transform(node.functions, context);
1226
+ }
1227
+ if (node.alias !== undefined) {
1228
+ result.alias = this.transform(node.alias, context);
1229
+ }
1230
+ if (node.coldeflist !== undefined) {
1231
+ result.coldeflist = Array.isArray(node.coldeflist)
1232
+ ? node.coldeflist.map(item => this.transform(item, context))
1233
+ : this.transform(node.coldeflist, context);
1234
+ }
1235
+ return { RangeFunction: result };
1236
+ }
1237
+ XmlSerialize(node, context) {
1238
+ const result = {};
1239
+ if (node.xmloption !== undefined) {
1240
+ result.xmloption = node.xmloption;
1241
+ }
1242
+ if (node.expr !== undefined) {
1243
+ result.expr = this.transform(node.expr, context);
1244
+ }
1245
+ if (node.typeName !== undefined) {
1246
+ result.typeName = this.transform(node.typeName, context);
1247
+ }
1248
+ if (node.location !== undefined) {
1249
+ result.location = node.location;
1250
+ }
1251
+ return { XmlSerialize: result };
1252
+ }
1253
+ RuleStmt(node, context) {
1254
+ return { RuleStmt: node };
1255
+ }
1256
+ GroupingFunc(node, context) {
1257
+ const result = {};
1258
+ if (node.args !== undefined) {
1259
+ result.args = Array.isArray(node.args)
1260
+ ? node.args.map((item) => this.transform(item, context))
1261
+ : this.transform(node.args, context);
1262
+ }
1263
+ if (node.refs !== undefined) {
1264
+ result.refs = Array.isArray(node.refs)
1265
+ ? node.refs.map((item) => this.transform(item, context))
1266
+ : this.transform(node.refs, context);
1267
+ }
1268
+ if (node.agglevelsup !== undefined) {
1269
+ result.agglevelsup = node.agglevelsup;
1270
+ }
1271
+ if (node.location !== undefined) {
1272
+ result.location = node.location;
1273
+ }
1274
+ return { GroupingFunc: result };
1275
+ }
1276
+ MultiAssignRef(node, context) {
1277
+ const result = {};
1278
+ if (node.source !== undefined) {
1279
+ result.source = this.transform(node.source, context);
1280
+ }
1281
+ if (node.colno !== undefined) {
1282
+ result.colno = node.colno;
1283
+ }
1284
+ if (node.ncolumns !== undefined) {
1285
+ result.ncolumns = node.ncolumns;
1286
+ }
1287
+ return { MultiAssignRef: result };
1288
+ }
1289
+ CurrentOfExpr(node, context) {
1290
+ const result = {};
1291
+ if (node.cursor_name !== undefined) {
1292
+ result.cursor_name = node.cursor_name;
1293
+ }
1294
+ if (node.cursor_param !== undefined) {
1295
+ result.cursor_param = node.cursor_param;
1296
+ }
1297
+ return { CurrentOfExpr: result };
1298
+ }
1299
+ TableLikeClause(node, context) {
1300
+ return { TableLikeClause: node };
1301
+ }
1302
+ AlterFunctionStmt(node, context) {
1303
+ return { AlterFunctionStmt: node };
1304
+ }
1305
+ AlterObjectSchemaStmt(node, context) {
1306
+ return { AlterObjectSchemaStmt: node };
1307
+ }
1308
+ AlterRoleSetStmt(node, context) {
1309
+ const result = {};
1310
+ if (node.role !== undefined) {
1311
+ result.role = this.transform(node.role, context);
1312
+ }
1313
+ if (node.database !== undefined) {
1314
+ result.database = node.database;
1315
+ }
1316
+ if (node.setstmt !== undefined) {
1317
+ result.setstmt = this.transform(node.setstmt, context);
1318
+ }
1319
+ return { AlterRoleSetStmt: result };
1320
+ }
1321
+ CreateForeignTableStmt(node, context) {
1322
+ return { CreateForeignTableStmt: node };
1323
+ }
1324
+ getFuncformatValue(node, funcname, context) {
1325
+ const functionName = this.getFunctionName(node, funcname);
1326
+ if (!functionName) {
1327
+ return 'COERCE_EXPLICIT_CALL';
1328
+ }
1329
+ const hasPgCatalogPrefix = this.hasPgCatalogPrefix(funcname);
1330
+ const sqlSyntaxFunctions = [
1331
+ 'trim', 'ltrim', 'rtrim', 'btrim',
1332
+ 'position', 'overlay', 'substring',
1333
+ 'extract', 'timezone', 'xmlexists',
1334
+ 'current_date', 'current_time', 'current_timestamp',
1335
+ 'localtime', 'localtimestamp', 'overlaps'
1336
+ ];
1337
+ // Handle specific functions that depend on pg_catalog prefix
1338
+ if (functionName.toLowerCase() === 'substring') {
1339
+ if (hasPgCatalogPrefix) {
1340
+ return 'COERCE_SQL_SYNTAX';
1341
+ }
1342
+ return 'COERCE_EXPLICIT_CALL';
1343
+ }
1344
+ if (functionName.toLowerCase() === 'ltrim') {
1345
+ if (hasPgCatalogPrefix) {
1346
+ return 'COERCE_SQL_SYNTAX';
1347
+ }
1348
+ return 'COERCE_EXPLICIT_CALL';
1349
+ }
1350
+ if (functionName.toLowerCase() === 'btrim') {
1351
+ if (hasPgCatalogPrefix) {
1352
+ return 'COERCE_SQL_SYNTAX';
1353
+ }
1354
+ return 'COERCE_EXPLICIT_CALL';
1355
+ }
1356
+ if (functionName.toLowerCase() === 'pg_collation_for') {
1357
+ if (hasPgCatalogPrefix) {
1358
+ return 'COERCE_SQL_SYNTAX';
1359
+ }
1360
+ return 'COERCE_EXPLICIT_CALL';
1361
+ }
1362
+ if (sqlSyntaxFunctions.includes(functionName.toLowerCase())) {
1363
+ return 'COERCE_SQL_SYNTAX';
1364
+ }
1365
+ return 'COERCE_EXPLICIT_CALL';
1366
+ }
1367
+ getFunctionName(node, funcname) {
1368
+ const names = funcname || node?.funcname;
1369
+ if (names && Array.isArray(names) && names.length > 0) {
1370
+ const lastName = names[names.length - 1];
1371
+ if (lastName && typeof lastName === 'object' && 'String' in lastName) {
1372
+ return lastName.String.str || lastName.String.sval;
1373
+ }
1374
+ }
1375
+ return null;
1376
+ }
1377
+ hasPgCatalogPrefix(funcname) {
1378
+ if (funcname && Array.isArray(funcname) && funcname.length >= 2) {
1379
+ const firstElement = funcname[0];
1380
+ if (firstElement && typeof firstElement === 'object' && 'String' in firstElement) {
1381
+ const prefix = firstElement.String.str || firstElement.String.sval;
1382
+ return prefix === 'pg_catalog';
1383
+ }
1384
+ }
1385
+ return false;
1386
+ }
1387
+ RangeTableSample(node, context) {
1388
+ const result = {};
1389
+ if (node.relation !== undefined) {
1390
+ result.relation = this.transform(node.relation, context);
1391
+ }
1392
+ if (node.method !== undefined) {
1393
+ result.method = Array.isArray(node.method)
1394
+ ? node.method.map(item => this.transform(item, context))
1395
+ : this.transform(node.method, context);
1396
+ }
1397
+ if (node.args !== undefined) {
1398
+ result.args = Array.isArray(node.args)
1399
+ ? node.args.map(item => this.transform(item, context))
1400
+ : this.transform(node.args, context);
1401
+ }
1402
+ if (node.repeatable !== undefined) {
1403
+ result.repeatable = this.transform(node.repeatable, context);
1404
+ }
1405
+ if (node.location !== undefined) {
1406
+ result.location = node.location;
1407
+ }
1408
+ return { RangeTableSample: result };
1409
+ }
1410
+ SQLValueFunction(node, context) {
1411
+ const result = {};
1412
+ if (node.op !== undefined) {
1413
+ result.op = node.op;
1414
+ }
1415
+ if (node.type !== undefined) {
1416
+ result.type = node.type;
1417
+ }
1418
+ if (node.typmod !== undefined) {
1419
+ result.typmod = node.typmod;
1420
+ }
1421
+ if (node.location !== undefined) {
1422
+ result.location = node.location;
1423
+ }
1424
+ return { SQLValueFunction: result };
1425
+ }
1426
+ XmlExpr(node, context) {
1427
+ const result = {};
1428
+ if (node.op !== undefined) {
1429
+ result.op = node.op;
1430
+ }
1431
+ if (node.name !== undefined) {
1432
+ result.name = node.name;
1433
+ }
1434
+ if (node.named_args !== undefined) {
1435
+ result.named_args = Array.isArray(node.named_args)
1436
+ ? node.named_args.map(item => this.transform(item, context))
1437
+ : this.transform(node.named_args, context);
1438
+ }
1439
+ if (node.arg_names !== undefined) {
1440
+ result.arg_names = Array.isArray(node.arg_names)
1441
+ ? node.arg_names.map(item => this.transform(item, context))
1442
+ : this.transform(node.arg_names, context);
1443
+ }
1444
+ if (node.args !== undefined) {
1445
+ result.args = Array.isArray(node.args)
1446
+ ? node.args.map(item => this.transform(item, context))
1447
+ : this.transform(node.args, context);
1448
+ }
1449
+ if (node.xmloption !== undefined) {
1450
+ result.xmloption = node.xmloption;
1451
+ }
1452
+ if (node.type !== undefined) {
1453
+ result.type = node.type;
1454
+ }
1455
+ if (node.typmod !== undefined) {
1456
+ result.typmod = node.typmod;
1457
+ }
1458
+ if (node.location !== undefined) {
1459
+ result.location = node.location;
1460
+ }
1461
+ return { XmlExpr: result };
1462
+ }
1463
+ RangeSubselect(node, context) {
1464
+ const result = {};
1465
+ if (node.lateral !== undefined) {
1466
+ result.lateral = node.lateral;
1467
+ }
1468
+ if (node.subquery !== undefined) {
1469
+ result.subquery = this.transform(node.subquery, context);
1470
+ }
1471
+ if (node.alias !== undefined) {
1472
+ result.alias = this.transform(node.alias, context);
1473
+ }
1474
+ return { RangeSubselect: result };
1475
+ }
1476
+ SetToDefault(node, context) {
1477
+ const result = {};
1478
+ if (node.location !== undefined) {
1479
+ result.location = node.location;
1480
+ }
1481
+ return { SetToDefault: result };
1482
+ }
1483
+ }