pgsql-deparser 16.1.1 → 16.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -7
- package/deparser/deparser.d.ts +31 -28
- package/deparser/deparser.js +1253 -814
- package/deparser/index.d.ts +3 -1
- package/deparser/index.js +5 -1
- package/deparser/utils/sql-formatter.d.ts +8 -0
- package/deparser/utils/sql-formatter.js +104 -1
- package/esm/deparser/deparser.js +1236 -797
- package/esm/deparser/index.js +3 -1
- package/esm/deparser/utils/sql-formatter.js +103 -1
- package/esm/index.js +16 -7
- package/esm/v16-to-v17.js +44 -1
- package/esm/v16-to-v18-direct.js +55 -0
- package/esm/v17-to-v18.js +209 -0
- package/index.d.ts +11 -4
- package/index.js +19 -6
- package/package.json +3 -2
- package/v16-to-v17.d.ts +3 -0
- package/v16-to-v17.js +44 -1
- package/v16-to-v18-direct.d.ts +22 -0
- package/v16-to-v18-direct.js +59 -0
- package/v17-to-v18.d.ts +55 -0
- package/v17-to-v18.js +213 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Auto-generated file with types stripped for better tree-shaking
|
|
4
|
+
* DO NOT EDIT - Generated by strip-direct-transformer-types.ts
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.PG16ToPG18Transformer = void 0;
|
|
8
|
+
const v16_to_v17_1 = require("./v16-to-v17");
|
|
9
|
+
const v17_to_v18_1 = require("./v17-to-v18");
|
|
10
|
+
/**
|
|
11
|
+
* Direct transformer from PG16 to PG18
|
|
12
|
+
* This transformer chains v16->...->v18 transformations
|
|
13
|
+
*/
|
|
14
|
+
class PG16ToPG18Transformer {
|
|
15
|
+
v16to17 = new v16_to_v17_1.V16ToV17Transformer();
|
|
16
|
+
v17to18 = new v17_to_v18_1.V17ToV18Transformer();
|
|
17
|
+
transform(node) {
|
|
18
|
+
if (this.isParseResult(node)) {
|
|
19
|
+
// Transform through the chain: v16->v17->v18
|
|
20
|
+
const v17Stmts = node.stmts.map((stmtWrapper) => {
|
|
21
|
+
if (stmtWrapper.stmt) {
|
|
22
|
+
const stmt = this.v16to17.transform(stmtWrapper.stmt, { parentNodeTypes: [] });
|
|
23
|
+
return { ...stmtWrapper, stmt };
|
|
24
|
+
}
|
|
25
|
+
return stmtWrapper;
|
|
26
|
+
});
|
|
27
|
+
const v18Stmts = v17Stmts.map((stmtWrapper) => {
|
|
28
|
+
if (stmtWrapper.stmt) {
|
|
29
|
+
const stmt = this.v17to18.transform(stmtWrapper.stmt, { parentNodeTypes: [] });
|
|
30
|
+
return { ...stmtWrapper, stmt };
|
|
31
|
+
}
|
|
32
|
+
return stmtWrapper;
|
|
33
|
+
});
|
|
34
|
+
return {
|
|
35
|
+
...node,
|
|
36
|
+
version: 180004, // PG18 version
|
|
37
|
+
stmts: v18Stmts
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
// Otherwise, transform as a regular node through the chain
|
|
41
|
+
const v17Node = this.v16to17.transform(node, { parentNodeTypes: [] });
|
|
42
|
+
return this.v17to18.transform(v17Node, { parentNodeTypes: [] });
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Transform a single statement from PG16 to PG18
|
|
46
|
+
* @deprecated Use transform() instead, which handles all node types
|
|
47
|
+
*/
|
|
48
|
+
transformStatement(stmt) {
|
|
49
|
+
const v17Stmt = this.v16to17.transform(stmt, { parentNodeTypes: [] });
|
|
50
|
+
return this.v17to18.transform(v17Stmt, { parentNodeTypes: [] });
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Type guard to check if a node is a ParseResult
|
|
54
|
+
*/
|
|
55
|
+
isParseResult(node) {
|
|
56
|
+
return node && typeof node === 'object' && 'version' in node && 'stmts' in node;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.PG16ToPG18Transformer = PG16ToPG18Transformer;
|
package/v17-to-v18.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auto-generated file with types stripped for better tree-shaking
|
|
3
|
+
* DO NOT EDIT - Generated by strip-transformer-types.ts
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* V17 to V18 AST Transformer
|
|
7
|
+
* Transforms PostgreSQL v17 AST nodes to v18 format
|
|
8
|
+
*
|
|
9
|
+
* Structural changes in v18:
|
|
10
|
+
* - InsertStmt/UpdateStmt/DeleteStmt/MergeStmt: returningList -> returningClause { exprs }
|
|
11
|
+
* - Constraint: new is_enforced flag (true by default for CHECK/FOREIGN/NOTNULL)
|
|
12
|
+
* - Constraint: CONSTR_GENERATED gains generated_kind ('s' = STORED, 'v' = VIRTUAL)
|
|
13
|
+
* - Column-level NOT NULL constraints gain initially_valid: true
|
|
14
|
+
*/
|
|
15
|
+
export declare class V17ToV18Transformer {
|
|
16
|
+
transform(node: any, context?: any): any;
|
|
17
|
+
visit(node: any, context?: any): any;
|
|
18
|
+
/**
|
|
19
|
+
* Generic recursive walk that re-dispatches wrapped nodes with a
|
|
20
|
+
* dedicated transformer method and deep-copies everything else.
|
|
21
|
+
*/
|
|
22
|
+
private walkValue;
|
|
23
|
+
getNodeType(node: any): any;
|
|
24
|
+
getNodeData(node: any): any;
|
|
25
|
+
ParseResult(node: any, context: any): any;
|
|
26
|
+
RawStmt(node: any, context: any): {
|
|
27
|
+
RawStmt: any;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Convert a v17 returningList into a v18 ReturningClause
|
|
31
|
+
*/
|
|
32
|
+
private transformReturningList;
|
|
33
|
+
private transformDmlStatement;
|
|
34
|
+
InsertStmt(node: any, context: any): {
|
|
35
|
+
InsertStmt: any;
|
|
36
|
+
};
|
|
37
|
+
UpdateStmt(node: any, context: any): {
|
|
38
|
+
UpdateStmt: any;
|
|
39
|
+
};
|
|
40
|
+
DeleteStmt(node: any, context: any): {
|
|
41
|
+
DeleteStmt: any;
|
|
42
|
+
};
|
|
43
|
+
MergeStmt(node: any, context: any): {
|
|
44
|
+
MergeStmt: any;
|
|
45
|
+
};
|
|
46
|
+
AlterTableCmd(node: any, context: any): {
|
|
47
|
+
AlterTableCmd: any;
|
|
48
|
+
};
|
|
49
|
+
VariableSetStmt(node: any, context: any): {
|
|
50
|
+
VariableSetStmt: any;
|
|
51
|
+
};
|
|
52
|
+
Constraint(node: any, context: any): {
|
|
53
|
+
Constraint: any;
|
|
54
|
+
};
|
|
55
|
+
}
|
package/v17-to-v18.js
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Auto-generated file with types stripped for better tree-shaking
|
|
4
|
+
* DO NOT EDIT - Generated by strip-transformer-types.ts
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.V17ToV18Transformer = void 0;
|
|
8
|
+
// @ts-nocheck
|
|
9
|
+
/**
|
|
10
|
+
* V17 to V18 AST Transformer
|
|
11
|
+
* Transforms PostgreSQL v17 AST nodes to v18 format
|
|
12
|
+
*
|
|
13
|
+
* Structural changes in v18:
|
|
14
|
+
* - InsertStmt/UpdateStmt/DeleteStmt/MergeStmt: returningList -> returningClause { exprs }
|
|
15
|
+
* - Constraint: new is_enforced flag (true by default for CHECK/FOREIGN/NOTNULL)
|
|
16
|
+
* - Constraint: CONSTR_GENERATED gains generated_kind ('s' = STORED, 'v' = VIRTUAL)
|
|
17
|
+
* - Column-level NOT NULL constraints gain initially_valid: true
|
|
18
|
+
*/
|
|
19
|
+
class V17ToV18Transformer {
|
|
20
|
+
transform(node, context = { parentNodeTypes: [] }) {
|
|
21
|
+
if (node == null) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
if (typeof node === 'number' || node instanceof Number) {
|
|
25
|
+
return node;
|
|
26
|
+
}
|
|
27
|
+
if (typeof node === 'string') {
|
|
28
|
+
return node;
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
return this.visit(node, context);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
const nodeType = Object.keys(node)[0];
|
|
35
|
+
throw new Error(`Error transforming ${nodeType}: ${error.message}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
visit(node, context = { parentNodeTypes: [] }) {
|
|
39
|
+
if (node && typeof node === 'object' && 'version' in node && 'stmts' in node) {
|
|
40
|
+
return this.ParseResult(node, context);
|
|
41
|
+
}
|
|
42
|
+
const nodeType = this.getNodeType(node);
|
|
43
|
+
// Handle empty objects
|
|
44
|
+
if (!nodeType) {
|
|
45
|
+
return {};
|
|
46
|
+
}
|
|
47
|
+
const nodeData = this.getNodeData(node);
|
|
48
|
+
const methodName = nodeType;
|
|
49
|
+
if (typeof this[methodName] === 'function') {
|
|
50
|
+
const childContext = {
|
|
51
|
+
...context,
|
|
52
|
+
parentNodeTypes: [...context.parentNodeTypes, nodeType]
|
|
53
|
+
};
|
|
54
|
+
const result = this[methodName](nodeData, childContext);
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
// No specific method: recurse into children so nested statements
|
|
58
|
+
// (e.g. DML inside CTEs) still get transformed
|
|
59
|
+
return this.walkValue(node, context);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Generic recursive walk that re-dispatches wrapped nodes with a
|
|
63
|
+
* dedicated transformer method and deep-copies everything else.
|
|
64
|
+
*/
|
|
65
|
+
walkValue(value, context) {
|
|
66
|
+
if (value == null || typeof value !== 'object') {
|
|
67
|
+
return value;
|
|
68
|
+
}
|
|
69
|
+
if (Array.isArray(value)) {
|
|
70
|
+
return value.map(item => this.walkValue(item, context));
|
|
71
|
+
}
|
|
72
|
+
const keys = Object.keys(value);
|
|
73
|
+
if (keys.length === 1 && typeof this[keys[0]] === 'function') {
|
|
74
|
+
// Wrapped node with a dedicated transformer method
|
|
75
|
+
return this.visit(value, context);
|
|
76
|
+
}
|
|
77
|
+
const result = {};
|
|
78
|
+
for (const key of keys) {
|
|
79
|
+
result[key] = this.walkValue(value[key], context);
|
|
80
|
+
}
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
getNodeType(node) {
|
|
84
|
+
return Object.keys(node)[0];
|
|
85
|
+
}
|
|
86
|
+
getNodeData(node) {
|
|
87
|
+
const keys = Object.keys(node);
|
|
88
|
+
if (keys.length === 1 && typeof node[keys[0]] === 'object') {
|
|
89
|
+
return node[keys[0]];
|
|
90
|
+
}
|
|
91
|
+
return node;
|
|
92
|
+
}
|
|
93
|
+
ParseResult(node, context) {
|
|
94
|
+
if (node && typeof node === 'object' && 'version' in node && 'stmts' in node) {
|
|
95
|
+
return {
|
|
96
|
+
version: 180004, // PG18 version
|
|
97
|
+
stmts: node.stmts.map((stmt) => {
|
|
98
|
+
if (stmt && typeof stmt === 'object' && 'stmt' in stmt) {
|
|
99
|
+
return {
|
|
100
|
+
...stmt,
|
|
101
|
+
stmt: this.transform(stmt.stmt, context)
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
return this.transform(stmt, context);
|
|
105
|
+
})
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
return node;
|
|
109
|
+
}
|
|
110
|
+
RawStmt(node, context) {
|
|
111
|
+
const result = {};
|
|
112
|
+
if (node.stmt !== undefined) {
|
|
113
|
+
result.stmt = this.transform(node.stmt, context);
|
|
114
|
+
}
|
|
115
|
+
if (node.stmt_location !== undefined) {
|
|
116
|
+
result.stmt_location = node.stmt_location;
|
|
117
|
+
}
|
|
118
|
+
if (node.stmt_len !== undefined) {
|
|
119
|
+
result.stmt_len = node.stmt_len;
|
|
120
|
+
}
|
|
121
|
+
return { RawStmt: result };
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Convert a v17 returningList into a v18 ReturningClause
|
|
125
|
+
*/
|
|
126
|
+
transformReturningList(returningList, context) {
|
|
127
|
+
return {
|
|
128
|
+
exprs: returningList.map(item => this.transform(item, context))
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
transformDmlStatement(nodeType, node, context) {
|
|
132
|
+
const result = {};
|
|
133
|
+
for (const key of Object.keys(node)) {
|
|
134
|
+
if (key === 'returningList') {
|
|
135
|
+
result.returningClause = this.transformReturningList(node.returningList, context);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
result[key] = this.walkValue(node[key], context);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return { [nodeType]: result };
|
|
142
|
+
}
|
|
143
|
+
InsertStmt(node, context) {
|
|
144
|
+
return this.transformDmlStatement('InsertStmt', node, context);
|
|
145
|
+
}
|
|
146
|
+
UpdateStmt(node, context) {
|
|
147
|
+
return this.transformDmlStatement('UpdateStmt', node, context);
|
|
148
|
+
}
|
|
149
|
+
DeleteStmt(node, context) {
|
|
150
|
+
return this.transformDmlStatement('DeleteStmt', node, context);
|
|
151
|
+
}
|
|
152
|
+
MergeStmt(node, context) {
|
|
153
|
+
return this.transformDmlStatement('MergeStmt', node, context);
|
|
154
|
+
}
|
|
155
|
+
AlterTableCmd(node, context) {
|
|
156
|
+
const result = {};
|
|
157
|
+
for (const key of Object.keys(node)) {
|
|
158
|
+
result[key] = this.walkValue(node[key], context);
|
|
159
|
+
}
|
|
160
|
+
// v18 wraps ALTER CONSTRAINT definitions in the new ATAlterConstraint node
|
|
161
|
+
if (node.subtype === 'AT_AlterConstraint' && node.def?.Constraint) {
|
|
162
|
+
const constraint = node.def.Constraint;
|
|
163
|
+
const alterConstraint = {};
|
|
164
|
+
if (constraint.conname !== undefined) {
|
|
165
|
+
alterConstraint.conname = constraint.conname;
|
|
166
|
+
}
|
|
167
|
+
alterConstraint.is_enforced = true;
|
|
168
|
+
// v17 ALTER CONSTRAINT could only change deferrability
|
|
169
|
+
alterConstraint.alterDeferrability = true;
|
|
170
|
+
if (constraint.deferrable !== undefined) {
|
|
171
|
+
alterConstraint.deferrable = constraint.deferrable;
|
|
172
|
+
}
|
|
173
|
+
if (constraint.initdeferred !== undefined) {
|
|
174
|
+
alterConstraint.initdeferred = constraint.initdeferred;
|
|
175
|
+
}
|
|
176
|
+
result.def = { ATAlterConstraint: alterConstraint };
|
|
177
|
+
}
|
|
178
|
+
return { AlterTableCmd: result };
|
|
179
|
+
}
|
|
180
|
+
VariableSetStmt(node, context) {
|
|
181
|
+
const result = {};
|
|
182
|
+
for (const key of Object.keys(node)) {
|
|
183
|
+
result[key] = this.walkValue(node[key], context);
|
|
184
|
+
}
|
|
185
|
+
// v18 marks SET TRANSACTION / SESSION CHARACTERISTICS args as jumbled
|
|
186
|
+
if (node.kind === 'VAR_SET_MULTI' && (node.name === 'TRANSACTION' || node.name === 'SESSION CHARACTERISTICS')) {
|
|
187
|
+
result.jumble_args = true;
|
|
188
|
+
}
|
|
189
|
+
return { VariableSetStmt: result };
|
|
190
|
+
}
|
|
191
|
+
Constraint(node, context) {
|
|
192
|
+
const result = {};
|
|
193
|
+
for (const key of Object.keys(node)) {
|
|
194
|
+
result[key] = this.walkValue(node[key], context);
|
|
195
|
+
}
|
|
196
|
+
// v18 constraints are enforced by default; v17 grammar had no ENFORCED syntax
|
|
197
|
+
if (node.contype === 'CONSTR_CHECK' || node.contype === 'CONSTR_FOREIGN') {
|
|
198
|
+
result.is_enforced = true;
|
|
199
|
+
}
|
|
200
|
+
if (node.contype === 'CONSTR_NOTNULL') {
|
|
201
|
+
// v17 only produces column-level NOT NULL constraints, which in v18
|
|
202
|
+
// carry is_enforced and initially_valid
|
|
203
|
+
result.is_enforced = true;
|
|
204
|
+
result.initially_valid = true;
|
|
205
|
+
}
|
|
206
|
+
if (node.contype === 'CONSTR_GENERATED' && result.generated_kind === undefined) {
|
|
207
|
+
// v17 only supports STORED generated columns
|
|
208
|
+
result.generated_kind = 's';
|
|
209
|
+
}
|
|
210
|
+
return { Constraint: result };
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
exports.V17ToV18Transformer = V17ToV18Transformer;
|