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.
- package/LICENSE +21 -0
- package/README.md +12 -10
- package/deparser/deparser.d.ts +308 -0
- package/deparser/deparser.js +10477 -0
- package/deparser/index.d.ts +9 -0
- package/deparser/index.js +17 -0
- package/deparser/utils/list-utils.d.ts +8 -0
- package/deparser/utils/list-utils.js +30 -0
- package/deparser/utils/quote-utils.d.ts +24 -0
- package/deparser/utils/quote-utils.js +89 -0
- package/deparser/utils/sql-formatter.d.ts +16 -0
- package/deparser/utils/sql-formatter.js +40 -0
- package/deparser/visitors/base.d.ts +68 -0
- package/deparser/visitors/base.js +122 -0
- package/{src/deparser/deparser.ts → esm/deparser/deparser.js} +751 -752
- package/{src/deparser/index.ts → esm/deparser/index.js} +3 -4
- package/{src/deparser/utils/list-utils.ts → esm/deparser/utils/list-utils.js} +2 -3
- package/{src/deparser/utils/quote-utils.ts → esm/deparser/utils/quote-utils.js} +6 -7
- package/{src/deparser/utils/sql-formatter.ts → esm/deparser/utils/sql-formatter.js} +10 -11
- package/{src/deparser/visitors/base.ts → esm/deparser/visitors/base.js} +34 -62
- package/esm/index.js +15 -0
- package/{src/v13-to-v14.ts → esm/v13-to-v14.js} +472 -609
- package/{src/v13-to-v17-direct.ts → esm/v13-to-v17-direct.js} +11 -12
- package/{src/v14-to-v15.ts → esm/v14-to-v15.js} +261 -662
- package/{src/v15-to-v16.ts → esm/v15-to-v16.js} +814 -1229
- package/esm/v16-to-v17.js +1488 -0
- package/index.d.ts +9 -0
- package/index.js +19 -0
- package/package.json +5 -5
- package/v13-to-v14.d.ts +253 -0
- package/v13-to-v14.js +2754 -0
- package/v13-to-v17-direct.d.ts +24 -0
- package/v13-to-v17-direct.js +82 -0
- package/v14-to-v15.d.ts +616 -0
- package/v14-to-v15.js +1227 -0
- package/v15-to-v16.d.ts +633 -0
- package/v15-to-v16.js +2944 -0
- package/v16-to-v17.d.ts +638 -0
- package/v16-to-v17.js +1492 -0
- package/src/index.ts +0 -27
- package/src/v16-to-v17.ts +0 -1897
- package/tsconfig.esm.json +0 -8
- package/tsconfig.json +0 -26
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
* Auto-generated file with types stripped for better tree-shaking
|
|
3
3
|
* DO NOT EDIT - Generated by strip-transformer-types.ts
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
// @ts-nocheck
|
|
5
|
+
// @ts-nocheck
|
|
7
6
|
export class V13ToV14Transformer {
|
|
8
|
-
transform(node
|
|
7
|
+
transform(node, context = { parentNodeTypes: [] }) {
|
|
9
8
|
if (node == null) {
|
|
10
9
|
return null;
|
|
11
10
|
}
|
|
@@ -20,17 +19,17 @@ export class V13ToV14Transformer {
|
|
|
20
19
|
}
|
|
21
20
|
// Handle ParseResult objects specially
|
|
22
21
|
if (typeof node === 'object' && node !== null && 'version' in node && 'stmts' in node) {
|
|
23
|
-
return this.ParseResult(node
|
|
22
|
+
return this.ParseResult(node, context);
|
|
24
23
|
}
|
|
25
24
|
try {
|
|
26
25
|
return this.visit(node, context);
|
|
27
26
|
}
|
|
28
27
|
catch (error) {
|
|
29
28
|
const nodeType = Object.keys(node)[0];
|
|
30
|
-
throw new Error(`Error transforming ${nodeType}: ${
|
|
29
|
+
throw new Error(`Error transforming ${nodeType}: ${error.message}`);
|
|
31
30
|
}
|
|
32
31
|
}
|
|
33
|
-
visit(node
|
|
32
|
+
visit(node, context = { parentNodeTypes: [] }) {
|
|
34
33
|
if (!context.parentNodeTypes || !Array.isArray(context.parentNodeTypes)) {
|
|
35
34
|
context = { ...context, parentNodeTypes: [] };
|
|
36
35
|
}
|
|
@@ -43,19 +42,19 @@ export class V13ToV14Transformer {
|
|
|
43
42
|
if (nodeType === 'WithClause') {
|
|
44
43
|
console.log('Found WithClause node, nodeData:', JSON.stringify(nodeData, null, 2));
|
|
45
44
|
}
|
|
46
|
-
const methodName = nodeType
|
|
45
|
+
const methodName = nodeType;
|
|
47
46
|
if (typeof this[methodName] === 'function') {
|
|
48
|
-
const childContext
|
|
47
|
+
const childContext = {
|
|
49
48
|
...context,
|
|
50
49
|
parentNodeTypes: [...context.parentNodeTypes, nodeType]
|
|
51
50
|
};
|
|
52
|
-
const result =
|
|
51
|
+
const result = this[methodName](nodeData, childContext);
|
|
53
52
|
return result;
|
|
54
53
|
}
|
|
55
54
|
// If no specific method, use transformGenericNode to handle nested transformations
|
|
56
55
|
return this.transformGenericNode(node, context);
|
|
57
56
|
}
|
|
58
|
-
|
|
57
|
+
transformGenericNode(node, context) {
|
|
59
58
|
if (typeof node !== 'object' || node === null)
|
|
60
59
|
return node;
|
|
61
60
|
if (Array.isArray(node))
|
|
@@ -71,14 +70,14 @@ export class V13ToV14Transformer {
|
|
|
71
70
|
isArray: Array.isArray(nodeData.ctes)
|
|
72
71
|
});
|
|
73
72
|
}
|
|
74
|
-
const transformedData
|
|
73
|
+
const transformedData = {};
|
|
75
74
|
for (const [key, value] of Object.entries(nodeData)) {
|
|
76
75
|
if (key === 'ctes' && Array.isArray(value)) {
|
|
77
|
-
transformedData[key] = value.map(item => this.transform(item
|
|
76
|
+
transformedData[key] = value.map(item => this.transform(item, context));
|
|
78
77
|
}
|
|
79
78
|
else if (key === 'objname' && typeof value === 'object' && value !== null) {
|
|
80
79
|
if (Array.isArray(value)) {
|
|
81
|
-
transformedData[key] = value.map(item => this.transform(item
|
|
80
|
+
transformedData[key] = value.map(item => this.transform(item, context));
|
|
82
81
|
}
|
|
83
82
|
else {
|
|
84
83
|
const keys = Object.keys(value);
|
|
@@ -86,28 +85,28 @@ export class V13ToV14Transformer {
|
|
|
86
85
|
if (isNumericKeysObject && keys.length > 0) {
|
|
87
86
|
const shouldPreserve = this.shouldPreserveObjnameAsObject(context);
|
|
88
87
|
if (shouldPreserve) {
|
|
89
|
-
const transformedObjname
|
|
88
|
+
const transformedObjname = {};
|
|
90
89
|
Object.keys(value).forEach(k => {
|
|
91
|
-
transformedObjname[k] = this.transform(
|
|
90
|
+
transformedObjname[k] = this.transform(value[k], context);
|
|
92
91
|
});
|
|
93
92
|
transformedData[key] = transformedObjname;
|
|
94
93
|
}
|
|
95
94
|
else {
|
|
96
95
|
const sortedKeys = keys.sort((a, b) => parseInt(a) - parseInt(b));
|
|
97
|
-
transformedData[key] = sortedKeys.map(k => this.transform(
|
|
96
|
+
transformedData[key] = sortedKeys.map(k => this.transform(value[k], context));
|
|
98
97
|
}
|
|
99
98
|
}
|
|
100
99
|
else {
|
|
101
100
|
// Regular object transformation
|
|
102
|
-
transformedData[key] = this.transform(value
|
|
101
|
+
transformedData[key] = this.transform(value, context);
|
|
103
102
|
}
|
|
104
103
|
}
|
|
105
104
|
}
|
|
106
105
|
else if (Array.isArray(value)) {
|
|
107
|
-
transformedData[key] = value.map(item => this.transform(item
|
|
106
|
+
transformedData[key] = value.map(item => this.transform(item, context));
|
|
108
107
|
}
|
|
109
108
|
else if (typeof value === 'object' && value !== null) {
|
|
110
|
-
transformedData[key] = this.transform(value
|
|
109
|
+
transformedData[key] = this.transform(value, context);
|
|
111
110
|
}
|
|
112
111
|
else {
|
|
113
112
|
transformedData[key] = value;
|
|
@@ -115,13 +114,13 @@ export class V13ToV14Transformer {
|
|
|
115
114
|
}
|
|
116
115
|
return { [nodeType]: transformedData };
|
|
117
116
|
}
|
|
118
|
-
const result
|
|
117
|
+
const result = {};
|
|
119
118
|
for (const [key, value] of Object.entries(node)) {
|
|
120
119
|
if (Array.isArray(value)) {
|
|
121
|
-
result[key] = value.map(item => this.transform(item
|
|
120
|
+
result[key] = value.map(item => this.transform(item, context));
|
|
122
121
|
}
|
|
123
122
|
else if (typeof value === 'object' && value !== null) {
|
|
124
|
-
result[key] = this.transform(value
|
|
123
|
+
result[key] = this.transform(value, context);
|
|
125
124
|
}
|
|
126
125
|
else {
|
|
127
126
|
result[key] = value;
|
|
@@ -129,21 +128,21 @@ export class V13ToV14Transformer {
|
|
|
129
128
|
}
|
|
130
129
|
return result;
|
|
131
130
|
}
|
|
132
|
-
getNodeType(node
|
|
131
|
+
getNodeType(node) {
|
|
133
132
|
return Object.keys(node)[0];
|
|
134
133
|
}
|
|
135
|
-
getNodeData(node
|
|
134
|
+
getNodeData(node) {
|
|
136
135
|
const keys = Object.keys(node);
|
|
137
|
-
if (keys.length === 1 && typeof
|
|
138
|
-
return
|
|
136
|
+
if (keys.length === 1 && typeof node[keys[0]] === 'object' && node[keys[0]] !== null) {
|
|
137
|
+
return node[keys[0]];
|
|
139
138
|
}
|
|
140
139
|
return node;
|
|
141
140
|
}
|
|
142
|
-
ParseResult(node
|
|
141
|
+
ParseResult(node, context) {
|
|
143
142
|
if (node && typeof node === 'object' && 'version' in node && 'stmts' in node) {
|
|
144
143
|
return {
|
|
145
144
|
version: 140007,
|
|
146
|
-
stmts: node.stmts.map((stmt
|
|
145
|
+
stmts: node.stmts.map((stmt) => {
|
|
147
146
|
if (stmt && typeof stmt === 'object' && 'stmt' in stmt) {
|
|
148
147
|
return { ...stmt, stmt: this.transform(stmt.stmt, context) };
|
|
149
148
|
}
|
|
@@ -151,16 +150,14 @@ export class V13ToV14Transformer {
|
|
|
151
150
|
})
|
|
152
151
|
};
|
|
153
152
|
}
|
|
154
|
-
return node
|
|
153
|
+
return node;
|
|
155
154
|
}
|
|
156
|
-
FuncCall(node
|
|
157
|
-
|
|
158
|
-
} {
|
|
159
|
-
const result: any = {};
|
|
155
|
+
FuncCall(node, context) {
|
|
156
|
+
const result = {};
|
|
160
157
|
if (node.funcname !== undefined) {
|
|
161
158
|
let funcname = Array.isArray(node.funcname)
|
|
162
|
-
? node.funcname.map(item => this.transform(item
|
|
163
|
-
: this.transform(node.funcname
|
|
159
|
+
? node.funcname.map(item => this.transform(item, context))
|
|
160
|
+
: this.transform(node.funcname, context);
|
|
164
161
|
if (Array.isArray(funcname) && funcname.length >= 2) {
|
|
165
162
|
const lastName = funcname[funcname.length - 1];
|
|
166
163
|
if (lastName && typeof lastName === 'object' && 'String' in lastName) {
|
|
@@ -221,16 +218,16 @@ export class V13ToV14Transformer {
|
|
|
221
218
|
}
|
|
222
219
|
if (node.args !== undefined) {
|
|
223
220
|
result.args = Array.isArray(node.args)
|
|
224
|
-
? node.args.map(item => this.transform(item
|
|
225
|
-
: this.transform(node.args
|
|
221
|
+
? node.args.map(item => this.transform(item, context))
|
|
222
|
+
: this.transform(node.args, context);
|
|
226
223
|
}
|
|
227
224
|
if (node.agg_order !== undefined) {
|
|
228
225
|
result.agg_order = Array.isArray(node.agg_order)
|
|
229
|
-
? node.agg_order.map(item => this.transform(item
|
|
230
|
-
: this.transform(node.agg_order
|
|
226
|
+
? node.agg_order.map(item => this.transform(item, context))
|
|
227
|
+
: this.transform(node.agg_order, context);
|
|
231
228
|
}
|
|
232
229
|
if (node.agg_filter !== undefined) {
|
|
233
|
-
result.agg_filter = this.transform(node.agg_filter
|
|
230
|
+
result.agg_filter = this.transform(node.agg_filter, context);
|
|
234
231
|
}
|
|
235
232
|
if (node.agg_within_group !== undefined) {
|
|
236
233
|
result.agg_within_group = node.agg_within_group;
|
|
@@ -245,7 +242,7 @@ export class V13ToV14Transformer {
|
|
|
245
242
|
result.func_variadic = node.func_variadic;
|
|
246
243
|
}
|
|
247
244
|
if (node.over !== undefined) {
|
|
248
|
-
result.over = this.transform(node.over
|
|
245
|
+
result.over = this.transform(node.over, context);
|
|
249
246
|
}
|
|
250
247
|
if (node.location !== undefined) {
|
|
251
248
|
result.location = node.location;
|
|
@@ -260,7 +257,7 @@ export class V13ToV14Transformer {
|
|
|
260
257
|
}
|
|
261
258
|
return { FuncCall: result };
|
|
262
259
|
}
|
|
263
|
-
|
|
260
|
+
shouldAddFuncformat(context) {
|
|
264
261
|
if (this.isInCheckConstraintContext(context)) {
|
|
265
262
|
return false;
|
|
266
263
|
}
|
|
@@ -291,7 +288,7 @@ export class V13ToV14Transformer {
|
|
|
291
288
|
if (this.isInConstraintContext(context)) {
|
|
292
289
|
// Check if this is a function that should have funcformat even in constraints
|
|
293
290
|
const path = context.path || [];
|
|
294
|
-
const hasFuncCall = path.some((node
|
|
291
|
+
const hasFuncCall = path.some((node) => node && typeof node === 'object' && 'FuncCall' in node);
|
|
295
292
|
if (hasFuncCall) {
|
|
296
293
|
return true;
|
|
297
294
|
}
|
|
@@ -299,21 +296,21 @@ export class V13ToV14Transformer {
|
|
|
299
296
|
}
|
|
300
297
|
return true;
|
|
301
298
|
}
|
|
302
|
-
|
|
299
|
+
isInCheckConstraintContext(context) {
|
|
303
300
|
const path = context.path || [];
|
|
304
|
-
const hasDirectConstraint = path.some((node
|
|
301
|
+
const hasDirectConstraint = path.some((node) => node && typeof node === 'object' &&
|
|
305
302
|
('Constraint' in node && node.Constraint?.contype === 'CONSTR_CHECK'));
|
|
306
303
|
if (hasDirectConstraint) {
|
|
307
304
|
return true;
|
|
308
305
|
}
|
|
309
|
-
const hasAlterTableConstraint = path.some((node
|
|
306
|
+
const hasAlterTableConstraint = path.some((node) => node && typeof node === 'object' &&
|
|
310
307
|
('AlterTableCmd' in node &&
|
|
311
308
|
node.AlterTableCmd?.def?.Constraint?.contype === 'CONSTR_CHECK'));
|
|
312
309
|
if (hasAlterTableConstraint) {
|
|
313
310
|
return true;
|
|
314
311
|
}
|
|
315
312
|
if (context.parentNodeTypes) {
|
|
316
|
-
const hasConstraintParent = context.parentNodeTypes.some((parentType
|
|
313
|
+
const hasConstraintParent = context.parentNodeTypes.some((parentType) => parentType === 'Constraint' || parentType === 'AlterTableCmd');
|
|
317
314
|
if (hasConstraintParent && context.parent?.currentNode) {
|
|
318
315
|
const parentNode = context.parent.currentNode;
|
|
319
316
|
if ('Constraint' in parentNode && parentNode.Constraint?.contype === 'CONSTR_CHECK') {
|
|
@@ -327,46 +324,46 @@ export class V13ToV14Transformer {
|
|
|
327
324
|
}
|
|
328
325
|
return false;
|
|
329
326
|
}
|
|
330
|
-
|
|
327
|
+
isInCommentContext(context) {
|
|
331
328
|
const path = context.path || [];
|
|
332
|
-
return path.some((node
|
|
329
|
+
return path.some((node) => node && typeof node === 'object' && 'CommentStmt' in node);
|
|
333
330
|
}
|
|
334
|
-
|
|
331
|
+
isInTypeCastContext(context) {
|
|
335
332
|
const path = context.path || [];
|
|
336
|
-
return path.some((node
|
|
333
|
+
return path.some((node) => node && typeof node === 'object' && 'TypeCast' in node);
|
|
337
334
|
}
|
|
338
|
-
|
|
335
|
+
isInInsertContext(context) {
|
|
339
336
|
const path = context.path || [];
|
|
340
|
-
return path.some((node
|
|
337
|
+
return path.some((node) => node && typeof node === 'object' && 'InsertStmt' in node);
|
|
341
338
|
}
|
|
342
|
-
|
|
339
|
+
isInUpdateContext(context) {
|
|
343
340
|
const path = context.path || [];
|
|
344
|
-
return path.some((node
|
|
341
|
+
return path.some((node) => node && typeof node === 'object' && 'UpdateStmt' in node);
|
|
345
342
|
}
|
|
346
|
-
|
|
343
|
+
isInXmlExprContext(context) {
|
|
347
344
|
const path = context.path || [];
|
|
348
|
-
return path.some((node
|
|
345
|
+
return path.some((node) => node && typeof node === 'object' && 'XmlExpr' in node);
|
|
349
346
|
}
|
|
350
|
-
|
|
347
|
+
isInRangeFunctionContext(context) {
|
|
351
348
|
const path = context.path || [];
|
|
352
|
-
return path.some((node
|
|
349
|
+
return path.some((node) => node && typeof node === 'object' && 'RangeFunction' in node);
|
|
353
350
|
}
|
|
354
|
-
|
|
351
|
+
isInSortByContext(context) {
|
|
355
352
|
const path = context.path || [];
|
|
356
|
-
return path.some((node
|
|
353
|
+
return path.some((node) => node && typeof node === 'object' && 'SortBy' in node);
|
|
357
354
|
}
|
|
358
|
-
|
|
355
|
+
isInDefaultConstraintContext(context) {
|
|
359
356
|
const path = context.path || [];
|
|
360
|
-
return path.some((node
|
|
357
|
+
return path.some((node) => node && typeof node === 'object' && 'Constraint' in node &&
|
|
361
358
|
node.Constraint && node.Constraint.contype === 'CONSTR_DEFAULT');
|
|
362
359
|
}
|
|
363
|
-
|
|
360
|
+
isInPolicyContext(context) {
|
|
364
361
|
const path = context.path || [];
|
|
365
|
-
return path.some((node
|
|
362
|
+
return path.some((node) => node && typeof node === 'object' && 'CreatePolicyStmt' in node);
|
|
366
363
|
}
|
|
367
|
-
|
|
364
|
+
isInSelectFromContext(context) {
|
|
368
365
|
const path = context.path || [];
|
|
369
|
-
return path.some((node
|
|
366
|
+
return path.some((node, index) => {
|
|
370
367
|
if (node && typeof node === 'object' && 'SelectStmt' in node) {
|
|
371
368
|
const nextNode = path[index + 1];
|
|
372
369
|
return nextNode && typeof nextNode === 'string' && nextNode === 'fromClause';
|
|
@@ -374,38 +371,38 @@ export class V13ToV14Transformer {
|
|
|
374
371
|
return false;
|
|
375
372
|
});
|
|
376
373
|
}
|
|
377
|
-
|
|
374
|
+
isInSelectTargetContext(context) {
|
|
378
375
|
const parentNodeTypes = context.parentNodeTypes || [];
|
|
379
376
|
// Check if we're in a SelectStmt and ResTarget context (which indicates targetList)
|
|
380
377
|
return parentNodeTypes.includes('SelectStmt') && parentNodeTypes.includes('ResTarget');
|
|
381
378
|
}
|
|
382
|
-
|
|
379
|
+
isInReturningContext(context) {
|
|
383
380
|
const parentNodeTypes = context.parentNodeTypes || [];
|
|
384
381
|
// Check if we're in a ResTarget context within UPDATE or DELETE RETURNING clauses
|
|
385
382
|
return parentNodeTypes.includes('ResTarget') &&
|
|
386
383
|
(parentNodeTypes.includes('UpdateStmt') || parentNodeTypes.includes('DeleteStmt'));
|
|
387
384
|
}
|
|
388
|
-
|
|
385
|
+
isInCreateIndexContext(context) {
|
|
389
386
|
const path = context.path || [];
|
|
390
|
-
return path.some((node
|
|
387
|
+
return path.some((node) => node && typeof node === 'object' && 'IndexStmt' in node);
|
|
391
388
|
}
|
|
392
|
-
|
|
389
|
+
isInConstraintContext(context) {
|
|
393
390
|
const path = context.path || [];
|
|
394
|
-
return path.some((node
|
|
391
|
+
return path.some((node) => node && typeof node === 'object' && 'Constraint' in node);
|
|
395
392
|
}
|
|
396
|
-
|
|
393
|
+
isInCreateDomainContext(context) {
|
|
397
394
|
const parentNodeTypes = context.parentNodeTypes || [];
|
|
398
395
|
return parentNodeTypes.includes('CreateDomainStmt');
|
|
399
396
|
}
|
|
400
|
-
|
|
397
|
+
isInCreateProcedureContext(context) {
|
|
401
398
|
const parentNodeTypes = context.parentNodeTypes || [];
|
|
402
399
|
return parentNodeTypes.includes('CreateFunctionStmt');
|
|
403
400
|
}
|
|
404
|
-
|
|
401
|
+
isInCallStmtContext(context) {
|
|
405
402
|
const parentNodeTypes = context.parentNodeTypes || [];
|
|
406
403
|
return parentNodeTypes.includes('CallStmt');
|
|
407
404
|
}
|
|
408
|
-
|
|
405
|
+
isStandardFunctionCallSyntax(node, context) {
|
|
409
406
|
if (!node.args || !Array.isArray(node.args)) {
|
|
410
407
|
return true; // Default to function call syntax
|
|
411
408
|
}
|
|
@@ -436,24 +433,20 @@ export class V13ToV14Transformer {
|
|
|
436
433
|
}
|
|
437
434
|
return true; // Default to function call syntax
|
|
438
435
|
}
|
|
439
|
-
|
|
436
|
+
isSqlStandardSyntax(node, context) {
|
|
440
437
|
return !this.isStandardFunctionCallSyntax(node, context);
|
|
441
438
|
}
|
|
442
|
-
CallStmt(node
|
|
443
|
-
|
|
444
|
-
} {
|
|
445
|
-
const result: any = { ...node };
|
|
439
|
+
CallStmt(node, context) {
|
|
440
|
+
const result = { ...node };
|
|
446
441
|
if (node.funccall !== undefined) {
|
|
447
442
|
const wrappedFuncCall = { FuncCall: node.funccall };
|
|
448
|
-
const transformedFuncCall = this.transform(wrappedFuncCall
|
|
443
|
+
const transformedFuncCall = this.transform(wrappedFuncCall, context);
|
|
449
444
|
result.funccall = transformedFuncCall.FuncCall || transformedFuncCall;
|
|
450
445
|
}
|
|
451
446
|
return { CallStmt: result };
|
|
452
447
|
}
|
|
453
|
-
CommentStmt(node
|
|
454
|
-
|
|
455
|
-
} {
|
|
456
|
-
const result: any = { ...node };
|
|
448
|
+
CommentStmt(node, context) {
|
|
449
|
+
const result = { ...node };
|
|
457
450
|
if (result.object !== undefined) {
|
|
458
451
|
const childContext = {
|
|
459
452
|
...context,
|
|
@@ -469,10 +462,8 @@ export class V13ToV14Transformer {
|
|
|
469
462
|
}
|
|
470
463
|
return { CommentStmt: result };
|
|
471
464
|
}
|
|
472
|
-
DropStmt(node
|
|
473
|
-
|
|
474
|
-
} {
|
|
475
|
-
const result: any = { ...node };
|
|
465
|
+
DropStmt(node, context) {
|
|
466
|
+
const result = { ...node };
|
|
476
467
|
if (result.objects !== undefined) {
|
|
477
468
|
const childContext = {
|
|
478
469
|
...context,
|
|
@@ -480,7 +471,7 @@ export class V13ToV14Transformer {
|
|
|
480
471
|
dropRemoveType: result.removeType
|
|
481
472
|
};
|
|
482
473
|
result.objects = Array.isArray(result.objects)
|
|
483
|
-
? result.objects.map((item
|
|
474
|
+
? result.objects.map((item) => {
|
|
484
475
|
const transformedItem = this.transform(item, childContext);
|
|
485
476
|
return transformedItem;
|
|
486
477
|
})
|
|
@@ -500,12 +491,10 @@ export class V13ToV14Transformer {
|
|
|
500
491
|
}
|
|
501
492
|
return { DropStmt: result };
|
|
502
493
|
}
|
|
503
|
-
InsertStmt(node
|
|
504
|
-
|
|
505
|
-
} {
|
|
506
|
-
const result: any = { ...node };
|
|
494
|
+
InsertStmt(node, context) {
|
|
495
|
+
const result = { ...node };
|
|
507
496
|
// Create child context with InsertStmt as parent
|
|
508
|
-
const childContext
|
|
497
|
+
const childContext = {
|
|
509
498
|
...context,
|
|
510
499
|
parentNodeTypes: [...(context.parentNodeTypes || []), 'InsertStmt']
|
|
511
500
|
};
|
|
@@ -514,7 +503,7 @@ export class V13ToV14Transformer {
|
|
|
514
503
|
}
|
|
515
504
|
if (result.cols !== undefined) {
|
|
516
505
|
result.cols = Array.isArray(result.cols)
|
|
517
|
-
? result.cols.map((item
|
|
506
|
+
? result.cols.map((item) => this.transform(item, childContext))
|
|
518
507
|
: this.transform(result.cols, childContext);
|
|
519
508
|
}
|
|
520
509
|
if (result.selectStmt !== undefined) {
|
|
@@ -525,13 +514,13 @@ export class V13ToV14Transformer {
|
|
|
525
514
|
}
|
|
526
515
|
if (result.returningList !== undefined) {
|
|
527
516
|
result.returningList = Array.isArray(result.returningList)
|
|
528
|
-
? result.returningList.map((item
|
|
517
|
+
? result.returningList.map((item) => this.transform(item, childContext))
|
|
529
518
|
: this.transform(result.returningList, childContext);
|
|
530
519
|
}
|
|
531
520
|
if (result.withClause !== undefined) {
|
|
532
521
|
if (result.withClause.ctes && Array.isArray(result.withClause.ctes)) {
|
|
533
522
|
const transformedWithClause = { ...result.withClause };
|
|
534
|
-
transformedWithClause.ctes = result.withClause.ctes.map((cte
|
|
523
|
+
transformedWithClause.ctes = result.withClause.ctes.map((cte) => this.transform(cte, childContext));
|
|
535
524
|
if (result.withClause.recursive !== undefined) {
|
|
536
525
|
transformedWithClause.recursive = result.withClause.recursive;
|
|
537
526
|
}
|
|
@@ -546,12 +535,10 @@ export class V13ToV14Transformer {
|
|
|
546
535
|
}
|
|
547
536
|
return { InsertStmt: result };
|
|
548
537
|
}
|
|
549
|
-
UpdateStmt(node
|
|
550
|
-
|
|
551
|
-
} {
|
|
552
|
-
const result: any = { ...node };
|
|
538
|
+
UpdateStmt(node, context) {
|
|
539
|
+
const result = { ...node };
|
|
553
540
|
// Create child context with UpdateStmt as parent
|
|
554
|
-
const childContext
|
|
541
|
+
const childContext = {
|
|
555
542
|
...context,
|
|
556
543
|
parentNodeTypes: [...(context.parentNodeTypes || []), 'UpdateStmt']
|
|
557
544
|
};
|
|
@@ -560,7 +547,7 @@ export class V13ToV14Transformer {
|
|
|
560
547
|
}
|
|
561
548
|
if (result.targetList !== undefined) {
|
|
562
549
|
result.targetList = Array.isArray(result.targetList)
|
|
563
|
-
? result.targetList.map((item
|
|
550
|
+
? result.targetList.map((item) => this.transform(item, childContext))
|
|
564
551
|
: this.transform(result.targetList, childContext);
|
|
565
552
|
}
|
|
566
553
|
if (result.whereClause !== undefined) {
|
|
@@ -568,18 +555,18 @@ export class V13ToV14Transformer {
|
|
|
568
555
|
}
|
|
569
556
|
if (result.fromClause !== undefined) {
|
|
570
557
|
result.fromClause = Array.isArray(result.fromClause)
|
|
571
|
-
? result.fromClause.map((item
|
|
558
|
+
? result.fromClause.map((item) => this.transform(item, childContext))
|
|
572
559
|
: this.transform(result.fromClause, childContext);
|
|
573
560
|
}
|
|
574
561
|
if (result.returningList !== undefined) {
|
|
575
562
|
result.returningList = Array.isArray(result.returningList)
|
|
576
|
-
? result.returningList.map((item
|
|
563
|
+
? result.returningList.map((item) => this.transform(item, childContext))
|
|
577
564
|
: this.transform(result.returningList, childContext);
|
|
578
565
|
}
|
|
579
566
|
if (result.withClause !== undefined) {
|
|
580
567
|
if (result.withClause.ctes && Array.isArray(result.withClause.ctes)) {
|
|
581
568
|
const transformedWithClause = { ...result.withClause };
|
|
582
|
-
transformedWithClause.ctes = result.withClause.ctes.map((cte
|
|
569
|
+
transformedWithClause.ctes = result.withClause.ctes.map((cte) => this.transform(cte, childContext));
|
|
583
570
|
if (result.withClause.recursive !== undefined) {
|
|
584
571
|
transformedWithClause.recursive = result.withClause.recursive;
|
|
585
572
|
}
|
|
@@ -594,12 +581,10 @@ export class V13ToV14Transformer {
|
|
|
594
581
|
}
|
|
595
582
|
return { UpdateStmt: result };
|
|
596
583
|
}
|
|
597
|
-
DeleteStmt(node
|
|
598
|
-
|
|
599
|
-
} {
|
|
600
|
-
const result: any = { ...node };
|
|
584
|
+
DeleteStmt(node, context) {
|
|
585
|
+
const result = { ...node };
|
|
601
586
|
// Create child context with DeleteStmt as parent
|
|
602
|
-
const childContext
|
|
587
|
+
const childContext = {
|
|
603
588
|
...context,
|
|
604
589
|
parentNodeTypes: [...(context.parentNodeTypes || []), 'DeleteStmt']
|
|
605
590
|
};
|
|
@@ -608,7 +593,7 @@ export class V13ToV14Transformer {
|
|
|
608
593
|
}
|
|
609
594
|
if (result.usingClause !== undefined) {
|
|
610
595
|
result.usingClause = Array.isArray(result.usingClause)
|
|
611
|
-
? result.usingClause.map((item
|
|
596
|
+
? result.usingClause.map((item) => this.transform(item, childContext))
|
|
612
597
|
: this.transform(result.usingClause, childContext);
|
|
613
598
|
}
|
|
614
599
|
if (result.whereClause !== undefined) {
|
|
@@ -616,13 +601,13 @@ export class V13ToV14Transformer {
|
|
|
616
601
|
}
|
|
617
602
|
if (result.returningList !== undefined) {
|
|
618
603
|
result.returningList = Array.isArray(result.returningList)
|
|
619
|
-
? result.returningList.map((item
|
|
604
|
+
? result.returningList.map((item) => this.transform(item, childContext))
|
|
620
605
|
: this.transform(result.returningList, childContext);
|
|
621
606
|
}
|
|
622
607
|
if (result.withClause !== undefined) {
|
|
623
608
|
if (result.withClause.ctes && Array.isArray(result.withClause.ctes)) {
|
|
624
609
|
const transformedWithClause = { ...result.withClause };
|
|
625
|
-
transformedWithClause.ctes = result.withClause.ctes.map((cte
|
|
610
|
+
transformedWithClause.ctes = result.withClause.ctes.map((cte) => this.transform(cte, childContext));
|
|
626
611
|
if (result.withClause.recursive !== undefined) {
|
|
627
612
|
transformedWithClause.recursive = result.withClause.recursive;
|
|
628
613
|
}
|
|
@@ -637,23 +622,21 @@ export class V13ToV14Transformer {
|
|
|
637
622
|
}
|
|
638
623
|
return { DeleteStmt: result };
|
|
639
624
|
}
|
|
640
|
-
CreateOpClassStmt(node
|
|
641
|
-
|
|
642
|
-
} {
|
|
643
|
-
const result: any = { ...node };
|
|
625
|
+
CreateOpClassStmt(node, context) {
|
|
626
|
+
const result = { ...node };
|
|
644
627
|
// Create child context with CreateOpClassStmt as parent
|
|
645
|
-
const childContext
|
|
628
|
+
const childContext = {
|
|
646
629
|
...context,
|
|
647
630
|
parentNodeTypes: [...(context.parentNodeTypes || []), 'CreateOpClassStmt']
|
|
648
631
|
};
|
|
649
632
|
if (result.opclassname !== undefined) {
|
|
650
633
|
result.opclassname = Array.isArray(result.opclassname)
|
|
651
|
-
? result.opclassname.map((item
|
|
634
|
+
? result.opclassname.map((item) => this.transform(item, childContext))
|
|
652
635
|
: this.transform(result.opclassname, childContext);
|
|
653
636
|
}
|
|
654
637
|
if (result.opfamilyname !== undefined) {
|
|
655
638
|
result.opfamilyname = Array.isArray(result.opfamilyname)
|
|
656
|
-
? result.opfamilyname.map((item
|
|
639
|
+
? result.opfamilyname.map((item) => this.transform(item, childContext))
|
|
657
640
|
: this.transform(result.opfamilyname, childContext);
|
|
658
641
|
}
|
|
659
642
|
if (result.amname !== undefined) {
|
|
@@ -664,17 +647,15 @@ export class V13ToV14Transformer {
|
|
|
664
647
|
}
|
|
665
648
|
if (result.items !== undefined) {
|
|
666
649
|
result.items = Array.isArray(result.items)
|
|
667
|
-
? result.items.map((item
|
|
650
|
+
? result.items.map((item) => this.transform(item, childContext))
|
|
668
651
|
: this.transform(result.items, childContext);
|
|
669
652
|
}
|
|
670
653
|
return { CreateOpClassStmt: result };
|
|
671
654
|
}
|
|
672
|
-
CreateOpClassItem(node
|
|
673
|
-
|
|
674
|
-
} {
|
|
675
|
-
const result: any = { ...node };
|
|
655
|
+
CreateOpClassItem(node, context) {
|
|
656
|
+
const result = { ...node };
|
|
676
657
|
// Create child context with CreateOpClassItem as parent
|
|
677
|
-
const childContext
|
|
658
|
+
const childContext = {
|
|
678
659
|
...context,
|
|
679
660
|
parentNodeTypes: [...(context.parentNodeTypes || []), 'CreateOpClassItem']
|
|
680
661
|
};
|
|
@@ -695,7 +676,7 @@ export class V13ToV14Transformer {
|
|
|
695
676
|
const isOperator = this.isOperatorName(result.name.objname);
|
|
696
677
|
if (!isOperator) {
|
|
697
678
|
result.name.objfuncargs = Array.isArray(result.name.objargs)
|
|
698
|
-
? result.name.objargs.map((arg
|
|
679
|
+
? result.name.objargs.map((arg, index) => this.createFunctionParameterFromTypeName(arg, context, index))
|
|
699
680
|
: [this.createFunctionParameterFromTypeName(result.name.objargs, context, 0)];
|
|
700
681
|
}
|
|
701
682
|
}
|
|
@@ -703,7 +684,7 @@ export class V13ToV14Transformer {
|
|
|
703
684
|
}
|
|
704
685
|
if (result.args !== undefined) {
|
|
705
686
|
result.args = Array.isArray(result.args)
|
|
706
|
-
? result.args.map((item
|
|
687
|
+
? result.args.map((item) => this.transform(item, childContext))
|
|
707
688
|
: this.transform(result.args, childContext);
|
|
708
689
|
}
|
|
709
690
|
if (result.storedtype !== undefined) {
|
|
@@ -712,10 +693,10 @@ export class V13ToV14Transformer {
|
|
|
712
693
|
return { CreateOpClassItem: result };
|
|
713
694
|
}
|
|
714
695
|
// NOTE: apparently this is NOT even a thing in PG13???
|
|
715
|
-
CreateAccessMethodStmt(node
|
|
716
|
-
const result
|
|
696
|
+
CreateAccessMethodStmt(node, context) {
|
|
697
|
+
const result = { ...node };
|
|
717
698
|
// Create child context with CreateAccessMethodStmt as parent
|
|
718
|
-
const childContext
|
|
699
|
+
const childContext = {
|
|
719
700
|
...context,
|
|
720
701
|
parentNodeTypes: [...(context.parentNodeTypes || []), 'CreateAccessMethodStmt']
|
|
721
702
|
};
|
|
@@ -724,83 +705,79 @@ export class V13ToV14Transformer {
|
|
|
724
705
|
}
|
|
725
706
|
if (result.handler_name !== undefined) {
|
|
726
707
|
result.handler_name = Array.isArray(result.handler_name)
|
|
727
|
-
? result.handler_name.map((item
|
|
708
|
+
? result.handler_name.map((item) => this.transform(item, childContext))
|
|
728
709
|
: this.transform(result.handler_name, childContext);
|
|
729
710
|
}
|
|
730
711
|
return { CreateAccessMethodStmt: result };
|
|
731
712
|
}
|
|
732
|
-
GrantStmt(node
|
|
733
|
-
|
|
734
|
-
} {
|
|
735
|
-
const result: any = { ...node };
|
|
713
|
+
GrantStmt(node, context) {
|
|
714
|
+
const result = { ...node };
|
|
736
715
|
// Create child context with GrantStmt as parent
|
|
737
|
-
const childContext
|
|
716
|
+
const childContext = {
|
|
738
717
|
...context,
|
|
739
718
|
parentNodeTypes: [...(context.parentNodeTypes || []), 'GrantStmt']
|
|
740
719
|
};
|
|
741
720
|
if (result.objects !== undefined) {
|
|
742
721
|
result.objects = Array.isArray(result.objects)
|
|
743
|
-
? result.objects.map((item
|
|
722
|
+
? result.objects.map((item) => this.transform(item, childContext))
|
|
744
723
|
: this.transform(result.objects, childContext);
|
|
745
724
|
}
|
|
746
725
|
if (result.grantees !== undefined) {
|
|
747
726
|
result.grantees = Array.isArray(result.grantees)
|
|
748
|
-
? result.grantees.map((item
|
|
727
|
+
? result.grantees.map((item) => this.transform(item, childContext))
|
|
749
728
|
: this.transform(result.grantees, childContext);
|
|
750
729
|
}
|
|
751
730
|
if (result.privileges !== undefined) {
|
|
752
731
|
result.privileges = Array.isArray(result.privileges)
|
|
753
|
-
? result.privileges.map((item
|
|
732
|
+
? result.privileges.map((item) => this.transform(item, childContext))
|
|
754
733
|
: this.transform(result.privileges, childContext);
|
|
755
734
|
}
|
|
756
735
|
return { GrantStmt: result };
|
|
757
736
|
}
|
|
758
737
|
// NOTE: apparently this is NOT even a thing in PG13???
|
|
759
|
-
RevokeStmt(node
|
|
760
|
-
const result
|
|
738
|
+
RevokeStmt(node, context) {
|
|
739
|
+
const result = { ...node };
|
|
761
740
|
// Create child context with RevokeStmt as parent
|
|
762
|
-
const childContext
|
|
741
|
+
const childContext = {
|
|
763
742
|
...context,
|
|
764
743
|
parentNodeTypes: [...(context.parentNodeTypes || []), 'RevokeStmt']
|
|
765
744
|
};
|
|
766
745
|
if (result.objects !== undefined) {
|
|
767
746
|
result.objects = Array.isArray(result.objects)
|
|
768
|
-
? result.objects.map((item
|
|
747
|
+
? result.objects.map((item) => this.transform(item, childContext))
|
|
769
748
|
: this.transform(result.objects, childContext);
|
|
770
749
|
}
|
|
771
750
|
if (result.grantees !== undefined) {
|
|
772
751
|
result.grantees = Array.isArray(result.grantees)
|
|
773
|
-
? result.grantees.map((item
|
|
752
|
+
? result.grantees.map((item) => this.transform(item, childContext))
|
|
774
753
|
: this.transform(result.grantees, childContext);
|
|
775
754
|
}
|
|
776
755
|
if (result.privileges !== undefined) {
|
|
777
756
|
result.privileges = Array.isArray(result.privileges)
|
|
778
|
-
? result.privileges.map((item
|
|
757
|
+
? result.privileges.map((item) => this.transform(item, childContext))
|
|
779
758
|
: this.transform(result.privileges, childContext);
|
|
780
759
|
}
|
|
781
760
|
return { RevokeStmt: result };
|
|
782
761
|
}
|
|
783
|
-
ResTarget(node
|
|
784
|
-
|
|
785
|
-
} {
|
|
786
|
-
const result: any = { ...node };
|
|
762
|
+
ResTarget(node, context) {
|
|
763
|
+
const result = { ...node };
|
|
787
764
|
if (node.name !== undefined) {
|
|
788
765
|
result.name = node.name;
|
|
789
766
|
}
|
|
790
767
|
if (node.indirection !== undefined) {
|
|
791
768
|
result.indirection = Array.isArray(node.indirection)
|
|
792
|
-
? node.indirection.map(item => this.transform(item
|
|
793
|
-
: this.transform(node.indirection
|
|
769
|
+
? node.indirection.map(item => this.transform(item, context))
|
|
770
|
+
: this.transform(node.indirection, context);
|
|
794
771
|
}
|
|
795
772
|
if (node.val !== undefined) {
|
|
796
|
-
result.val = this.transform(node.val
|
|
773
|
+
result.val = this.transform(node.val, context);
|
|
797
774
|
}
|
|
798
775
|
if (node.location !== undefined) {
|
|
799
776
|
result.location = node.location;
|
|
800
777
|
}
|
|
801
778
|
return { ResTarget: result };
|
|
802
779
|
}
|
|
803
|
-
|
|
780
|
+
getFunctionName(funcCall) {
|
|
804
781
|
if (funcCall.funcname && Array.isArray(funcCall.funcname)) {
|
|
805
782
|
const lastName = funcCall.funcname[funcCall.funcname.length - 1];
|
|
806
783
|
if (lastName && typeof lastName === 'object' && 'String' in lastName) {
|
|
@@ -809,7 +786,7 @@ export class V13ToV14Transformer {
|
|
|
809
786
|
}
|
|
810
787
|
return null;
|
|
811
788
|
}
|
|
812
|
-
|
|
789
|
+
isOperatorName(objname) {
|
|
813
790
|
if (!objname || !Array.isArray(objname) || objname.length === 0) {
|
|
814
791
|
return false;
|
|
815
792
|
}
|
|
@@ -827,7 +804,7 @@ export class V13ToV14Transformer {
|
|
|
827
804
|
}
|
|
828
805
|
return false;
|
|
829
806
|
}
|
|
830
|
-
|
|
807
|
+
getFuncformatValue(node, context) {
|
|
831
808
|
const funcname = this.getFunctionName(node);
|
|
832
809
|
if (!funcname) {
|
|
833
810
|
return 'COERCE_EXPLICIT_CALL';
|
|
@@ -895,7 +872,7 @@ export class V13ToV14Transformer {
|
|
|
895
872
|
}
|
|
896
873
|
return 'COERCE_EXPLICIT_CALL';
|
|
897
874
|
}
|
|
898
|
-
|
|
875
|
+
getFunctionNameFromContext(context) {
|
|
899
876
|
if (context.nodeStack) {
|
|
900
877
|
for (let i = context.nodeStack.length - 1; i >= 0; i--) {
|
|
901
878
|
const node = context.nodeStack[i];
|
|
@@ -914,7 +891,7 @@ export class V13ToV14Transformer {
|
|
|
914
891
|
}
|
|
915
892
|
return null;
|
|
916
893
|
}
|
|
917
|
-
|
|
894
|
+
functionHasExplicitModes(parameters) {
|
|
918
895
|
if (!parameters || !Array.isArray(parameters)) {
|
|
919
896
|
return false;
|
|
920
897
|
}
|
|
@@ -924,7 +901,7 @@ export class V13ToV14Transformer {
|
|
|
924
901
|
return mode === 'FUNC_PARAM_OUT' || mode === 'FUNC_PARAM_INOUT' || mode === 'FUNC_PARAM_VARIADIC';
|
|
925
902
|
});
|
|
926
903
|
}
|
|
927
|
-
|
|
904
|
+
allParametersHaveExplicitModes(parameters) {
|
|
928
905
|
if (!parameters || !Array.isArray(parameters)) {
|
|
929
906
|
return false;
|
|
930
907
|
}
|
|
@@ -935,13 +912,13 @@ export class V13ToV14Transformer {
|
|
|
935
912
|
return mode === 'FUNC_PARAM_OUT' || mode === 'FUNC_PARAM_INOUT' || mode === 'FUNC_PARAM_VARIADIC';
|
|
936
913
|
});
|
|
937
914
|
}
|
|
938
|
-
|
|
915
|
+
hasOnlyExplicitInParameters(parameters) {
|
|
939
916
|
if (!parameters || !Array.isArray(parameters)) {
|
|
940
917
|
return false;
|
|
941
918
|
}
|
|
942
919
|
return false;
|
|
943
920
|
}
|
|
944
|
-
|
|
921
|
+
hasExplicitInParameters(parameters) {
|
|
945
922
|
if (!parameters || !Array.isArray(parameters)) {
|
|
946
923
|
return false;
|
|
947
924
|
}
|
|
@@ -956,7 +933,7 @@ export class V13ToV14Transformer {
|
|
|
956
933
|
const inParamsWithNames = inParams.filter(p => p?.FunctionParameter?.name);
|
|
957
934
|
return inParamsWithNames.length > 0;
|
|
958
935
|
}
|
|
959
|
-
|
|
936
|
+
isVariadicParameterType(argType, index, allArgs, context) {
|
|
960
937
|
if (!argType)
|
|
961
938
|
return false;
|
|
962
939
|
// Handle TypeName wrapper
|
|
@@ -1011,30 +988,26 @@ export class V13ToV14Transformer {
|
|
|
1011
988
|
}
|
|
1012
989
|
return false;
|
|
1013
990
|
}
|
|
1014
|
-
FunctionParameter(node
|
|
1015
|
-
|
|
1016
|
-
} {
|
|
1017
|
-
const result: any = {};
|
|
991
|
+
FunctionParameter(node, context) {
|
|
992
|
+
const result = {};
|
|
1018
993
|
if (node.name !== undefined) {
|
|
1019
994
|
result.name = node.name;
|
|
1020
995
|
}
|
|
1021
996
|
if (node.argType !== undefined) {
|
|
1022
|
-
result.argType = this.transform(node.argType
|
|
997
|
+
result.argType = this.transform(node.argType, context);
|
|
1023
998
|
}
|
|
1024
999
|
if (node.defexpr !== undefined) {
|
|
1025
|
-
result.defexpr = this.transform(node.defexpr
|
|
1000
|
+
result.defexpr = this.transform(node.defexpr, context);
|
|
1026
1001
|
}
|
|
1027
1002
|
if (node.mode !== undefined) {
|
|
1028
1003
|
result.mode = this.mapFunctionParameterMode(node.mode, context, !!node.name);
|
|
1029
1004
|
}
|
|
1030
1005
|
return { FunctionParameter: result };
|
|
1031
1006
|
}
|
|
1032
|
-
AlterFunctionStmt(node
|
|
1033
|
-
|
|
1034
|
-
} {
|
|
1035
|
-
const result: any = {};
|
|
1007
|
+
AlterFunctionStmt(node, context) {
|
|
1008
|
+
const result = {};
|
|
1036
1009
|
// Create child context with AlterFunctionStmt as parent
|
|
1037
|
-
const childContext
|
|
1010
|
+
const childContext = {
|
|
1038
1011
|
...context,
|
|
1039
1012
|
parentNodeTypes: [...(context.parentNodeTypes || []), 'AlterFunctionStmt']
|
|
1040
1013
|
};
|
|
@@ -1044,34 +1017,32 @@ export class V13ToV14Transformer {
|
|
|
1044
1017
|
if (node.func !== undefined) {
|
|
1045
1018
|
// Handle plain object func (not wrapped in ObjectWithArgs)
|
|
1046
1019
|
if (typeof node.func === 'object' && !('ObjectWithArgs' in node.func) && 'objargs' in node.func) {
|
|
1047
|
-
const funcResult
|
|
1048
|
-
if (
|
|
1049
|
-
funcResult.objname = this.transform(
|
|
1020
|
+
const funcResult = {};
|
|
1021
|
+
if (node.func.objname !== undefined) {
|
|
1022
|
+
funcResult.objname = this.transform(node.func.objname, childContext);
|
|
1050
1023
|
}
|
|
1051
|
-
if (
|
|
1052
|
-
funcResult.objargs = this.transform(
|
|
1053
|
-
funcResult.objfuncargs = Array.isArray(
|
|
1054
|
-
?
|
|
1055
|
-
: [this.createFunctionParameterFromTypeName(
|
|
1024
|
+
if (node.func.objargs !== undefined) {
|
|
1025
|
+
funcResult.objargs = this.transform(node.func.objargs, childContext);
|
|
1026
|
+
funcResult.objfuncargs = Array.isArray(node.func.objargs)
|
|
1027
|
+
? node.func.objargs.map((arg, index) => this.createFunctionParameterFromTypeName(arg, childContext, index))
|
|
1028
|
+
: [this.createFunctionParameterFromTypeName(node.func.objargs, childContext, 0)];
|
|
1056
1029
|
}
|
|
1057
1030
|
result.func = funcResult;
|
|
1058
1031
|
}
|
|
1059
1032
|
else {
|
|
1060
|
-
const funcResult = this.transform(node.func
|
|
1033
|
+
const funcResult = this.transform(node.func, childContext);
|
|
1061
1034
|
result.func = funcResult;
|
|
1062
1035
|
}
|
|
1063
1036
|
}
|
|
1064
1037
|
if (node.actions !== undefined) {
|
|
1065
1038
|
result.actions = Array.isArray(node.actions)
|
|
1066
|
-
? node.actions.map(item => this.transform(item
|
|
1067
|
-
: this.transform(node.actions
|
|
1039
|
+
? node.actions.map(item => this.transform(item, context))
|
|
1040
|
+
: this.transform(node.actions, context);
|
|
1068
1041
|
}
|
|
1069
1042
|
return { AlterFunctionStmt: result };
|
|
1070
1043
|
}
|
|
1071
|
-
AlterOwnerStmt(node
|
|
1072
|
-
|
|
1073
|
-
} {
|
|
1074
|
-
const result: any = {};
|
|
1044
|
+
AlterOwnerStmt(node, context) {
|
|
1045
|
+
const result = {};
|
|
1075
1046
|
if (node.objectType !== undefined) {
|
|
1076
1047
|
result.objectType = node.objectType;
|
|
1077
1048
|
}
|
|
@@ -1080,7 +1051,7 @@ export class V13ToV14Transformer {
|
|
|
1080
1051
|
...context,
|
|
1081
1052
|
alterOwnerObjectType: node.objectType
|
|
1082
1053
|
};
|
|
1083
|
-
const transformedObject = this.transform(node.object
|
|
1054
|
+
const transformedObject = this.transform(node.object, childContext);
|
|
1084
1055
|
if (node.objectType === 'OBJECT_FUNCTION' && transformedObject &&
|
|
1085
1056
|
typeof transformedObject === 'object' && 'ObjectWithArgs' in transformedObject) {
|
|
1086
1057
|
const objWithArgs = transformedObject.ObjectWithArgs;
|
|
@@ -1088,48 +1059,42 @@ export class V13ToV14Transformer {
|
|
|
1088
1059
|
result.object = transformedObject;
|
|
1089
1060
|
}
|
|
1090
1061
|
if (node.newowner !== undefined) {
|
|
1091
|
-
result.newowner = this.transform(node.newowner
|
|
1062
|
+
result.newowner = this.transform(node.newowner, context);
|
|
1092
1063
|
}
|
|
1093
1064
|
return { AlterOwnerStmt: result };
|
|
1094
1065
|
}
|
|
1095
|
-
AlterTableStmt(node
|
|
1096
|
-
|
|
1097
|
-
} {
|
|
1098
|
-
const result: any = { ...node };
|
|
1066
|
+
AlterTableStmt(node, context) {
|
|
1067
|
+
const result = { ...node };
|
|
1099
1068
|
if ('relkind' in result) {
|
|
1100
1069
|
result.objtype = result.relkind;
|
|
1101
1070
|
delete result.relkind;
|
|
1102
1071
|
}
|
|
1103
1072
|
if (result.relation !== undefined) {
|
|
1104
|
-
result.relation = this.transform(result.relation
|
|
1073
|
+
result.relation = this.transform(result.relation, context);
|
|
1105
1074
|
}
|
|
1106
1075
|
if (result.cmds !== undefined) {
|
|
1107
1076
|
result.cmds = Array.isArray(result.cmds)
|
|
1108
|
-
? result.cmds.map((item
|
|
1109
|
-
: this.transform(result.cmds
|
|
1077
|
+
? result.cmds.map((item) => this.transform(item, context))
|
|
1078
|
+
: this.transform(result.cmds, context);
|
|
1110
1079
|
}
|
|
1111
1080
|
return { AlterTableStmt: result };
|
|
1112
1081
|
}
|
|
1113
|
-
CreateTableAsStmt(node
|
|
1114
|
-
|
|
1115
|
-
} {
|
|
1116
|
-
const result: any = { ...node };
|
|
1082
|
+
CreateTableAsStmt(node, context) {
|
|
1083
|
+
const result = { ...node };
|
|
1117
1084
|
if ('relkind' in result) {
|
|
1118
1085
|
result.objtype = result.relkind;
|
|
1119
1086
|
delete result.relkind;
|
|
1120
1087
|
}
|
|
1121
1088
|
if (result.query !== undefined) {
|
|
1122
|
-
result.query = this.transform(result.query
|
|
1089
|
+
result.query = this.transform(result.query, context);
|
|
1123
1090
|
}
|
|
1124
1091
|
if (result.into !== undefined) {
|
|
1125
|
-
result.into = this.transform(result.into
|
|
1092
|
+
result.into = this.transform(result.into, context);
|
|
1126
1093
|
}
|
|
1127
1094
|
return { CreateTableAsStmt: result };
|
|
1128
1095
|
}
|
|
1129
|
-
RawStmt(node
|
|
1130
|
-
|
|
1131
|
-
} {
|
|
1132
|
-
const result: any = {};
|
|
1096
|
+
RawStmt(node, context) {
|
|
1097
|
+
const result = {};
|
|
1133
1098
|
if (node.stmt !== undefined) {
|
|
1134
1099
|
result.stmt = this.transform(node.stmt, context);
|
|
1135
1100
|
}
|
|
@@ -1141,17 +1106,15 @@ export class V13ToV14Transformer {
|
|
|
1141
1106
|
}
|
|
1142
1107
|
return { RawStmt: result };
|
|
1143
1108
|
}
|
|
1144
|
-
SelectStmt(node
|
|
1145
|
-
|
|
1146
|
-
} {
|
|
1147
|
-
const result: any = {};
|
|
1109
|
+
SelectStmt(node, context) {
|
|
1110
|
+
const result = {};
|
|
1148
1111
|
if (node.distinctClause !== undefined) {
|
|
1149
1112
|
result.distinctClause = Array.isArray(node.distinctClause)
|
|
1150
1113
|
? node.distinctClause.map(item => this.transform(item, context))
|
|
1151
1114
|
: this.transform(node.distinctClause, context);
|
|
1152
1115
|
}
|
|
1153
1116
|
if (node.intoClause !== undefined) {
|
|
1154
|
-
result.intoClause = this.transform(node.intoClause
|
|
1117
|
+
result.intoClause = this.transform(node.intoClause, context);
|
|
1155
1118
|
}
|
|
1156
1119
|
if (node.targetList !== undefined) {
|
|
1157
1120
|
result.targetList = Array.isArray(node.targetList)
|
|
@@ -1205,20 +1168,20 @@ export class V13ToV14Transformer {
|
|
|
1205
1168
|
}
|
|
1206
1169
|
if (node.withClause !== undefined) {
|
|
1207
1170
|
// Handle WithClause transformation directly here since the method dispatch isn't working
|
|
1208
|
-
const withClause = node.withClause
|
|
1171
|
+
const withClause = node.withClause;
|
|
1209
1172
|
if (withClause && typeof withClause === 'object' && withClause.ctes !== undefined) {
|
|
1210
|
-
const transformedWithClause
|
|
1173
|
+
const transformedWithClause = { ...withClause };
|
|
1211
1174
|
if (typeof withClause.ctes === 'object' && withClause.ctes !== null && !Array.isArray(withClause.ctes)) {
|
|
1212
1175
|
const cteArray = Object.keys(withClause.ctes)
|
|
1213
1176
|
.sort((a, b) => parseInt(a) - parseInt(b))
|
|
1214
|
-
.map(key => this.transform(
|
|
1177
|
+
.map(key => this.transform(withClause.ctes[key], context));
|
|
1215
1178
|
transformedWithClause.ctes = cteArray;
|
|
1216
1179
|
}
|
|
1217
1180
|
else if (Array.isArray(withClause.ctes)) {
|
|
1218
|
-
transformedWithClause.ctes = withClause.ctes.map((item
|
|
1181
|
+
transformedWithClause.ctes = withClause.ctes.map((item) => this.transform(item, context));
|
|
1219
1182
|
}
|
|
1220
1183
|
else {
|
|
1221
|
-
transformedWithClause.ctes = this.transform(withClause.ctes
|
|
1184
|
+
transformedWithClause.ctes = this.transform(withClause.ctes, context);
|
|
1222
1185
|
}
|
|
1223
1186
|
if (withClause.recursive !== undefined) {
|
|
1224
1187
|
transformedWithClause.recursive = withClause.recursive;
|
|
@@ -1229,7 +1192,7 @@ export class V13ToV14Transformer {
|
|
|
1229
1192
|
result.withClause = transformedWithClause;
|
|
1230
1193
|
}
|
|
1231
1194
|
else {
|
|
1232
|
-
result.withClause = this.transform(node.withClause
|
|
1195
|
+
result.withClause = this.transform(node.withClause, context);
|
|
1233
1196
|
}
|
|
1234
1197
|
}
|
|
1235
1198
|
if (node.op !== undefined) {
|
|
@@ -1239,17 +1202,15 @@ export class V13ToV14Transformer {
|
|
|
1239
1202
|
result.all = node.all;
|
|
1240
1203
|
}
|
|
1241
1204
|
if (node.larg !== undefined) {
|
|
1242
|
-
result.larg = this.transform(node.larg
|
|
1205
|
+
result.larg = this.transform(node.larg, context);
|
|
1243
1206
|
}
|
|
1244
1207
|
if (node.rarg !== undefined) {
|
|
1245
|
-
result.rarg = this.transform(node.rarg
|
|
1208
|
+
result.rarg = this.transform(node.rarg, context);
|
|
1246
1209
|
}
|
|
1247
1210
|
return { SelectStmt: result };
|
|
1248
1211
|
}
|
|
1249
|
-
RangeSubselect(node
|
|
1250
|
-
|
|
1251
|
-
} {
|
|
1252
|
-
const result: any = {};
|
|
1212
|
+
RangeSubselect(node, context) {
|
|
1213
|
+
const result = {};
|
|
1253
1214
|
if (node.lateral !== undefined) {
|
|
1254
1215
|
result.lateral = node.lateral;
|
|
1255
1216
|
}
|
|
@@ -1261,29 +1222,27 @@ export class V13ToV14Transformer {
|
|
|
1261
1222
|
}
|
|
1262
1223
|
return { RangeSubselect: result };
|
|
1263
1224
|
}
|
|
1264
|
-
CommonTableExpr(node
|
|
1265
|
-
|
|
1266
|
-
} {
|
|
1267
|
-
const result: any = { ...node };
|
|
1225
|
+
CommonTableExpr(node, context) {
|
|
1226
|
+
const result = { ...node };
|
|
1268
1227
|
if (node.ctename !== undefined) {
|
|
1269
1228
|
result.ctename = node.ctename;
|
|
1270
1229
|
}
|
|
1271
1230
|
if (node.aliascolnames !== undefined) {
|
|
1272
1231
|
result.aliascolnames = Array.isArray(node.aliascolnames)
|
|
1273
|
-
? node.aliascolnames.map(item => this.transform(item
|
|
1274
|
-
: this.transform(node.aliascolnames
|
|
1232
|
+
? node.aliascolnames.map(item => this.transform(item, context))
|
|
1233
|
+
: this.transform(node.aliascolnames, context);
|
|
1275
1234
|
}
|
|
1276
1235
|
if (node.ctematerialized !== undefined) {
|
|
1277
1236
|
result.ctematerialized = node.ctematerialized;
|
|
1278
1237
|
}
|
|
1279
1238
|
if (node.ctequery !== undefined) {
|
|
1280
|
-
const nodeType = this.getNodeType(node.ctequery
|
|
1281
|
-
const nodeData = this.getNodeData(node.ctequery
|
|
1239
|
+
const nodeType = this.getNodeType(node.ctequery);
|
|
1240
|
+
const nodeData = this.getNodeData(node.ctequery);
|
|
1282
1241
|
if (nodeType === 'SelectStmt' && typeof this.SelectStmt === 'function') {
|
|
1283
1242
|
result.ctequery = this.SelectStmt(nodeData, context);
|
|
1284
1243
|
}
|
|
1285
1244
|
else {
|
|
1286
|
-
result.ctequery = this.transform(node.ctequery
|
|
1245
|
+
result.ctequery = this.transform(node.ctequery, context);
|
|
1287
1246
|
}
|
|
1288
1247
|
}
|
|
1289
1248
|
if (node.location !== undefined) {
|
|
@@ -1297,30 +1256,28 @@ export class V13ToV14Transformer {
|
|
|
1297
1256
|
}
|
|
1298
1257
|
if (node.ctecolnames !== undefined) {
|
|
1299
1258
|
result.ctecolnames = Array.isArray(node.ctecolnames)
|
|
1300
|
-
? node.ctecolnames.map(item => this.transform(item
|
|
1301
|
-
: this.transform(node.ctecolnames
|
|
1259
|
+
? node.ctecolnames.map(item => this.transform(item, context))
|
|
1260
|
+
: this.transform(node.ctecolnames, context);
|
|
1302
1261
|
}
|
|
1303
1262
|
if (node.ctecoltypes !== undefined) {
|
|
1304
1263
|
result.ctecoltypes = Array.isArray(node.ctecoltypes)
|
|
1305
|
-
? node.ctecoltypes.map(item => this.transform(item
|
|
1306
|
-
: this.transform(node.ctecoltypes
|
|
1264
|
+
? node.ctecoltypes.map(item => this.transform(item, context))
|
|
1265
|
+
: this.transform(node.ctecoltypes, context);
|
|
1307
1266
|
}
|
|
1308
1267
|
if (node.ctecoltypmods !== undefined) {
|
|
1309
1268
|
result.ctecoltypmods = Array.isArray(node.ctecoltypmods)
|
|
1310
|
-
? node.ctecoltypmods.map(item => this.transform(item
|
|
1311
|
-
: this.transform(node.ctecoltypmods
|
|
1269
|
+
? node.ctecoltypmods.map(item => this.transform(item, context))
|
|
1270
|
+
: this.transform(node.ctecoltypmods, context);
|
|
1312
1271
|
}
|
|
1313
1272
|
if (node.ctecolcollations !== undefined) {
|
|
1314
1273
|
result.ctecolcollations = Array.isArray(node.ctecolcollations)
|
|
1315
|
-
? node.ctecolcollations.map(item => this.transform(item
|
|
1316
|
-
: this.transform(node.ctecolcollations
|
|
1274
|
+
? node.ctecolcollations.map(item => this.transform(item, context))
|
|
1275
|
+
: this.transform(node.ctecolcollations, context);
|
|
1317
1276
|
}
|
|
1318
1277
|
return { CommonTableExpr: result };
|
|
1319
1278
|
}
|
|
1320
|
-
SubLink(node
|
|
1321
|
-
|
|
1322
|
-
} {
|
|
1323
|
-
const result: any = {};
|
|
1279
|
+
SubLink(node, context) {
|
|
1280
|
+
const result = {};
|
|
1324
1281
|
if (node.xpr !== undefined) {
|
|
1325
1282
|
result.xpr = this.transform(node.xpr, context);
|
|
1326
1283
|
}
|
|
@@ -1344,20 +1301,18 @@ export class V13ToV14Transformer {
|
|
|
1344
1301
|
}
|
|
1345
1302
|
return { SubLink: result };
|
|
1346
1303
|
}
|
|
1347
|
-
CopyStmt(node
|
|
1348
|
-
|
|
1349
|
-
} {
|
|
1350
|
-
const result: any = {};
|
|
1304
|
+
CopyStmt(node, context) {
|
|
1305
|
+
const result = {};
|
|
1351
1306
|
if (node.relation !== undefined) {
|
|
1352
|
-
result.relation = this.transform(node.relation
|
|
1307
|
+
result.relation = this.transform(node.relation, context);
|
|
1353
1308
|
}
|
|
1354
1309
|
if (node.query !== undefined) {
|
|
1355
|
-
result.query = this.transform(node.query
|
|
1310
|
+
result.query = this.transform(node.query, context);
|
|
1356
1311
|
}
|
|
1357
1312
|
if (node.attlist !== undefined) {
|
|
1358
1313
|
result.attlist = Array.isArray(node.attlist)
|
|
1359
|
-
? node.attlist.map(item => this.transform(item
|
|
1360
|
-
: this.transform(node.attlist
|
|
1314
|
+
? node.attlist.map(item => this.transform(item, context))
|
|
1315
|
+
: this.transform(node.attlist, context);
|
|
1361
1316
|
}
|
|
1362
1317
|
if (node.is_from !== undefined) {
|
|
1363
1318
|
result.is_from = node.is_from;
|
|
@@ -1370,34 +1325,30 @@ export class V13ToV14Transformer {
|
|
|
1370
1325
|
}
|
|
1371
1326
|
if (node.options !== undefined) {
|
|
1372
1327
|
result.options = Array.isArray(node.options)
|
|
1373
|
-
? node.options.map(item => this.transform(item
|
|
1374
|
-
: this.transform(node.options
|
|
1328
|
+
? node.options.map(item => this.transform(item, context))
|
|
1329
|
+
: this.transform(node.options, context);
|
|
1375
1330
|
}
|
|
1376
1331
|
if (node.whereClause !== undefined) {
|
|
1377
|
-
result.whereClause = this.transform(node.whereClause
|
|
1332
|
+
result.whereClause = this.transform(node.whereClause, context);
|
|
1378
1333
|
}
|
|
1379
1334
|
return { CopyStmt: result };
|
|
1380
1335
|
}
|
|
1381
|
-
CreateEnumStmt(node
|
|
1382
|
-
|
|
1383
|
-
} {
|
|
1384
|
-
const result: any = {};
|
|
1336
|
+
CreateEnumStmt(node, context) {
|
|
1337
|
+
const result = {};
|
|
1385
1338
|
if (node.typeName !== undefined) {
|
|
1386
1339
|
result.typeName = Array.isArray(node.typeName)
|
|
1387
|
-
? node.typeName.map(item => this.transform(item
|
|
1388
|
-
: this.transform(node.typeName
|
|
1340
|
+
? node.typeName.map(item => this.transform(item, context))
|
|
1341
|
+
: this.transform(node.typeName, context);
|
|
1389
1342
|
}
|
|
1390
1343
|
if (node.vals !== undefined) {
|
|
1391
1344
|
result.vals = Array.isArray(node.vals)
|
|
1392
|
-
? node.vals.map(item => this.transform(item
|
|
1393
|
-
: this.transform(node.vals
|
|
1345
|
+
? node.vals.map(item => this.transform(item, context))
|
|
1346
|
+
: this.transform(node.vals, context);
|
|
1394
1347
|
}
|
|
1395
1348
|
return { CreateEnumStmt: result };
|
|
1396
1349
|
}
|
|
1397
|
-
DefineStmt(node
|
|
1398
|
-
|
|
1399
|
-
} {
|
|
1400
|
-
const result: any = {};
|
|
1350
|
+
DefineStmt(node, context) {
|
|
1351
|
+
const result = {};
|
|
1401
1352
|
if (node.kind !== undefined) {
|
|
1402
1353
|
result.kind = node.kind;
|
|
1403
1354
|
}
|
|
@@ -1406,18 +1357,18 @@ export class V13ToV14Transformer {
|
|
|
1406
1357
|
}
|
|
1407
1358
|
if (node.defnames !== undefined) {
|
|
1408
1359
|
result.defnames = Array.isArray(node.defnames)
|
|
1409
|
-
? node.defnames.map(item => this.transform(item
|
|
1410
|
-
: this.transform(node.defnames
|
|
1360
|
+
? node.defnames.map(item => this.transform(item, context))
|
|
1361
|
+
: this.transform(node.defnames, context);
|
|
1411
1362
|
}
|
|
1412
1363
|
if (node.args !== undefined) {
|
|
1413
1364
|
result.args = Array.isArray(node.args)
|
|
1414
|
-
? node.args.map(item => this.transform(item
|
|
1415
|
-
: this.transform(node.args
|
|
1365
|
+
? node.args.map(item => this.transform(item, context))
|
|
1366
|
+
: this.transform(node.args, context);
|
|
1416
1367
|
}
|
|
1417
1368
|
if (node.definition !== undefined) {
|
|
1418
1369
|
result.definition = Array.isArray(node.definition)
|
|
1419
|
-
? node.definition.map(item => this.transform(item
|
|
1420
|
-
: this.transform(node.definition
|
|
1370
|
+
? node.definition.map(item => this.transform(item, context))
|
|
1371
|
+
: this.transform(node.definition, context);
|
|
1421
1372
|
}
|
|
1422
1373
|
if (node.if_not_exists !== undefined) {
|
|
1423
1374
|
result.if_not_exists = node.if_not_exists;
|
|
@@ -1427,21 +1378,17 @@ export class V13ToV14Transformer {
|
|
|
1427
1378
|
}
|
|
1428
1379
|
return { DefineStmt: result };
|
|
1429
1380
|
}
|
|
1430
|
-
DoStmt(node
|
|
1431
|
-
|
|
1432
|
-
} {
|
|
1433
|
-
const result: any = {};
|
|
1381
|
+
DoStmt(node, context) {
|
|
1382
|
+
const result = {};
|
|
1434
1383
|
if (node.args !== undefined) {
|
|
1435
1384
|
result.args = Array.isArray(node.args)
|
|
1436
|
-
? node.args.map(item => this.transform(item
|
|
1437
|
-
: this.transform(node.args
|
|
1385
|
+
? node.args.map(item => this.transform(item, context))
|
|
1386
|
+
: this.transform(node.args, context);
|
|
1438
1387
|
}
|
|
1439
1388
|
return { DoStmt: result };
|
|
1440
1389
|
}
|
|
1441
|
-
DeclareCursorStmt(node
|
|
1442
|
-
|
|
1443
|
-
} {
|
|
1444
|
-
const result: any = {};
|
|
1390
|
+
DeclareCursorStmt(node, context) {
|
|
1391
|
+
const result = {};
|
|
1445
1392
|
if (node.portalname !== undefined) {
|
|
1446
1393
|
result.portalname = node.portalname;
|
|
1447
1394
|
}
|
|
@@ -1460,47 +1407,41 @@ export class V13ToV14Transformer {
|
|
|
1460
1407
|
}
|
|
1461
1408
|
}
|
|
1462
1409
|
if (node.query !== undefined) {
|
|
1463
|
-
result.query = this.transform(node.query
|
|
1410
|
+
result.query = this.transform(node.query, context);
|
|
1464
1411
|
}
|
|
1465
1412
|
return { DeclareCursorStmt: result };
|
|
1466
1413
|
}
|
|
1467
|
-
VacuumStmt(node
|
|
1468
|
-
|
|
1469
|
-
} {
|
|
1470
|
-
const result: any = {};
|
|
1414
|
+
VacuumStmt(node, context) {
|
|
1415
|
+
const result = {};
|
|
1471
1416
|
if (node.options !== undefined) {
|
|
1472
1417
|
result.options = Array.isArray(node.options)
|
|
1473
|
-
? node.options.map(item => this.transform(item
|
|
1474
|
-
: this.transform(node.options
|
|
1418
|
+
? node.options.map(item => this.transform(item, context))
|
|
1419
|
+
: this.transform(node.options, context);
|
|
1475
1420
|
}
|
|
1476
1421
|
if (node.rels !== undefined) {
|
|
1477
1422
|
result.rels = Array.isArray(node.rels)
|
|
1478
|
-
? node.rels.map(item => this.transform(item
|
|
1479
|
-
: this.transform(node.rels
|
|
1423
|
+
? node.rels.map(item => this.transform(item, context))
|
|
1424
|
+
: this.transform(node.rels, context);
|
|
1480
1425
|
}
|
|
1481
1426
|
if (node.is_vacuumcmd !== undefined) {
|
|
1482
1427
|
result.is_vacuumcmd = node.is_vacuumcmd;
|
|
1483
1428
|
}
|
|
1484
1429
|
return { VacuumStmt: result };
|
|
1485
1430
|
}
|
|
1486
|
-
VacuumRelation(node
|
|
1487
|
-
|
|
1488
|
-
} {
|
|
1489
|
-
const result: any = {};
|
|
1431
|
+
VacuumRelation(node, context) {
|
|
1432
|
+
const result = {};
|
|
1490
1433
|
if (node.relation !== undefined) {
|
|
1491
1434
|
result.relation = node.relation;
|
|
1492
1435
|
}
|
|
1493
1436
|
if (node.va_cols !== undefined) {
|
|
1494
1437
|
result.va_cols = Array.isArray(node.va_cols)
|
|
1495
|
-
? node.va_cols.map(item => this.transform(item
|
|
1496
|
-
: this.transform(node.va_cols
|
|
1438
|
+
? node.va_cols.map(item => this.transform(item, context))
|
|
1439
|
+
: this.transform(node.va_cols, context);
|
|
1497
1440
|
}
|
|
1498
1441
|
return { VacuumRelation: result };
|
|
1499
1442
|
}
|
|
1500
|
-
RangeVar(node
|
|
1501
|
-
|
|
1502
|
-
} {
|
|
1503
|
-
const result: any = {};
|
|
1443
|
+
RangeVar(node, context) {
|
|
1444
|
+
const result = {};
|
|
1504
1445
|
if (node.catalogname !== undefined) {
|
|
1505
1446
|
result.catalogname = node.catalogname;
|
|
1506
1447
|
}
|
|
@@ -1518,29 +1459,27 @@ export class V13ToV14Transformer {
|
|
|
1518
1459
|
result.relpersistence = node.relpersistence;
|
|
1519
1460
|
}
|
|
1520
1461
|
if (node.alias !== undefined) {
|
|
1521
|
-
result.alias = this.transform(node.alias
|
|
1462
|
+
result.alias = this.transform(node.alias, context);
|
|
1522
1463
|
}
|
|
1523
1464
|
if (node.location !== undefined) {
|
|
1524
1465
|
result.location = node.location;
|
|
1525
1466
|
}
|
|
1526
1467
|
return { RangeVar: result };
|
|
1527
1468
|
}
|
|
1528
|
-
IntoClause(node
|
|
1529
|
-
|
|
1530
|
-
} {
|
|
1531
|
-
const result: any = {};
|
|
1469
|
+
IntoClause(node, context) {
|
|
1470
|
+
const result = {};
|
|
1532
1471
|
if (node.rel !== undefined) {
|
|
1533
1472
|
result.rel = node.rel;
|
|
1534
1473
|
}
|
|
1535
1474
|
if (node.colNames !== undefined) {
|
|
1536
1475
|
result.colNames = Array.isArray(node.colNames)
|
|
1537
|
-
? node.colNames.map(item => this.transform(item
|
|
1538
|
-
: this.transform(node.colNames
|
|
1476
|
+
? node.colNames.map(item => this.transform(item, context))
|
|
1477
|
+
: this.transform(node.colNames, context);
|
|
1539
1478
|
}
|
|
1540
1479
|
if (node.options !== undefined) {
|
|
1541
1480
|
result.options = Array.isArray(node.options)
|
|
1542
|
-
? node.options.map(item => this.transform(item
|
|
1543
|
-
: this.transform(node.options
|
|
1481
|
+
? node.options.map(item => this.transform(item, context))
|
|
1482
|
+
: this.transform(node.options, context);
|
|
1544
1483
|
}
|
|
1545
1484
|
if (node.onCommit !== undefined) {
|
|
1546
1485
|
result.onCommit = node.onCommit;
|
|
@@ -1549,30 +1488,28 @@ export class V13ToV14Transformer {
|
|
|
1549
1488
|
result.tableSpaceName = node.tableSpaceName;
|
|
1550
1489
|
}
|
|
1551
1490
|
if (node.viewQuery !== undefined) {
|
|
1552
|
-
result.viewQuery = this.transform(node.viewQuery
|
|
1491
|
+
result.viewQuery = this.transform(node.viewQuery, context);
|
|
1553
1492
|
}
|
|
1554
1493
|
if (node.skipData !== undefined) {
|
|
1555
1494
|
result.skipData = node.skipData;
|
|
1556
1495
|
}
|
|
1557
1496
|
return { IntoClause: result };
|
|
1558
1497
|
}
|
|
1559
|
-
CreateCastStmt(node
|
|
1560
|
-
|
|
1561
|
-
} {
|
|
1562
|
-
const result: any = {};
|
|
1498
|
+
CreateCastStmt(node, context) {
|
|
1499
|
+
const result = {};
|
|
1563
1500
|
if (node.sourcetype !== undefined) {
|
|
1564
|
-
result.sourcetype = this.transform(node.sourcetype
|
|
1501
|
+
result.sourcetype = this.transform(node.sourcetype, context);
|
|
1565
1502
|
}
|
|
1566
1503
|
if (node.targettype !== undefined) {
|
|
1567
|
-
result.targettype = this.transform(node.targettype
|
|
1504
|
+
result.targettype = this.transform(node.targettype, context);
|
|
1568
1505
|
}
|
|
1569
1506
|
if (node.func !== undefined) {
|
|
1570
|
-
const childContext
|
|
1507
|
+
const childContext = {
|
|
1571
1508
|
...context,
|
|
1572
1509
|
parentNodeTypes: [...(context.parentNodeTypes || []), 'CreateCastStmt']
|
|
1573
1510
|
};
|
|
1574
1511
|
const wrappedFunc = { ObjectWithArgs: node.func };
|
|
1575
|
-
const transformedFunc = this.transform(wrappedFunc
|
|
1512
|
+
const transformedFunc = this.transform(wrappedFunc, childContext);
|
|
1576
1513
|
result.func = transformedFunc.ObjectWithArgs;
|
|
1577
1514
|
}
|
|
1578
1515
|
if (node.context !== undefined) {
|
|
@@ -1583,28 +1520,26 @@ export class V13ToV14Transformer {
|
|
|
1583
1520
|
}
|
|
1584
1521
|
return { CreateCastStmt: result };
|
|
1585
1522
|
}
|
|
1586
|
-
CreateTransformStmt(node
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
const result: any = {};
|
|
1590
|
-
const childContext: any = {
|
|
1523
|
+
CreateTransformStmt(node, context) {
|
|
1524
|
+
const result = {};
|
|
1525
|
+
const childContext = {
|
|
1591
1526
|
...context,
|
|
1592
1527
|
parentNodeTypes: [...(context.parentNodeTypes || []), 'CreateTransformStmt']
|
|
1593
1528
|
};
|
|
1594
1529
|
if (node.type_name !== undefined) {
|
|
1595
|
-
result.type_name = this.transform(node.type_name
|
|
1530
|
+
result.type_name = this.transform(node.type_name, childContext);
|
|
1596
1531
|
}
|
|
1597
1532
|
if (node.lang !== undefined) {
|
|
1598
1533
|
result.lang = node.lang;
|
|
1599
1534
|
}
|
|
1600
1535
|
if (node.fromsql !== undefined) {
|
|
1601
1536
|
const wrappedFromsql = { ObjectWithArgs: node.fromsql };
|
|
1602
|
-
const transformedFromsql = this.transform(wrappedFromsql
|
|
1537
|
+
const transformedFromsql = this.transform(wrappedFromsql, childContext);
|
|
1603
1538
|
result.fromsql = transformedFromsql.ObjectWithArgs;
|
|
1604
1539
|
}
|
|
1605
1540
|
if (node.tosql !== undefined) {
|
|
1606
1541
|
const wrappedTosql = { ObjectWithArgs: node.tosql };
|
|
1607
|
-
const transformedTosql = this.transform(wrappedTosql
|
|
1542
|
+
const transformedTosql = this.transform(wrappedTosql, childContext);
|
|
1608
1543
|
result.tosql = transformedTosql.ObjectWithArgs;
|
|
1609
1544
|
}
|
|
1610
1545
|
if (node.replace !== undefined) {
|
|
@@ -1612,16 +1547,14 @@ export class V13ToV14Transformer {
|
|
|
1612
1547
|
}
|
|
1613
1548
|
return { CreateTransformStmt: result };
|
|
1614
1549
|
}
|
|
1615
|
-
CreateFunctionStmt(node
|
|
1616
|
-
|
|
1617
|
-
} {
|
|
1618
|
-
const result: any = { ...node };
|
|
1550
|
+
CreateFunctionStmt(node, context) {
|
|
1551
|
+
const result = { ...node };
|
|
1619
1552
|
const hasExplicitModes = this.functionHasExplicitModes(node.parameters);
|
|
1620
1553
|
const allHaveExplicitModes = this.allParametersHaveExplicitModes(node.parameters);
|
|
1621
1554
|
const hasOnlyExplicitIn = this.hasOnlyExplicitInParameters(node.parameters);
|
|
1622
1555
|
const hasExplicitIn = this.hasExplicitInParameters(node.parameters);
|
|
1623
1556
|
// Create child context with CreateFunctionStmt as parent and explicit mode info
|
|
1624
|
-
const childContext
|
|
1557
|
+
const childContext = {
|
|
1625
1558
|
...context,
|
|
1626
1559
|
parentNodeTypes: [...(context.parentNodeTypes || []), 'CreateFunctionStmt'],
|
|
1627
1560
|
functionHasExplicitModes: hasExplicitModes,
|
|
@@ -1631,30 +1564,28 @@ export class V13ToV14Transformer {
|
|
|
1631
1564
|
};
|
|
1632
1565
|
if (node.funcname !== undefined) {
|
|
1633
1566
|
result.funcname = Array.isArray(node.funcname)
|
|
1634
|
-
? node.funcname.map(item => this.transform(item
|
|
1635
|
-
: this.transform(node.funcname
|
|
1567
|
+
? node.funcname.map(item => this.transform(item, context))
|
|
1568
|
+
: this.transform(node.funcname, context);
|
|
1636
1569
|
}
|
|
1637
1570
|
if (node.parameters !== undefined) {
|
|
1638
1571
|
result.parameters = Array.isArray(node.parameters)
|
|
1639
|
-
? node.parameters.map(item => this.transform(item
|
|
1640
|
-
: this.transform(node.parameters
|
|
1572
|
+
? node.parameters.map(item => this.transform(item, childContext))
|
|
1573
|
+
: this.transform(node.parameters, childContext);
|
|
1641
1574
|
}
|
|
1642
1575
|
if (node.returnType !== undefined) {
|
|
1643
|
-
result.returnType = this.transform(node.returnType
|
|
1576
|
+
result.returnType = this.transform(node.returnType, context);
|
|
1644
1577
|
}
|
|
1645
1578
|
if (node.options !== undefined) {
|
|
1646
1579
|
result.options = Array.isArray(node.options)
|
|
1647
|
-
? node.options.map(item => this.transform(item
|
|
1648
|
-
: this.transform(node.options
|
|
1580
|
+
? node.options.map(item => this.transform(item, context))
|
|
1581
|
+
: this.transform(node.options, context);
|
|
1649
1582
|
}
|
|
1650
1583
|
return { CreateFunctionStmt: result };
|
|
1651
1584
|
}
|
|
1652
|
-
TableLikeClause(node
|
|
1653
|
-
|
|
1654
|
-
} {
|
|
1655
|
-
const result: any = {};
|
|
1585
|
+
TableLikeClause(node, context) {
|
|
1586
|
+
const result = {};
|
|
1656
1587
|
if (node.relation !== undefined) {
|
|
1657
|
-
result.relation = this.transform(node.relation
|
|
1588
|
+
result.relation = this.transform(node.relation, context);
|
|
1658
1589
|
}
|
|
1659
1590
|
if (node.options !== undefined) {
|
|
1660
1591
|
if (typeof node.options === 'number') {
|
|
@@ -1666,10 +1597,8 @@ export class V13ToV14Transformer {
|
|
|
1666
1597
|
}
|
|
1667
1598
|
return { TableLikeClause: result };
|
|
1668
1599
|
}
|
|
1669
|
-
|
|
1670
|
-
const pg13ToP14TableLikeMapping
|
|
1671
|
-
[key: number]: number;
|
|
1672
|
-
} = {
|
|
1600
|
+
transformTableLikeOption(option) {
|
|
1601
|
+
const pg13ToP14TableLikeMapping = {
|
|
1673
1602
|
0: 0,
|
|
1674
1603
|
1: 2,
|
|
1675
1604
|
2: 3,
|
|
@@ -1683,7 +1612,7 @@ export class V13ToV14Transformer {
|
|
|
1683
1612
|
};
|
|
1684
1613
|
return pg13ToP14TableLikeMapping[option] !== undefined ? pg13ToP14TableLikeMapping[option] : option;
|
|
1685
1614
|
}
|
|
1686
|
-
|
|
1615
|
+
extractParameterNameFromFunctionName(functionName, paramIndex, isVariadic) {
|
|
1687
1616
|
if (!functionName) {
|
|
1688
1617
|
return undefined;
|
|
1689
1618
|
}
|
|
@@ -1708,13 +1637,11 @@ export class V13ToV14Transformer {
|
|
|
1708
1637
|
// Functions like testfunc1(int), testfunc2(int), testfunc4(boolean) should NOT have parameter names
|
|
1709
1638
|
return undefined;
|
|
1710
1639
|
}
|
|
1711
|
-
ObjectWithArgs(node
|
|
1712
|
-
|
|
1713
|
-
} {
|
|
1714
|
-
const result: any = { ...node };
|
|
1640
|
+
ObjectWithArgs(node, context) {
|
|
1641
|
+
const result = { ...node };
|
|
1715
1642
|
if (result.objname !== undefined) {
|
|
1716
1643
|
if (Array.isArray(result.objname)) {
|
|
1717
|
-
result.objname = result.objname.map((item
|
|
1644
|
+
result.objname = result.objname.map((item) => this.transform(item, context));
|
|
1718
1645
|
}
|
|
1719
1646
|
else if (typeof result.objname === 'object' && result.objname !== null) {
|
|
1720
1647
|
const keys = Object.keys(result.objname);
|
|
@@ -1723,7 +1650,7 @@ export class V13ToV14Transformer {
|
|
|
1723
1650
|
// Check if we should preserve objname as object with numeric keys
|
|
1724
1651
|
const shouldPreserve = this.shouldPreserveObjnameAsObject(context);
|
|
1725
1652
|
if (shouldPreserve) {
|
|
1726
|
-
const transformedObjname
|
|
1653
|
+
const transformedObjname = {};
|
|
1727
1654
|
Object.keys(result.objname).forEach(k => {
|
|
1728
1655
|
transformedObjname[k] = this.transform(result.objname[k], context);
|
|
1729
1656
|
});
|
|
@@ -1745,7 +1672,7 @@ export class V13ToV14Transformer {
|
|
|
1745
1672
|
}
|
|
1746
1673
|
if (result.objargs !== undefined) {
|
|
1747
1674
|
result.objargs = Array.isArray(result.objargs)
|
|
1748
|
-
? result.objargs.map((item
|
|
1675
|
+
? result.objargs.map((item) => this.transform(item, context))
|
|
1749
1676
|
: [this.transform(result.objargs, context)];
|
|
1750
1677
|
}
|
|
1751
1678
|
// Handle special cases for objfuncargs deletion in specific contexts
|
|
@@ -1755,13 +1682,13 @@ export class V13ToV14Transformer {
|
|
|
1755
1682
|
const shouldCreateObjfuncargsFromObjargs = this.shouldCreateObjfuncargsFromObjargs(context);
|
|
1756
1683
|
if (shouldCreateObjfuncargsFromObjargs && result.objargs) {
|
|
1757
1684
|
// Create objfuncargs from objargs, with smart parameter mode handling
|
|
1758
|
-
const originalObjfuncargs =
|
|
1685
|
+
const originalObjfuncargs = node.objfuncargs;
|
|
1759
1686
|
// Don't create objfuncargs in certain contexts where they shouldn't exist
|
|
1760
|
-
const skipObjfuncargsContexts
|
|
1687
|
+
const skipObjfuncargsContexts = [];
|
|
1761
1688
|
const shouldSkipObjfuncargs = skipObjfuncargsContexts.some(ctx => context.parentNodeTypes?.includes(ctx));
|
|
1762
1689
|
if (originalObjfuncargs && Array.isArray(originalObjfuncargs)) {
|
|
1763
1690
|
if (!shouldSkipObjfuncargs) {
|
|
1764
|
-
result.objfuncargs = originalObjfuncargs.map((item
|
|
1691
|
+
result.objfuncargs = originalObjfuncargs.map((item) => {
|
|
1765
1692
|
return this.transform(item, context);
|
|
1766
1693
|
});
|
|
1767
1694
|
}
|
|
@@ -1769,7 +1696,7 @@ export class V13ToV14Transformer {
|
|
|
1769
1696
|
else {
|
|
1770
1697
|
if (!shouldSkipObjfuncargs) {
|
|
1771
1698
|
result.objfuncargs = Array.isArray(result.objargs)
|
|
1772
|
-
? result.objargs.map((arg
|
|
1699
|
+
? result.objargs.map((arg, index) => {
|
|
1773
1700
|
const transformedArgType = this.visit(arg, context);
|
|
1774
1701
|
// Check if there's an existing objfuncargs with original mode information
|
|
1775
1702
|
let mode = 'FUNC_PARAM_DEFAULT';
|
|
@@ -1788,7 +1715,7 @@ export class V13ToV14Transformer {
|
|
|
1788
1715
|
mode = isVariadic ? 'FUNC_PARAM_VARIADIC' : 'FUNC_PARAM_DEFAULT';
|
|
1789
1716
|
}
|
|
1790
1717
|
// Extract parameter name if available from original objfuncargs
|
|
1791
|
-
let paramName
|
|
1718
|
+
let paramName;
|
|
1792
1719
|
if (originalObjfuncargs && Array.isArray(originalObjfuncargs) && originalObjfuncargs[index]) {
|
|
1793
1720
|
const originalParam = originalObjfuncargs[index];
|
|
1794
1721
|
if (originalParam && originalParam.FunctionParameter && originalParam.FunctionParameter.name) {
|
|
@@ -1796,9 +1723,9 @@ export class V13ToV14Transformer {
|
|
|
1796
1723
|
}
|
|
1797
1724
|
}
|
|
1798
1725
|
if (!paramName && context.parentNodeTypes?.includes('DropStmt') &&
|
|
1799
|
-
|
|
1726
|
+
context.dropRemoveType === 'OBJECT_FUNCTION') {
|
|
1800
1727
|
// Extract function name from current node
|
|
1801
|
-
let functionName
|
|
1728
|
+
let functionName;
|
|
1802
1729
|
if (node.objname && Array.isArray(node.objname) && node.objname.length > 0) {
|
|
1803
1730
|
const lastName = node.objname[node.objname.length - 1];
|
|
1804
1731
|
if (lastName && typeof lastName === 'object' && 'String' in lastName && lastName.String && lastName.String.str) {
|
|
@@ -1808,7 +1735,7 @@ export class V13ToV14Transformer {
|
|
|
1808
1735
|
const isVariadic = this.isVariadicParameterType(arg, index, result.objargs, context);
|
|
1809
1736
|
paramName = this.extractParameterNameFromFunctionName(functionName, index, isVariadic);
|
|
1810
1737
|
}
|
|
1811
|
-
const parameter
|
|
1738
|
+
const parameter = {
|
|
1812
1739
|
FunctionParameter: {
|
|
1813
1740
|
argType: transformedArgType.TypeName || transformedArgType,
|
|
1814
1741
|
mode: mode
|
|
@@ -1839,7 +1766,7 @@ export class V13ToV14Transformer {
|
|
|
1839
1766
|
else if (result.objfuncargs !== undefined) {
|
|
1840
1767
|
if (shouldPreserveObjfuncargs) {
|
|
1841
1768
|
result.objfuncargs = Array.isArray(result.objfuncargs)
|
|
1842
|
-
? result.objfuncargs.map((item
|
|
1769
|
+
? result.objfuncargs.map((item) => this.transform(item, context))
|
|
1843
1770
|
: [this.transform(result.objfuncargs, context)];
|
|
1844
1771
|
}
|
|
1845
1772
|
else {
|
|
@@ -1851,7 +1778,7 @@ export class V13ToV14Transformer {
|
|
|
1851
1778
|
}
|
|
1852
1779
|
return { ObjectWithArgs: result };
|
|
1853
1780
|
}
|
|
1854
|
-
|
|
1781
|
+
shouldCreateObjfuncargs(context) {
|
|
1855
1782
|
if (!context.parentNodeTypes || context.parentNodeTypes.length === 0) {
|
|
1856
1783
|
return false;
|
|
1857
1784
|
}
|
|
@@ -1862,7 +1789,7 @@ export class V13ToV14Transformer {
|
|
|
1862
1789
|
}
|
|
1863
1790
|
return false;
|
|
1864
1791
|
}
|
|
1865
|
-
|
|
1792
|
+
shouldPreserveObjfuncargs(context) {
|
|
1866
1793
|
if (!context.parentNodeTypes || context.parentNodeTypes.length === 0) {
|
|
1867
1794
|
return false;
|
|
1868
1795
|
}
|
|
@@ -1907,25 +1834,25 @@ export class V13ToV14Transformer {
|
|
|
1907
1834
|
}
|
|
1908
1835
|
return false;
|
|
1909
1836
|
}
|
|
1910
|
-
|
|
1837
|
+
shouldCreateObjfuncargsFromObjargs(context) {
|
|
1911
1838
|
if (!context.parentNodeTypes || context.parentNodeTypes.length === 0) {
|
|
1912
1839
|
return false;
|
|
1913
1840
|
}
|
|
1914
|
-
if (
|
|
1841
|
+
if (context.commentObjtype === 'OBJECT_OPERATOR' &&
|
|
1915
1842
|
context.parentNodeTypes.includes('CommentStmt')) {
|
|
1916
1843
|
return false;
|
|
1917
1844
|
}
|
|
1918
1845
|
// Check if this is an operator context - operators should NOT get objfuncargs
|
|
1919
1846
|
const path = context.path || [];
|
|
1920
1847
|
// Check if we're in any statement with OBJECT_OPERATOR
|
|
1921
|
-
if (
|
|
1922
|
-
|
|
1923
|
-
|
|
1848
|
+
if (context.alterOwnerObjectType === 'OBJECT_OPERATOR' ||
|
|
1849
|
+
context.alterObjectSchemaObjectType === 'OBJECT_OPERATOR' ||
|
|
1850
|
+
context.renameObjectType === 'OBJECT_OPERATOR') {
|
|
1924
1851
|
return false;
|
|
1925
1852
|
}
|
|
1926
1853
|
for (const node of path) {
|
|
1927
1854
|
if (node && typeof node === 'object') {
|
|
1928
|
-
const nodeData = Object.values(node)[0]
|
|
1855
|
+
const nodeData = Object.values(node)[0];
|
|
1929
1856
|
if (nodeData && (nodeData.objtype === 'OBJECT_OPERATOR' ||
|
|
1930
1857
|
nodeData.objectType === 'OBJECT_OPERATOR' ||
|
|
1931
1858
|
nodeData.renameType === 'OBJECT_OPERATOR')) {
|
|
@@ -1933,7 +1860,7 @@ export class V13ToV14Transformer {
|
|
|
1933
1860
|
}
|
|
1934
1861
|
if (nodeData && nodeData.objname && Array.isArray(nodeData.objname)) {
|
|
1935
1862
|
// Check if objname contains operator symbols - but only if it's actually an operator context
|
|
1936
|
-
const objnameStr = nodeData.objname.map((item
|
|
1863
|
+
const objnameStr = nodeData.objname.map((item) => {
|
|
1937
1864
|
if (item && typeof item === 'object' && item.String && item.String.str) {
|
|
1938
1865
|
return item.String.str;
|
|
1939
1866
|
}
|
|
@@ -1990,7 +1917,7 @@ export class V13ToV14Transformer {
|
|
|
1990
1917
|
}
|
|
1991
1918
|
return false;
|
|
1992
1919
|
}
|
|
1993
|
-
|
|
1920
|
+
shouldAddObjfuncargsForDropStmt(context) {
|
|
1994
1921
|
const path = context.path || [];
|
|
1995
1922
|
for (const node of path) {
|
|
1996
1923
|
if (node && typeof node === 'object' && 'DropStmt' in node) {
|
|
@@ -2007,8 +1934,8 @@ export class V13ToV14Transformer {
|
|
|
2007
1934
|
}
|
|
2008
1935
|
}
|
|
2009
1936
|
}
|
|
2010
|
-
if (
|
|
2011
|
-
const removeType =
|
|
1937
|
+
if (context.dropRemoveType) {
|
|
1938
|
+
const removeType = context.dropRemoveType;
|
|
2012
1939
|
if (removeType === 'OBJECT_OPERATOR') {
|
|
2013
1940
|
return false;
|
|
2014
1941
|
}
|
|
@@ -2022,7 +1949,7 @@ export class V13ToV14Transformer {
|
|
|
2022
1949
|
}
|
|
2023
1950
|
return false;
|
|
2024
1951
|
}
|
|
2025
|
-
|
|
1952
|
+
shouldPreserveObjnameAsObject(context) {
|
|
2026
1953
|
if (!context.parentNodeTypes || context.parentNodeTypes.length === 0) {
|
|
2027
1954
|
return false; // Default to converting to arrays for PG14
|
|
2028
1955
|
}
|
|
@@ -2037,13 +1964,13 @@ export class V13ToV14Transformer {
|
|
|
2037
1964
|
}
|
|
2038
1965
|
return true; // Preserve as object for other contexts
|
|
2039
1966
|
}
|
|
2040
|
-
|
|
1967
|
+
createFunctionParameterFromTypeName(typeNameNode, context, index = 0) {
|
|
2041
1968
|
const transformedTypeName = this.transform(typeNameNode, context || { parentNodeTypes: [] });
|
|
2042
1969
|
const argType = transformedTypeName.TypeName ? transformedTypeName.TypeName : transformedTypeName;
|
|
2043
1970
|
// Check if this should be a variadic parameter
|
|
2044
1971
|
const isVariadic = this.isVariadicParameterType(typeNameNode, index, undefined, context);
|
|
2045
1972
|
let mode = isVariadic ? "FUNC_PARAM_VARIADIC" : "FUNC_PARAM_DEFAULT";
|
|
2046
|
-
const functionParam
|
|
1973
|
+
const functionParam = {
|
|
2047
1974
|
argType: argType,
|
|
2048
1975
|
mode: mode
|
|
2049
1976
|
};
|
|
@@ -2058,7 +1985,7 @@ export class V13ToV14Transformer {
|
|
|
2058
1985
|
FunctionParameter: functionParam
|
|
2059
1986
|
};
|
|
2060
1987
|
}
|
|
2061
|
-
|
|
1988
|
+
isVariadicAggregateContext(context) {
|
|
2062
1989
|
let parent = context.parent;
|
|
2063
1990
|
while (parent) {
|
|
2064
1991
|
if (parent.currentNode && typeof parent.currentNode === 'object') {
|
|
@@ -2075,10 +2002,8 @@ export class V13ToV14Transformer {
|
|
|
2075
2002
|
}
|
|
2076
2003
|
return false;
|
|
2077
2004
|
}
|
|
2078
|
-
|
|
2079
|
-
const pg13ToP14Map
|
|
2080
|
-
[key: string]: string;
|
|
2081
|
-
} = {
|
|
2005
|
+
transformA_Expr_Kind(kind) {
|
|
2006
|
+
const pg13ToP14Map = {
|
|
2082
2007
|
'AEXPR_OP': 'AEXPR_OP',
|
|
2083
2008
|
'AEXPR_OP_ANY': 'AEXPR_OP_ANY',
|
|
2084
2009
|
'AEXPR_OP_ALL': 'AEXPR_OP_ALL',
|
|
@@ -2098,10 +2023,8 @@ export class V13ToV14Transformer {
|
|
|
2098
2023
|
};
|
|
2099
2024
|
return pg13ToP14Map[kind] || kind;
|
|
2100
2025
|
}
|
|
2101
|
-
|
|
2102
|
-
const pg13ToP14Map
|
|
2103
|
-
[key: string]: string;
|
|
2104
|
-
} = {
|
|
2026
|
+
transformRoleSpecType(type) {
|
|
2027
|
+
const pg13ToP14Map = {
|
|
2105
2028
|
'ROLESPEC_CSTRING': 'ROLESPEC_CSTRING',
|
|
2106
2029
|
'ROLESPEC_CURRENT_USER': 'ROLESPEC_CURRENT_USER',
|
|
2107
2030
|
'ROLESPEC_SESSION_USER': 'ROLESPEC_SESSION_USER',
|
|
@@ -2109,7 +2032,7 @@ export class V13ToV14Transformer {
|
|
|
2109
2032
|
};
|
|
2110
2033
|
return pg13ToP14Map[type] || type;
|
|
2111
2034
|
}
|
|
2112
|
-
|
|
2035
|
+
isVariadicParameterContext(context) {
|
|
2113
2036
|
if (!context.parentNodeTypes || context.parentNodeTypes.length === 0) {
|
|
2114
2037
|
return false;
|
|
2115
2038
|
}
|
|
@@ -2121,7 +2044,7 @@ export class V13ToV14Transformer {
|
|
|
2121
2044
|
}
|
|
2122
2045
|
return false;
|
|
2123
2046
|
}
|
|
2124
|
-
|
|
2047
|
+
isCreateFunctionContext(context) {
|
|
2125
2048
|
if (!context.parentNodeTypes || context.parentNodeTypes.length === 0) {
|
|
2126
2049
|
return false;
|
|
2127
2050
|
}
|
|
@@ -2132,51 +2055,37 @@ export class V13ToV14Transformer {
|
|
|
2132
2055
|
}
|
|
2133
2056
|
return false;
|
|
2134
2057
|
}
|
|
2135
|
-
String(node
|
|
2136
|
-
|
|
2137
|
-
} {
|
|
2138
|
-
const result: any = { ...node };
|
|
2058
|
+
String(node, context) {
|
|
2059
|
+
const result = { ...node };
|
|
2139
2060
|
return { String: result };
|
|
2140
2061
|
}
|
|
2141
|
-
BitString(node
|
|
2142
|
-
|
|
2143
|
-
} {
|
|
2144
|
-
const result: any = { ...node };
|
|
2062
|
+
BitString(node, context) {
|
|
2063
|
+
const result = { ...node };
|
|
2145
2064
|
return { BitString: result };
|
|
2146
2065
|
}
|
|
2147
|
-
Float(node
|
|
2148
|
-
|
|
2149
|
-
} {
|
|
2150
|
-
const result: any = { ...node };
|
|
2066
|
+
Float(node, context) {
|
|
2067
|
+
const result = { ...node };
|
|
2151
2068
|
return { Float: result };
|
|
2152
2069
|
}
|
|
2153
|
-
Integer(node
|
|
2154
|
-
|
|
2155
|
-
} {
|
|
2156
|
-
const result: any = { ...node };
|
|
2070
|
+
Integer(node, context) {
|
|
2071
|
+
const result = { ...node };
|
|
2157
2072
|
return { Integer: result };
|
|
2158
2073
|
}
|
|
2159
|
-
Null(node
|
|
2160
|
-
|
|
2161
|
-
} {
|
|
2162
|
-
const result: any = { ...node };
|
|
2074
|
+
Null(node, context) {
|
|
2075
|
+
const result = { ...node };
|
|
2163
2076
|
return { Null: result };
|
|
2164
2077
|
}
|
|
2165
|
-
List(node
|
|
2166
|
-
|
|
2167
|
-
} {
|
|
2168
|
-
const result: any = {};
|
|
2078
|
+
List(node, context) {
|
|
2079
|
+
const result = {};
|
|
2169
2080
|
if (node.items !== undefined) {
|
|
2170
2081
|
result.items = Array.isArray(node.items)
|
|
2171
|
-
? node.items.map((item
|
|
2172
|
-
: this.transform(node.items
|
|
2082
|
+
? node.items.map((item) => this.transform(item, context))
|
|
2083
|
+
: this.transform(node.items, context);
|
|
2173
2084
|
}
|
|
2174
2085
|
return { List: result };
|
|
2175
2086
|
}
|
|
2176
|
-
A_Expr(node
|
|
2177
|
-
|
|
2178
|
-
} {
|
|
2179
|
-
const result: any = {};
|
|
2087
|
+
A_Expr(node, context) {
|
|
2088
|
+
const result = {};
|
|
2180
2089
|
if (node.kind !== undefined) {
|
|
2181
2090
|
if (node.kind === "AEXPR_OF") {
|
|
2182
2091
|
result.kind = "AEXPR_IN";
|
|
@@ -2190,14 +2099,14 @@ export class V13ToV14Transformer {
|
|
|
2190
2099
|
}
|
|
2191
2100
|
if (node.name !== undefined) {
|
|
2192
2101
|
result.name = Array.isArray(node.name)
|
|
2193
|
-
? node.name.map((item
|
|
2194
|
-
: this.transform(node.name
|
|
2102
|
+
? node.name.map((item) => this.transform(item, context))
|
|
2103
|
+
: this.transform(node.name, context);
|
|
2195
2104
|
}
|
|
2196
2105
|
if (node.lexpr !== undefined) {
|
|
2197
|
-
result.lexpr = this.transform(node.lexpr
|
|
2106
|
+
result.lexpr = this.transform(node.lexpr, context);
|
|
2198
2107
|
}
|
|
2199
2108
|
if (node.rexpr !== undefined) {
|
|
2200
|
-
result.rexpr = this.transform(node.rexpr
|
|
2109
|
+
result.rexpr = this.transform(node.rexpr, context);
|
|
2201
2110
|
}
|
|
2202
2111
|
if (node.location !== undefined) {
|
|
2203
2112
|
result.location = node.location;
|
|
@@ -2207,10 +2116,8 @@ export class V13ToV14Transformer {
|
|
|
2207
2116
|
}
|
|
2208
2117
|
return { A_Expr: result };
|
|
2209
2118
|
}
|
|
2210
|
-
RoleSpec(node
|
|
2211
|
-
|
|
2212
|
-
} {
|
|
2213
|
-
const result: any = {};
|
|
2119
|
+
RoleSpec(node, context) {
|
|
2120
|
+
const result = {};
|
|
2214
2121
|
if (node.roletype !== undefined) {
|
|
2215
2122
|
result.roletype = this.transformRoleSpecType(node.roletype);
|
|
2216
2123
|
}
|
|
@@ -2222,10 +2129,8 @@ export class V13ToV14Transformer {
|
|
|
2222
2129
|
}
|
|
2223
2130
|
return { RoleSpec: result };
|
|
2224
2131
|
}
|
|
2225
|
-
AlterTableCmd(node
|
|
2226
|
-
|
|
2227
|
-
} {
|
|
2228
|
-
const result: any = {};
|
|
2132
|
+
AlterTableCmd(node, context) {
|
|
2133
|
+
const result = {};
|
|
2229
2134
|
if (node.subtype !== undefined) {
|
|
2230
2135
|
result.subtype = node.subtype;
|
|
2231
2136
|
}
|
|
@@ -2236,10 +2141,10 @@ export class V13ToV14Transformer {
|
|
|
2236
2141
|
result.num = node.num;
|
|
2237
2142
|
}
|
|
2238
2143
|
if (node.newowner !== undefined) {
|
|
2239
|
-
result.newowner = this.transform(node.newowner
|
|
2144
|
+
result.newowner = this.transform(node.newowner, context);
|
|
2240
2145
|
}
|
|
2241
2146
|
if (node.def !== undefined) {
|
|
2242
|
-
result.def = this.transform(node.def
|
|
2147
|
+
result.def = this.transform(node.def, context);
|
|
2243
2148
|
}
|
|
2244
2149
|
if (node.behavior !== undefined) {
|
|
2245
2150
|
result.behavior = node.behavior;
|
|
@@ -2249,14 +2154,12 @@ export class V13ToV14Transformer {
|
|
|
2249
2154
|
}
|
|
2250
2155
|
return { AlterTableCmd: result };
|
|
2251
2156
|
}
|
|
2252
|
-
TypeName(node
|
|
2253
|
-
|
|
2254
|
-
} {
|
|
2255
|
-
const result: any = {};
|
|
2157
|
+
TypeName(node, context) {
|
|
2158
|
+
const result = {};
|
|
2256
2159
|
if (node.names !== undefined) {
|
|
2257
2160
|
result.names = Array.isArray(node.names)
|
|
2258
|
-
? node.names.map((item
|
|
2259
|
-
: this.transform(node.names
|
|
2161
|
+
? node.names.map((item) => this.transform(item, context))
|
|
2162
|
+
: this.transform(node.names, context);
|
|
2260
2163
|
}
|
|
2261
2164
|
if (node.typeOid !== undefined) {
|
|
2262
2165
|
result.typeOid = node.typeOid;
|
|
@@ -2269,60 +2172,52 @@ export class V13ToV14Transformer {
|
|
|
2269
2172
|
}
|
|
2270
2173
|
if (node.typmods !== undefined) {
|
|
2271
2174
|
result.typmods = Array.isArray(node.typmods)
|
|
2272
|
-
? node.typmods.map((item
|
|
2273
|
-
: this.transform(node.typmods
|
|
2175
|
+
? node.typmods.map((item) => this.transform(item, context))
|
|
2176
|
+
: this.transform(node.typmods, context);
|
|
2274
2177
|
}
|
|
2275
2178
|
if (node.typemod !== undefined) {
|
|
2276
2179
|
result.typemod = node.typemod;
|
|
2277
2180
|
}
|
|
2278
2181
|
if (node.arrayBounds !== undefined) {
|
|
2279
2182
|
result.arrayBounds = Array.isArray(node.arrayBounds)
|
|
2280
|
-
? node.arrayBounds.map((item
|
|
2281
|
-
: this.transform(node.arrayBounds
|
|
2183
|
+
? node.arrayBounds.map((item) => this.transform(item, context))
|
|
2184
|
+
: this.transform(node.arrayBounds, context);
|
|
2282
2185
|
}
|
|
2283
2186
|
if (node.location !== undefined) {
|
|
2284
2187
|
result.location = node.location;
|
|
2285
2188
|
}
|
|
2286
2189
|
return { TypeName: result };
|
|
2287
2190
|
}
|
|
2288
|
-
ColumnRef(node
|
|
2289
|
-
|
|
2290
|
-
} {
|
|
2291
|
-
const result: any = {};
|
|
2191
|
+
ColumnRef(node, context) {
|
|
2192
|
+
const result = {};
|
|
2292
2193
|
if (node.fields !== undefined) {
|
|
2293
2194
|
result.fields = Array.isArray(node.fields)
|
|
2294
|
-
? node.fields.map((item
|
|
2295
|
-
: this.transform(node.fields
|
|
2195
|
+
? node.fields.map((item) => this.transform(item, context))
|
|
2196
|
+
: this.transform(node.fields, context);
|
|
2296
2197
|
}
|
|
2297
2198
|
if (node.location !== undefined) {
|
|
2298
2199
|
result.location = node.location;
|
|
2299
2200
|
}
|
|
2300
2201
|
return { ColumnRef: result };
|
|
2301
2202
|
}
|
|
2302
|
-
A_Const(node
|
|
2303
|
-
|
|
2304
|
-
} {
|
|
2305
|
-
const result: any = {};
|
|
2203
|
+
A_Const(node, context) {
|
|
2204
|
+
const result = {};
|
|
2306
2205
|
if (node.val !== undefined) {
|
|
2307
|
-
result.val = this.transform(node.val
|
|
2206
|
+
result.val = this.transform(node.val, context);
|
|
2308
2207
|
}
|
|
2309
2208
|
if (node.location !== undefined) {
|
|
2310
2209
|
result.location = node.location;
|
|
2311
2210
|
}
|
|
2312
2211
|
return { A_Const: result };
|
|
2313
2212
|
}
|
|
2314
|
-
A_Star(node
|
|
2315
|
-
|
|
2316
|
-
} {
|
|
2317
|
-
const result: any = { ...node };
|
|
2213
|
+
A_Star(node, context) {
|
|
2214
|
+
const result = { ...node };
|
|
2318
2215
|
return { A_Star: result };
|
|
2319
2216
|
}
|
|
2320
|
-
SortBy(node
|
|
2321
|
-
|
|
2322
|
-
} {
|
|
2323
|
-
const result: any = {};
|
|
2217
|
+
SortBy(node, context) {
|
|
2218
|
+
const result = {};
|
|
2324
2219
|
if (node.node !== undefined) {
|
|
2325
|
-
result.node = this.transform(node.node
|
|
2220
|
+
result.node = this.transform(node.node, context);
|
|
2326
2221
|
}
|
|
2327
2222
|
if (node.sortby_dir !== undefined) {
|
|
2328
2223
|
result.sortby_dir = node.sortby_dir;
|
|
@@ -2332,52 +2227,48 @@ export class V13ToV14Transformer {
|
|
|
2332
2227
|
}
|
|
2333
2228
|
if (node.useOp !== undefined) {
|
|
2334
2229
|
result.useOp = Array.isArray(node.useOp)
|
|
2335
|
-
? node.useOp.map((item
|
|
2336
|
-
: this.transform(node.useOp
|
|
2230
|
+
? node.useOp.map((item) => this.transform(item, context))
|
|
2231
|
+
: this.transform(node.useOp, context);
|
|
2337
2232
|
}
|
|
2338
2233
|
if (node.location !== undefined) {
|
|
2339
2234
|
result.location = node.location;
|
|
2340
2235
|
}
|
|
2341
2236
|
return { SortBy: result };
|
|
2342
2237
|
}
|
|
2343
|
-
CreateDomainStmt(node
|
|
2344
|
-
|
|
2345
|
-
} {
|
|
2346
|
-
const result: any = {};
|
|
2238
|
+
CreateDomainStmt(node, context) {
|
|
2239
|
+
const result = {};
|
|
2347
2240
|
// Create child context with CreateDomainStmt as parent
|
|
2348
|
-
const childContext
|
|
2241
|
+
const childContext = {
|
|
2349
2242
|
...context,
|
|
2350
2243
|
parentNodeTypes: [...(context.parentNodeTypes || []), 'CreateDomainStmt']
|
|
2351
2244
|
};
|
|
2352
2245
|
if (node.domainname !== undefined) {
|
|
2353
2246
|
result.domainname = Array.isArray(node.domainname)
|
|
2354
|
-
? node.domainname.map((item
|
|
2355
|
-
: this.transform(node.domainname
|
|
2247
|
+
? node.domainname.map((item) => this.transform(item, context))
|
|
2248
|
+
: this.transform(node.domainname, context);
|
|
2356
2249
|
}
|
|
2357
2250
|
if (node.typeName !== undefined) {
|
|
2358
|
-
result.typeName = this.transform(node.typeName
|
|
2251
|
+
result.typeName = this.transform(node.typeName, context);
|
|
2359
2252
|
}
|
|
2360
2253
|
if (node.collClause !== undefined) {
|
|
2361
|
-
result.collClause = this.transform(node.collClause
|
|
2254
|
+
result.collClause = this.transform(node.collClause, context);
|
|
2362
2255
|
}
|
|
2363
2256
|
if (node.constraints !== undefined) {
|
|
2364
2257
|
result.constraints = Array.isArray(node.constraints)
|
|
2365
|
-
? node.constraints.map((item
|
|
2366
|
-
: this.transform(node.constraints
|
|
2258
|
+
? node.constraints.map((item) => this.transform(item, childContext))
|
|
2259
|
+
: this.transform(node.constraints, childContext);
|
|
2367
2260
|
}
|
|
2368
2261
|
return { CreateDomainStmt: result };
|
|
2369
2262
|
}
|
|
2370
|
-
CreateSeqStmt(node
|
|
2371
|
-
|
|
2372
|
-
} {
|
|
2373
|
-
const result: any = {};
|
|
2263
|
+
CreateSeqStmt(node, context) {
|
|
2264
|
+
const result = {};
|
|
2374
2265
|
if (node.sequence !== undefined) {
|
|
2375
|
-
result.sequence = this.transform(node.sequence
|
|
2266
|
+
result.sequence = this.transform(node.sequence, context);
|
|
2376
2267
|
}
|
|
2377
2268
|
if (node.options !== undefined) {
|
|
2378
2269
|
result.options = Array.isArray(node.options)
|
|
2379
|
-
? node.options.map((item
|
|
2380
|
-
: this.transform(node.options
|
|
2270
|
+
? node.options.map((item) => this.transform(item, context))
|
|
2271
|
+
: this.transform(node.options, context);
|
|
2381
2272
|
}
|
|
2382
2273
|
if (node.ownerId !== undefined) {
|
|
2383
2274
|
result.ownerId = node.ownerId;
|
|
@@ -2390,16 +2281,14 @@ export class V13ToV14Transformer {
|
|
|
2390
2281
|
}
|
|
2391
2282
|
return { CreateSeqStmt: result };
|
|
2392
2283
|
}
|
|
2393
|
-
WithClause(node
|
|
2394
|
-
WithClause: any;
|
|
2395
|
-
} {
|
|
2284
|
+
WithClause(node, context) {
|
|
2396
2285
|
console.log('WithClause called with:', {
|
|
2397
2286
|
ctes: node.ctes,
|
|
2398
2287
|
ctesType: typeof node.ctes,
|
|
2399
2288
|
isArray: Array.isArray(node.ctes),
|
|
2400
2289
|
keys: node.ctes ? Object.keys(node.ctes) : null
|
|
2401
2290
|
});
|
|
2402
|
-
const result
|
|
2291
|
+
const result = { ...node };
|
|
2403
2292
|
if (node.ctes !== undefined) {
|
|
2404
2293
|
const shouldConvertToArray = this.shouldConvertCTEsToArray(context);
|
|
2405
2294
|
console.log('shouldConvertToArray:', shouldConvertToArray);
|
|
@@ -2408,26 +2297,26 @@ export class V13ToV14Transformer {
|
|
|
2408
2297
|
if (shouldConvertToArray) {
|
|
2409
2298
|
const cteArray = Object.keys(node.ctes)
|
|
2410
2299
|
.sort((a, b) => parseInt(a) - parseInt(b))
|
|
2411
|
-
.map(key => this.transform(
|
|
2300
|
+
.map(key => this.transform(node.ctes[key], context));
|
|
2412
2301
|
console.log('Converted to array:', cteArray);
|
|
2413
2302
|
result.ctes = cteArray;
|
|
2414
2303
|
}
|
|
2415
2304
|
else {
|
|
2416
2305
|
console.log('Keeping as object');
|
|
2417
|
-
const transformedCtes
|
|
2306
|
+
const transformedCtes = {};
|
|
2418
2307
|
Object.keys(node.ctes).forEach(key => {
|
|
2419
|
-
transformedCtes[key] = this.transform(
|
|
2308
|
+
transformedCtes[key] = this.transform(node.ctes[key], context);
|
|
2420
2309
|
});
|
|
2421
2310
|
result.ctes = transformedCtes;
|
|
2422
2311
|
}
|
|
2423
2312
|
}
|
|
2424
2313
|
else if (Array.isArray(node.ctes)) {
|
|
2425
2314
|
console.log('Input is already array, transforming items');
|
|
2426
|
-
result.ctes = node.ctes.map(item => this.transform(item
|
|
2315
|
+
result.ctes = node.ctes.map(item => this.transform(item, context));
|
|
2427
2316
|
}
|
|
2428
2317
|
else {
|
|
2429
2318
|
console.log('Input is neither object nor array, transforming directly');
|
|
2430
|
-
result.ctes = this.transform(node.ctes
|
|
2319
|
+
result.ctes = this.transform(node.ctes, context);
|
|
2431
2320
|
}
|
|
2432
2321
|
}
|
|
2433
2322
|
if (node.recursive !== undefined) {
|
|
@@ -2438,20 +2327,18 @@ export class V13ToV14Transformer {
|
|
|
2438
2327
|
}
|
|
2439
2328
|
return { WithClause: result };
|
|
2440
2329
|
}
|
|
2441
|
-
|
|
2330
|
+
shouldConvertCTEsToArray(context) {
|
|
2442
2331
|
return true;
|
|
2443
2332
|
}
|
|
2444
|
-
AlterSeqStmt(node
|
|
2445
|
-
|
|
2446
|
-
} {
|
|
2447
|
-
const result: any = {};
|
|
2333
|
+
AlterSeqStmt(node, context) {
|
|
2334
|
+
const result = {};
|
|
2448
2335
|
if (node.sequence !== undefined) {
|
|
2449
|
-
result.sequence = this.transform(node.sequence
|
|
2336
|
+
result.sequence = this.transform(node.sequence, context);
|
|
2450
2337
|
}
|
|
2451
2338
|
if (node.options !== undefined) {
|
|
2452
2339
|
result.options = Array.isArray(node.options)
|
|
2453
|
-
? node.options.map((item
|
|
2454
|
-
: this.transform(node.options
|
|
2340
|
+
? node.options.map((item) => this.transform(item, context))
|
|
2341
|
+
: this.transform(node.options, context);
|
|
2455
2342
|
}
|
|
2456
2343
|
if (node.for_identity !== undefined) {
|
|
2457
2344
|
result.for_identity = node.for_identity;
|
|
@@ -2461,23 +2348,21 @@ export class V13ToV14Transformer {
|
|
|
2461
2348
|
}
|
|
2462
2349
|
return { AlterSeqStmt: result };
|
|
2463
2350
|
}
|
|
2464
|
-
CTECycleClause(node
|
|
2465
|
-
|
|
2466
|
-
} {
|
|
2467
|
-
const result: any = {};
|
|
2351
|
+
CTECycleClause(node, context) {
|
|
2352
|
+
const result = {};
|
|
2468
2353
|
if (node.cycle_col_list !== undefined) {
|
|
2469
2354
|
result.cycle_col_list = Array.isArray(node.cycle_col_list)
|
|
2470
|
-
? node.cycle_col_list.map((item
|
|
2471
|
-
: this.transform(node.cycle_col_list
|
|
2355
|
+
? node.cycle_col_list.map((item) => this.transform(item, context))
|
|
2356
|
+
: this.transform(node.cycle_col_list, context);
|
|
2472
2357
|
}
|
|
2473
2358
|
if (node.cycle_mark_column !== undefined) {
|
|
2474
2359
|
result.cycle_mark_column = node.cycle_mark_column;
|
|
2475
2360
|
}
|
|
2476
2361
|
if (node.cycle_mark_value !== undefined) {
|
|
2477
|
-
result.cycle_mark_value = this.transform(node.cycle_mark_value
|
|
2362
|
+
result.cycle_mark_value = this.transform(node.cycle_mark_value, context);
|
|
2478
2363
|
}
|
|
2479
2364
|
if (node.cycle_mark_default !== undefined) {
|
|
2480
|
-
result.cycle_mark_default = this.transform(node.cycle_mark_default
|
|
2365
|
+
result.cycle_mark_default = this.transform(node.cycle_mark_default, context);
|
|
2481
2366
|
}
|
|
2482
2367
|
if (node.cycle_path_column !== undefined) {
|
|
2483
2368
|
result.cycle_path_column = node.cycle_path_column;
|
|
@@ -2487,14 +2372,12 @@ export class V13ToV14Transformer {
|
|
|
2487
2372
|
}
|
|
2488
2373
|
return { CTECycleClause: result };
|
|
2489
2374
|
}
|
|
2490
|
-
CTESearchClause(node
|
|
2491
|
-
|
|
2492
|
-
} {
|
|
2493
|
-
const result: any = {};
|
|
2375
|
+
CTESearchClause(node, context) {
|
|
2376
|
+
const result = {};
|
|
2494
2377
|
if (node.search_col_list !== undefined) {
|
|
2495
2378
|
result.search_col_list = Array.isArray(node.search_col_list)
|
|
2496
|
-
? node.search_col_list.map((item
|
|
2497
|
-
: this.transform(node.search_col_list
|
|
2379
|
+
? node.search_col_list.map((item) => this.transform(item, context))
|
|
2380
|
+
: this.transform(node.search_col_list, context);
|
|
2498
2381
|
}
|
|
2499
2382
|
if (node.search_breadth_first !== undefined) {
|
|
2500
2383
|
result.search_breadth_first = node.search_breadth_first;
|
|
@@ -2507,67 +2390,59 @@ export class V13ToV14Transformer {
|
|
|
2507
2390
|
}
|
|
2508
2391
|
return { CTESearchClause: result };
|
|
2509
2392
|
}
|
|
2510
|
-
PLAssignStmt(node
|
|
2511
|
-
|
|
2512
|
-
} {
|
|
2513
|
-
const result: any = {};
|
|
2393
|
+
PLAssignStmt(node, context) {
|
|
2394
|
+
const result = {};
|
|
2514
2395
|
if (node.name !== undefined) {
|
|
2515
2396
|
result.name = node.name;
|
|
2516
2397
|
}
|
|
2517
2398
|
if (node.indirection !== undefined) {
|
|
2518
2399
|
result.indirection = Array.isArray(node.indirection)
|
|
2519
|
-
? node.indirection.map((item
|
|
2520
|
-
: this.transform(node.indirection
|
|
2400
|
+
? node.indirection.map((item) => this.transform(item, context))
|
|
2401
|
+
: this.transform(node.indirection, context);
|
|
2521
2402
|
}
|
|
2522
2403
|
if (node.nnames !== undefined) {
|
|
2523
2404
|
result.nnames = node.nnames;
|
|
2524
2405
|
}
|
|
2525
2406
|
if (node.val !== undefined) {
|
|
2526
|
-
result.val = this.transform(node.val
|
|
2407
|
+
result.val = this.transform(node.val, context);
|
|
2527
2408
|
}
|
|
2528
2409
|
if (node.location !== undefined) {
|
|
2529
2410
|
result.location = node.location;
|
|
2530
2411
|
}
|
|
2531
2412
|
return { PLAssignStmt: result };
|
|
2532
2413
|
}
|
|
2533
|
-
ReturnStmt(node
|
|
2534
|
-
|
|
2535
|
-
} {
|
|
2536
|
-
const result: any = {};
|
|
2414
|
+
ReturnStmt(node, context) {
|
|
2415
|
+
const result = {};
|
|
2537
2416
|
if (node.returnval !== undefined) {
|
|
2538
|
-
result.returnval = this.transform(node.returnval
|
|
2417
|
+
result.returnval = this.transform(node.returnval, context);
|
|
2539
2418
|
}
|
|
2540
2419
|
return { ReturnStmt: result };
|
|
2541
2420
|
}
|
|
2542
|
-
StatsElem(node
|
|
2543
|
-
|
|
2544
|
-
} {
|
|
2545
|
-
const result: any = {};
|
|
2421
|
+
StatsElem(node, context) {
|
|
2422
|
+
const result = {};
|
|
2546
2423
|
if (node.name !== undefined) {
|
|
2547
2424
|
result.name = node.name;
|
|
2548
2425
|
}
|
|
2549
2426
|
if (node.expr !== undefined) {
|
|
2550
|
-
result.expr = this.transform(node.expr
|
|
2427
|
+
result.expr = this.transform(node.expr, context);
|
|
2551
2428
|
}
|
|
2552
2429
|
return { StatsElem: result };
|
|
2553
2430
|
}
|
|
2554
|
-
CreateStatsStmt(node
|
|
2555
|
-
|
|
2556
|
-
} {
|
|
2557
|
-
const result: any = {};
|
|
2431
|
+
CreateStatsStmt(node, context) {
|
|
2432
|
+
const result = {};
|
|
2558
2433
|
if (node.defnames !== undefined) {
|
|
2559
2434
|
result.defnames = Array.isArray(node.defnames)
|
|
2560
|
-
? node.defnames.map((item
|
|
2561
|
-
: this.transform(node.defnames
|
|
2435
|
+
? node.defnames.map((item) => this.transform(item, context))
|
|
2436
|
+
: this.transform(node.defnames, context);
|
|
2562
2437
|
}
|
|
2563
2438
|
if (node.stat_types !== undefined) {
|
|
2564
2439
|
result.stat_types = Array.isArray(node.stat_types)
|
|
2565
|
-
? node.stat_types.map((item
|
|
2566
|
-
: this.transform(node.stat_types
|
|
2440
|
+
? node.stat_types.map((item) => this.transform(item, context))
|
|
2441
|
+
: this.transform(node.stat_types, context);
|
|
2567
2442
|
}
|
|
2568
2443
|
if (node.exprs !== undefined) {
|
|
2569
2444
|
result.exprs = Array.isArray(node.exprs)
|
|
2570
|
-
? node.exprs.map((item
|
|
2445
|
+
? node.exprs.map((item) => {
|
|
2571
2446
|
// Check if this is a simple column reference
|
|
2572
2447
|
if (item && item.ColumnRef && item.ColumnRef.fields &&
|
|
2573
2448
|
Array.isArray(item.ColumnRef.fields) && item.ColumnRef.fields.length === 1 &&
|
|
@@ -2579,7 +2454,7 @@ export class V13ToV14Transformer {
|
|
|
2579
2454
|
};
|
|
2580
2455
|
}
|
|
2581
2456
|
else {
|
|
2582
|
-
const transformedExpr = this.transform(item
|
|
2457
|
+
const transformedExpr = this.transform(item, context);
|
|
2583
2458
|
return {
|
|
2584
2459
|
StatsElem: {
|
|
2585
2460
|
expr: transformedExpr
|
|
@@ -2599,7 +2474,7 @@ export class V13ToV14Transformer {
|
|
|
2599
2474
|
};
|
|
2600
2475
|
}
|
|
2601
2476
|
else {
|
|
2602
|
-
const transformedExpr = this.transform(node.exprs
|
|
2477
|
+
const transformedExpr = this.transform(node.exprs, context);
|
|
2603
2478
|
return {
|
|
2604
2479
|
StatsElem: {
|
|
2605
2480
|
expr: transformedExpr
|
|
@@ -2610,8 +2485,8 @@ export class V13ToV14Transformer {
|
|
|
2610
2485
|
}
|
|
2611
2486
|
if (node.relations !== undefined) {
|
|
2612
2487
|
result.relations = Array.isArray(node.relations)
|
|
2613
|
-
? node.relations.map((item
|
|
2614
|
-
: this.transform(node.relations
|
|
2488
|
+
? node.relations.map((item) => this.transform(item, context))
|
|
2489
|
+
: this.transform(node.relations, context);
|
|
2615
2490
|
}
|
|
2616
2491
|
if (node.stxcomment !== undefined) {
|
|
2617
2492
|
result.stxcomment = node.stxcomment;
|
|
@@ -2621,41 +2496,39 @@ export class V13ToV14Transformer {
|
|
|
2621
2496
|
}
|
|
2622
2497
|
return { CreateStatsStmt: result };
|
|
2623
2498
|
}
|
|
2624
|
-
CreateStmt(node
|
|
2625
|
-
|
|
2626
|
-
} {
|
|
2627
|
-
const result: any = {};
|
|
2499
|
+
CreateStmt(node, context) {
|
|
2500
|
+
const result = {};
|
|
2628
2501
|
if (node.relation !== undefined) {
|
|
2629
|
-
result.relation = this.transform(node.relation
|
|
2502
|
+
result.relation = this.transform(node.relation, context);
|
|
2630
2503
|
}
|
|
2631
2504
|
if (node.tableElts !== undefined) {
|
|
2632
2505
|
result.tableElts = Array.isArray(node.tableElts)
|
|
2633
|
-
? node.tableElts.map((item
|
|
2634
|
-
: this.transform(node.tableElts
|
|
2506
|
+
? node.tableElts.map((item) => this.transform(item, context))
|
|
2507
|
+
: this.transform(node.tableElts, context);
|
|
2635
2508
|
}
|
|
2636
2509
|
if (node.inhRelations !== undefined) {
|
|
2637
2510
|
result.inhRelations = Array.isArray(node.inhRelations)
|
|
2638
|
-
? node.inhRelations.map((item
|
|
2639
|
-
: this.transform(node.inhRelations
|
|
2511
|
+
? node.inhRelations.map((item) => this.transform(item, context))
|
|
2512
|
+
: this.transform(node.inhRelations, context);
|
|
2640
2513
|
}
|
|
2641
2514
|
if (node.partbound !== undefined) {
|
|
2642
|
-
result.partbound = this.transform(node.partbound
|
|
2515
|
+
result.partbound = this.transform(node.partbound, context);
|
|
2643
2516
|
}
|
|
2644
2517
|
if (node.partspec !== undefined) {
|
|
2645
|
-
result.partspec = this.transform(node.partspec
|
|
2518
|
+
result.partspec = this.transform(node.partspec, context);
|
|
2646
2519
|
}
|
|
2647
2520
|
if (node.ofTypename !== undefined) {
|
|
2648
|
-
result.ofTypename = this.transform(node.ofTypename
|
|
2521
|
+
result.ofTypename = this.transform(node.ofTypename, context);
|
|
2649
2522
|
}
|
|
2650
2523
|
if (node.constraints !== undefined) {
|
|
2651
2524
|
result.constraints = Array.isArray(node.constraints)
|
|
2652
|
-
? node.constraints.map((item
|
|
2653
|
-
: this.transform(node.constraints
|
|
2525
|
+
? node.constraints.map((item) => this.transform(item, context))
|
|
2526
|
+
: this.transform(node.constraints, context);
|
|
2654
2527
|
}
|
|
2655
2528
|
if (node.options !== undefined) {
|
|
2656
2529
|
result.options = Array.isArray(node.options)
|
|
2657
|
-
? node.options.map((item
|
|
2658
|
-
: this.transform(node.options
|
|
2530
|
+
? node.options.map((item) => this.transform(item, context))
|
|
2531
|
+
: this.transform(node.options, context);
|
|
2659
2532
|
}
|
|
2660
2533
|
if (node.oncommit !== undefined) {
|
|
2661
2534
|
result.oncommit = node.oncommit;
|
|
@@ -2671,15 +2544,13 @@ export class V13ToV14Transformer {
|
|
|
2671
2544
|
}
|
|
2672
2545
|
return { CreateStmt: result };
|
|
2673
2546
|
}
|
|
2674
|
-
CreatePolicyStmt(node
|
|
2675
|
-
|
|
2676
|
-
} {
|
|
2677
|
-
const result: any = {};
|
|
2547
|
+
CreatePolicyStmt(node, context) {
|
|
2548
|
+
const result = {};
|
|
2678
2549
|
if (node.policy_name !== undefined) {
|
|
2679
2550
|
result.policy_name = node.policy_name;
|
|
2680
2551
|
}
|
|
2681
2552
|
if (node.table !== undefined) {
|
|
2682
|
-
result.table = this.transform(node.table
|
|
2553
|
+
result.table = this.transform(node.table, context);
|
|
2683
2554
|
}
|
|
2684
2555
|
if (node.cmd_name !== undefined) {
|
|
2685
2556
|
result.cmd_name = node.cmd_name;
|
|
@@ -2689,23 +2560,21 @@ export class V13ToV14Transformer {
|
|
|
2689
2560
|
}
|
|
2690
2561
|
if (node.roles !== undefined) {
|
|
2691
2562
|
result.roles = Array.isArray(node.roles)
|
|
2692
|
-
? node.roles.map((item
|
|
2693
|
-
: this.transform(node.roles
|
|
2563
|
+
? node.roles.map((item) => this.transform(item, context))
|
|
2564
|
+
: this.transform(node.roles, context);
|
|
2694
2565
|
}
|
|
2695
2566
|
if (node.qual !== undefined) {
|
|
2696
|
-
result.qual = this.transform(node.qual
|
|
2567
|
+
result.qual = this.transform(node.qual, context);
|
|
2697
2568
|
}
|
|
2698
2569
|
if (node.with_check !== undefined) {
|
|
2699
|
-
result.with_check = this.transform(node.with_check
|
|
2570
|
+
result.with_check = this.transform(node.with_check, context);
|
|
2700
2571
|
}
|
|
2701
2572
|
return { CreatePolicyStmt: result };
|
|
2702
2573
|
}
|
|
2703
|
-
RenameStmt(node
|
|
2704
|
-
|
|
2705
|
-
} {
|
|
2706
|
-
const result: any = {};
|
|
2574
|
+
RenameStmt(node, context) {
|
|
2575
|
+
const result = {};
|
|
2707
2576
|
// Create child context with RenameStmt as parent
|
|
2708
|
-
const childContext
|
|
2577
|
+
const childContext = {
|
|
2709
2578
|
...context,
|
|
2710
2579
|
parentNodeTypes: [...(context.parentNodeTypes || []), 'RenameStmt'],
|
|
2711
2580
|
renameObjectType: node.renameType
|
|
@@ -2717,10 +2586,10 @@ export class V13ToV14Transformer {
|
|
|
2717
2586
|
result.relationType = node.relationType;
|
|
2718
2587
|
}
|
|
2719
2588
|
if (node.relation !== undefined) {
|
|
2720
|
-
result.relation = this.transform(node.relation
|
|
2589
|
+
result.relation = this.transform(node.relation, childContext);
|
|
2721
2590
|
}
|
|
2722
2591
|
if (node.object !== undefined) {
|
|
2723
|
-
result.object = this.transform(node.object
|
|
2592
|
+
result.object = this.transform(node.object, childContext);
|
|
2724
2593
|
}
|
|
2725
2594
|
if (node.subname !== undefined) {
|
|
2726
2595
|
result.subname = node.subname;
|
|
@@ -2736,12 +2605,10 @@ export class V13ToV14Transformer {
|
|
|
2736
2605
|
}
|
|
2737
2606
|
return { RenameStmt: result };
|
|
2738
2607
|
}
|
|
2739
|
-
AlterObjectSchemaStmt(node
|
|
2740
|
-
|
|
2741
|
-
} {
|
|
2742
|
-
const result: any = {};
|
|
2608
|
+
AlterObjectSchemaStmt(node, context) {
|
|
2609
|
+
const result = {};
|
|
2743
2610
|
// Create child context with AlterObjectSchemaStmt as parent
|
|
2744
|
-
const childContext
|
|
2611
|
+
const childContext = {
|
|
2745
2612
|
...context,
|
|
2746
2613
|
parentNodeTypes: [...(context.parentNodeTypes || []), 'AlterObjectSchemaStmt'],
|
|
2747
2614
|
alterObjectSchemaObjectType: node.objectType
|
|
@@ -2750,10 +2617,10 @@ export class V13ToV14Transformer {
|
|
|
2750
2617
|
result.objectType = node.objectType;
|
|
2751
2618
|
}
|
|
2752
2619
|
if (node.relation !== undefined) {
|
|
2753
|
-
result.relation = this.transform(node.relation
|
|
2620
|
+
result.relation = this.transform(node.relation, childContext);
|
|
2754
2621
|
}
|
|
2755
2622
|
if (node.object !== undefined) {
|
|
2756
|
-
result.object = this.transform(node.object
|
|
2623
|
+
result.object = this.transform(node.object, childContext);
|
|
2757
2624
|
}
|
|
2758
2625
|
if (node.newschema !== undefined) {
|
|
2759
2626
|
result.newschema = node.newschema;
|
|
@@ -2763,7 +2630,7 @@ export class V13ToV14Transformer {
|
|
|
2763
2630
|
}
|
|
2764
2631
|
return { AlterObjectSchemaStmt: result };
|
|
2765
2632
|
}
|
|
2766
|
-
|
|
2633
|
+
mapTableLikeOption(pg13Value) {
|
|
2767
2634
|
// Handle negative values (bitwise NOT operations) - these need special handling
|
|
2768
2635
|
if (pg13Value < 0) {
|
|
2769
2636
|
return pg13Value;
|
|
@@ -2771,9 +2638,7 @@ export class V13ToV14Transformer {
|
|
|
2771
2638
|
if (pg13Value & 256) { // ALL bit in PG13
|
|
2772
2639
|
return 2147483647; // This is the expected value from the test
|
|
2773
2640
|
}
|
|
2774
|
-
const pg13BitToPg14Bit
|
|
2775
|
-
[key: number]: number;
|
|
2776
|
-
} = {
|
|
2641
|
+
const pg13BitToPg14Bit = {
|
|
2777
2642
|
1: 1, // COMMENTS (bit 0) -> COMMENTS (bit 0) - unchanged
|
|
2778
2643
|
2: 4, // CONSTRAINTS (bit 1) -> CONSTRAINTS (bit 2) - shifted by compression
|
|
2779
2644
|
4: 8, // DEFAULTS (bit 2) -> DEFAULTS (bit 3) - shifted by compression
|
|
@@ -2804,9 +2669,9 @@ export class V13ToV14Transformer {
|
|
|
2804
2669
|
}
|
|
2805
2670
|
return result || pg13Value; // fallback to original value if no bits were set
|
|
2806
2671
|
}
|
|
2807
|
-
|
|
2672
|
+
getPG13EnumName(value) {
|
|
2808
2673
|
// Handle bit flag values for TableLikeOption enum
|
|
2809
|
-
const bitNames
|
|
2674
|
+
const bitNames = [];
|
|
2810
2675
|
if (value & 1)
|
|
2811
2676
|
bitNames.push('COMMENTS');
|
|
2812
2677
|
if (value & 2)
|
|
@@ -2827,7 +2692,7 @@ export class V13ToV14Transformer {
|
|
|
2827
2692
|
bitNames.push('ALL');
|
|
2828
2693
|
return bitNames.length > 0 ? bitNames.join(' | ') : `UNKNOWN(${value})`;
|
|
2829
2694
|
}
|
|
2830
|
-
|
|
2695
|
+
mapFunctionParameterMode(pg13Mode, context, hasParameterName) {
|
|
2831
2696
|
// Handle specific mode mappings between PG13 and PG14
|
|
2832
2697
|
switch (pg13Mode) {
|
|
2833
2698
|
case 'FUNC_PARAM_VARIADIC':
|
|
@@ -2837,15 +2702,15 @@ export class V13ToV14Transformer {
|
|
|
2837
2702
|
return 'FUNC_PARAM_IN';
|
|
2838
2703
|
}
|
|
2839
2704
|
if (context &&
|
|
2840
|
-
(
|
|
2841
|
-
!
|
|
2842
|
-
|
|
2705
|
+
(context.functionHasExplicitModes &&
|
|
2706
|
+
!context.hasExplicitInParameters &&
|
|
2707
|
+
context.allParametersHaveExplicitModes === false)) {
|
|
2843
2708
|
return 'FUNC_PARAM_DEFAULT';
|
|
2844
2709
|
}
|
|
2845
2710
|
// Convert implicit IN parameters to DEFAULT for functions with only IN parameters
|
|
2846
2711
|
if (context &&
|
|
2847
|
-
!
|
|
2848
|
-
!
|
|
2712
|
+
!context.functionHasExplicitModes &&
|
|
2713
|
+
!context.hasExplicitInParameters) {
|
|
2849
2714
|
return 'FUNC_PARAM_DEFAULT';
|
|
2850
2715
|
}
|
|
2851
2716
|
return 'FUNC_PARAM_IN';
|
|
@@ -2853,20 +2718,18 @@ export class V13ToV14Transformer {
|
|
|
2853
2718
|
return pg13Mode;
|
|
2854
2719
|
}
|
|
2855
2720
|
}
|
|
2856
|
-
ReindexStmt(node
|
|
2857
|
-
|
|
2858
|
-
} {
|
|
2859
|
-
const result: any = {};
|
|
2721
|
+
ReindexStmt(node, context) {
|
|
2722
|
+
const result = {};
|
|
2860
2723
|
if (node.kind !== undefined) {
|
|
2861
2724
|
result.kind = node.kind;
|
|
2862
2725
|
}
|
|
2863
2726
|
if (node.relation !== undefined) {
|
|
2864
|
-
result.relation = this.transform(node.relation
|
|
2727
|
+
result.relation = this.transform(node.relation, context);
|
|
2865
2728
|
}
|
|
2866
2729
|
if (node.name !== undefined) {
|
|
2867
2730
|
result.name = node.name;
|
|
2868
2731
|
}
|
|
2869
|
-
const nodeAny = node
|
|
2732
|
+
const nodeAny = node;
|
|
2870
2733
|
if (nodeAny.options !== undefined) {
|
|
2871
2734
|
const params = [];
|
|
2872
2735
|
if (nodeAny.options & 1) { // REINDEXOPT_VERBOSE
|