pgsql-deparser 17.18.5 → 17.19.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 CHANGED
@@ -69,27 +69,29 @@ console.log(deparse(stmt));
69
69
  // Output: SELECT * FROM another_table
70
70
  ```
71
71
 
72
- ### Latest Version (PostgreSQL 17)
72
+ ### Latest Version (PostgreSQL 18)
73
73
 
74
74
  ```sh
75
75
  npm install pgsql-deparser
76
76
  ```
77
77
 
78
- ### Version-Specific Packages (PostgreSQL 13-16)
78
+ ### Version-Specific Packages (PostgreSQL 13-17)
79
79
 
80
- While we highly recommend using PG17, for PostgreSQL versions 13-16, use the version-specific packages:
80
+ We recommend PG18. PG17 remains fully supported; for PostgreSQL versions 13-17, use the version-specific packages:
81
81
 
82
82
  ```sh
83
83
  npm install pgsql-deparser@pg13 # PostgreSQL 13
84
84
  npm install pgsql-deparser@pg14 # PostgreSQL 14
85
85
  npm install pgsql-deparser@pg15 # PostgreSQL 15
86
86
  npm install pgsql-deparser@pg16 # PostgreSQL 16
87
+ npm install pgsql-deparser@pg17 # PostgreSQL 17
87
88
  ```
88
89
 
89
90
  **Version Status:**
90
- - **PG17**: 🚀 Recommended (stable + modern AST)
91
- - **PG14-16**: ⚠️ Experimental (modern AST, hardening in progress)
92
- - **PG13**: Stable (legacy AST format)
91
+ - **PG18**: 🚀 Recommended (stable + modern AST)
92
+ - **PG17**: Stable (modern AST)
93
+ - **PG14-16**: Legacy (modern AST, not actively developed)
94
+ - **PG13**: Legacy (legacy AST format)
93
95
 
94
96
  ## Options
95
97
 
@@ -147,8 +149,6 @@ Built on the excellent work of several contributors:
147
149
  * **[Ethan Resnick](https://github.com/ethanresnick)** for the original Node.js N-API bindings
148
150
  * **[Zac McCormick](https://github.com/zhm)** for the foundational [node-pg-query-native](https://github.com/zhm/node-pg-query-native) parser
149
151
 
150
- ---
151
-
152
152
  **🛠 Built by the [Constructive](https://constructive.io) team — creators of modular Postgres tooling for secure, composable backends. If you like our work, contribute on [GitHub](https://github.com/constructive-io).**
153
153
 
154
154
  ## Related
@@ -170,4 +170,4 @@ Built on the excellent work of several contributors:
170
170
 
171
171
  AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
172
172
 
173
- No developer or entity involved in creating Software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the Software code or Software CLI, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
173
+ No developer or entity involved in creating Software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the Software code or Software CLI, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
@@ -0,0 +1,311 @@
1
+ /**
2
+ * Auto-generated file with types stripped for better tree-shaking
3
+ * DO NOT EDIT - Generated by strip-deparser-types.ts
4
+ */
5
+ import { DeparserContext, DeparserVisitor } from './visitors/base';
6
+ export interface DeparserOptions {
7
+ newline?: string;
8
+ tab?: string;
9
+ functionDelimiter?: string;
10
+ functionDelimiterFallback?: string;
11
+ pretty?: boolean;
12
+ }
13
+ export declare class Deparser implements DeparserVisitor {
14
+ private tree;
15
+ private options;
16
+ constructor(tree: any | any[] | any, opts?: DeparserOptions);
17
+ /**
18
+ * Static method to deparse PostgreSQL AST nodes to SQL
19
+ * @param query - Can be:
20
+ * - ParseResult from libpg-query (e.g., { version: 170004, stmts: [...] })
21
+ * - Wrapped ParseResult node (e.g., { ParseResult: {...} })
22
+ * - Wrapped RawStmt node (e.g., { RawStmt: {...} })
23
+ * - Array of Nodes
24
+ * - Single Node (e.g., { SelectStmt: {...} })
25
+ * @param opts - Deparser options for formatting
26
+ * @returns The deparsed SQL string
27
+ */
28
+ static deparse(query: any | any[] | any, opts?: DeparserOptions): string;
29
+ deparseQuery(): string;
30
+ /**
31
+ * Get the appropriate function delimiter based on the body content
32
+ * @param body The function body to check
33
+ * @returns The delimiter to use
34
+ */
35
+ private getFunctionDelimiter;
36
+ /**
37
+ * Maps ObjectType enum values to their corresponding SQL keywords
38
+ * Used by AlterOwnerStmt, AlterObjectSchemaStmt, and other statements that need object type keywords
39
+ */
40
+ private getObjectTypeKeyword;
41
+ deparse(node: any, context?: DeparserContext): string | null;
42
+ visit(node: any, context?: DeparserContext): string;
43
+ getNodeType(node: any): string;
44
+ getNodeData(node: any): any;
45
+ ParseResult(node: any, context: DeparserContext): string;
46
+ RawStmt(node: any, context: DeparserContext): string;
47
+ SelectStmt(node: any, context: DeparserContext): string;
48
+ A_Expr(node: any, context: DeparserContext): string;
49
+ deparseOperatorName(name: any, context: DeparserContext): string;
50
+ private getOperatorPrecedence;
51
+ private needsParentheses;
52
+ private isComplexExpression;
53
+ private isComplexSelectTarget;
54
+ visitBetweenRange(rexpr: any, context: DeparserContext): string;
55
+ InsertStmt(node: any, context: DeparserContext): string;
56
+ UpdateStmt(node: any, context: DeparserContext): string;
57
+ formatUpdateAssignments(targets: any[], context: DeparserContext): string;
58
+ DeleteStmt(node: any, context: DeparserContext): string;
59
+ WithClause(node: any, context: DeparserContext): string;
60
+ ResTarget(node: any, context: DeparserContext): string;
61
+ ATAlterConstraint(node: any, context: DeparserContext): string;
62
+ deparseKeyAttrs(attrs: any, withPeriod: boolean | undefined, context: DeparserContext): string;
63
+ ReturningClause(node: any, context: DeparserContext): string;
64
+ ReturningOption(node: any, context: DeparserContext): string;
65
+ deparseReturningList(list: any, context: DeparserContext): string;
66
+ BoolExpr(node: any, context: DeparserContext): string;
67
+ FuncCall(node: any, context: DeparserContext): string;
68
+ formatOverClause(over: any, context: DeparserContext): string;
69
+ FuncExpr(node: any, context: DeparserContext): string;
70
+ A_Const(node: any, context: DeparserContext): string;
71
+ ColumnRef(node: any, context: DeparserContext): string;
72
+ TypeName(node: any, context: DeparserContext): string;
73
+ Alias(node: any, context: DeparserContext): string;
74
+ RangeVar(node: any, context: DeparserContext): string;
75
+ formatIntervalTypeMods(typmods: any, context: DeparserContext): string | null;
76
+ formatTypeMods(typmods: any, context: DeparserContext): string | null;
77
+ formatSingleTypeMod(typemod: number, typeName: string): string | null;
78
+ getPgCatalogTypeName(typeName: string, size: string | null): string;
79
+ isPgCatalogType(typeName: string): boolean;
80
+ A_ArrayExpr(node: any, context: DeparserContext): string;
81
+ A_Indices(node: any, context: DeparserContext): string;
82
+ A_Indirection(node: any, context: DeparserContext): string;
83
+ A_Star(node: any, context: DeparserContext): string;
84
+ CaseExpr(node: any, context: DeparserContext): string;
85
+ CoalesceExpr(node: any, context: DeparserContext): string;
86
+ TypeCast(node: any, context: DeparserContext): string;
87
+ CollateClause(node: any, context: DeparserContext): string;
88
+ BooleanTest(node: any, context: DeparserContext): string;
89
+ NullTest(node: any, context: DeparserContext): string;
90
+ quoteIfNeeded(value: string): string;
91
+ preserveOperatorDefElemCase(defName: string): string;
92
+ String(node: any, context: DeparserContext): string;
93
+ Integer(node: any, context: DeparserContext): string;
94
+ Float(node: any, context: DeparserContext): string;
95
+ Boolean(node: any, context: DeparserContext): string;
96
+ BitString(node: any, context: DeparserContext): string;
97
+ Null(node: any, context: DeparserContext): string;
98
+ List(node: any, context: DeparserContext): string;
99
+ CreateStmt(node: any, context: DeparserContext): string;
100
+ ColumnDef(node: any, context: DeparserContext): string;
101
+ Constraint(node: any, context: DeparserContext): string;
102
+ SubLink(node: any, context: DeparserContext): string;
103
+ CaseWhen(node: any, context: DeparserContext): string;
104
+ WindowDef(node: any, context: DeparserContext): string;
105
+ formatIdentityColumnOptions(def: any, context: DeparserContext): string;
106
+ needsBExprParens(node: any): boolean;
107
+ formatWindowFrame(node: any, context: DeparserContext): string | null;
108
+ SortBy(node: any, context: DeparserContext): string;
109
+ GroupingSet(node: any, context: DeparserContext): string;
110
+ CommonTableExpr(node: any, context: DeparserContext): string;
111
+ formatAexprConst(node: any, context: DeparserContext): string;
112
+ ParamRef(node: any, context: DeparserContext): string;
113
+ LockingClause(node: any, context: DeparserContext): string;
114
+ MinMaxExpr(node: any, context: DeparserContext): string;
115
+ RowExpr(node: any, context: DeparserContext): string;
116
+ OpExpr(node: any, context: DeparserContext): string;
117
+ DistinctExpr(node: any, context: DeparserContext): string;
118
+ NullIfExpr(node: any, context: DeparserContext): string;
119
+ ScalarArrayOpExpr(node: any, context: DeparserContext): string;
120
+ Aggref(node: any, context: DeparserContext): string;
121
+ WindowFunc(node: any, context: DeparserContext): string;
122
+ FieldSelect(node: any, context: DeparserContext): string;
123
+ RelabelType(node: any, context: DeparserContext): string;
124
+ CoerceViaIO(node: any, context: DeparserContext): string;
125
+ ArrayCoerceExpr(node: any, context: DeparserContext): string;
126
+ ConvertRowtypeExpr(node: any, context: DeparserContext): string;
127
+ NamedArgExpr(node: any, context: DeparserContext): string;
128
+ ViewStmt(node: any, context: DeparserContext): string;
129
+ IndexStmt(node: any, context: DeparserContext): string;
130
+ IndexElem(node: any, context: DeparserContext): string;
131
+ PartitionElem(node: any, context: DeparserContext): string;
132
+ PartitionCmd(node: any, context: DeparserContext): string;
133
+ private getAggFunctionName;
134
+ private getWindowFunctionName;
135
+ private getOperatorName;
136
+ JoinExpr(node: any, context: DeparserContext): string;
137
+ FromExpr(node: any, context: DeparserContext): string;
138
+ TransactionStmt(node: any, context: DeparserContext): string;
139
+ VariableSetStmt(node: any, context: DeparserContext): string;
140
+ VariableShowStmt(node: any, context: DeparserContext): string;
141
+ CreateSchemaStmt(node: any, context: DeparserContext): string;
142
+ RoleSpec(node: any, context: DeparserContext): string;
143
+ roletype(node: any, context: DeparserContext): string;
144
+ DropStmt(node: any, context: DeparserContext): string;
145
+ TruncateStmt(node: any, context: DeparserContext): string;
146
+ ReturnStmt(node: any, context: DeparserContext): string;
147
+ PLAssignStmt(node: any, context: DeparserContext): string;
148
+ CopyStmt(node: any, context: DeparserContext): string;
149
+ AlterTableStmt(node: any, context: DeparserContext): string;
150
+ AlterTableCmd(node: any, context: DeparserContext): string;
151
+ CreateFunctionStmt(node: any, context: DeparserContext): string;
152
+ FunctionParameter(node: any, context: DeparserContext): string;
153
+ CreateEnumStmt(node: any, context: DeparserContext): string;
154
+ CreateDomainStmt(node: any, context: DeparserContext): string;
155
+ CreateRoleStmt(node: any, context: DeparserContext): string;
156
+ DefElem(node: any, context: DeparserContext): string;
157
+ CreateTableSpaceStmt(node: any, context: DeparserContext): string;
158
+ DropTableSpaceStmt(node: any, context: DeparserContext): string;
159
+ AlterTableSpaceOptionsStmt(node: any, context: DeparserContext): string;
160
+ CreateExtensionStmt(node: any, context: DeparserContext): string;
161
+ AlterExtensionStmt(node: any, context: DeparserContext): string;
162
+ AlterExtensionContentsStmt(node: any, context: DeparserContext): string;
163
+ CreateFdwStmt(node: any, context: DeparserContext): string;
164
+ SetOperationStmt(node: any, context: DeparserContext): string;
165
+ ReplicaIdentityStmt(node: any, context: DeparserContext): string;
166
+ AlterCollationStmt(node: any, context: DeparserContext): string;
167
+ AlterDomainStmt(node: any, context: DeparserContext): string;
168
+ PrepareStmt(node: any, context: DeparserContext): string;
169
+ ExecuteStmt(node: any, context: DeparserContext): string;
170
+ DeallocateStmt(node: any, context: DeparserContext): string;
171
+ NotifyStmt(node: any, context: DeparserContext): string;
172
+ ListenStmt(node: any, context: DeparserContext): string;
173
+ UnlistenStmt(node: any, context: DeparserContext): string;
174
+ CheckPointStmt(node: any, context: DeparserContext): string;
175
+ LoadStmt(node: any, context: DeparserContext): string;
176
+ DiscardStmt(node: any, context: DeparserContext): string;
177
+ /** `schema.op` for an operator name list: schema parts quoted, the operator symbol as is. */
178
+ private qualifiedOperatorName;
179
+ CommentStmt(node: any, context: DeparserContext): string;
180
+ LockStmt(node: any, context: DeparserContext): string;
181
+ CreatePolicyStmt(node: any, context: DeparserContext): string;
182
+ AlterPolicyStmt(node: any, context: DeparserContext): string;
183
+ CreateUserMappingStmt(node: any, context: DeparserContext): string;
184
+ CreateStatsStmt(node: any, context: DeparserContext): string;
185
+ StatsElem(node: any, context: DeparserContext): string;
186
+ CreatePublicationStmt(node: any, context: DeparserContext): string;
187
+ CreateSubscriptionStmt(node: any, context: DeparserContext): string;
188
+ AlterPublicationStmt(node: any, context: DeparserContext): string;
189
+ AlterSubscriptionStmt(node: any, context: DeparserContext): string;
190
+ DropSubscriptionStmt(node: any, context: DeparserContext): string;
191
+ DoStmt(node: any, context: DeparserContext): string;
192
+ private generateUniqueDollarTag;
193
+ InlineCodeBlock(node: any, context: DeparserContext): string;
194
+ CallContext(node: any, context: DeparserContext): string;
195
+ ConstraintsSetStmt(node: any, context: DeparserContext): string;
196
+ AlterSystemStmt(node: any, context: DeparserContext): string;
197
+ VacuumRelation(node: any, context: DeparserContext): string;
198
+ DropOwnedStmt(node: any, context: DeparserContext): string;
199
+ ReassignOwnedStmt(node: any, context: DeparserContext): string;
200
+ AlterTSDictionaryStmt(node: any, context: DeparserContext): string;
201
+ AlterTSConfigurationStmt(node: any, context: DeparserContext): string;
202
+ ClosePortalStmt(node: any, context: DeparserContext): string;
203
+ FetchStmt(node: any, context: DeparserContext): string;
204
+ AlterStatsStmt(node: any, context: DeparserContext): string;
205
+ ObjectWithArgs(node: any, context: DeparserContext): string;
206
+ AlterOperatorStmt(node: any, context: DeparserContext): string;
207
+ AlterFdwStmt(node: any, context: DeparserContext): string;
208
+ CreateForeignServerStmt(node: any, context: DeparserContext): string;
209
+ AlterForeignServerStmt(node: any, context: DeparserContext): string;
210
+ AlterUserMappingStmt(node: any, context: DeparserContext): string;
211
+ DropUserMappingStmt(node: any, context: DeparserContext): string;
212
+ ImportForeignSchemaStmt(node: any, context: DeparserContext): string;
213
+ ClusterStmt(node: any, context: DeparserContext): string;
214
+ VacuumStmt(node: any, context: DeparserContext): string;
215
+ ExplainStmt(node: any, context: DeparserContext): string;
216
+ ReindexStmt(node: any, context: DeparserContext): string;
217
+ CallStmt(node: any, context: DeparserContext): string;
218
+ CreatedbStmt(node: any, context: DeparserContext): string;
219
+ DropdbStmt(node: any, context: DeparserContext): string;
220
+ RenameStmt(node: any, context: DeparserContext): string;
221
+ AlterOwnerStmt(node: any, context: DeparserContext): string;
222
+ GrantStmt(node: any, context: DeparserContext): string;
223
+ GrantRoleStmt(node: any, context: DeparserContext): string;
224
+ SecLabelStmt(node: any, context: DeparserContext): string;
225
+ AlterDefaultPrivilegesStmt(node: any, context: DeparserContext): string;
226
+ CreateConversionStmt(node: any, context: DeparserContext): string;
227
+ CreateCastStmt(node: any, context: DeparserContext): string;
228
+ CreatePLangStmt(node: any, context: DeparserContext): string;
229
+ CreateTransformStmt(node: any, context: DeparserContext): string;
230
+ CreateTrigStmt(node: any, context: DeparserContext): string;
231
+ TriggerTransition(node: any, context: DeparserContext): string;
232
+ CreateEventTrigStmt(node: any, context: DeparserContext): string;
233
+ AlterEventTrigStmt(node: any, context: DeparserContext): string;
234
+ CreateOpClassStmt(node: any, context: DeparserContext): string;
235
+ CreateOpFamilyStmt(node: any, context: DeparserContext): string;
236
+ AlterOpFamilyStmt(node: any, context: DeparserContext): string;
237
+ MergeStmt(node: any, context: DeparserContext): string;
238
+ MergeSupportFunc(node: any, context: DeparserContext): string;
239
+ MergeWhenClause(node: any, context: DeparserContext): string;
240
+ AlterTableMoveAllStmt(node: any, context: DeparserContext): string;
241
+ CreateSeqStmt(node: any, context: DeparserContext): string;
242
+ AlterSeqStmt(node: any, context: DeparserContext): string;
243
+ CompositeTypeStmt(node: any, context: DeparserContext): string;
244
+ CreateRangeStmt(node: any, context: DeparserContext): string;
245
+ AlterEnumStmt(node: any, context: DeparserContext): string;
246
+ AlterTypeStmt(node: any, context: DeparserContext): string;
247
+ AlterRoleStmt(node: any, context: DeparserContext): string;
248
+ DropRoleStmt(node: any, context: DeparserContext): string;
249
+ targetList(node: any, context: DeparserContext): string;
250
+ CreateAggregateStmt(node: any, context: DeparserContext): string;
251
+ CreateTableAsStmt(node: any, context: DeparserContext): string;
252
+ RefreshMatViewStmt(node: any, context: DeparserContext): string;
253
+ AccessPriv(node: any, context: DeparserContext): string;
254
+ aliasname(node: any, context: DeparserContext): string;
255
+ DefineStmt(node: any, context: DeparserContext): string;
256
+ AlterDatabaseStmt(node: any, context: DeparserContext): string;
257
+ AlterDatabaseRefreshCollStmt(node: any, context: DeparserContext): string;
258
+ AlterDatabaseSetStmt(node: any, context: DeparserContext): string;
259
+ DeclareCursorStmt(node: any, context: DeparserContext): string;
260
+ PublicationObjSpec(node: any, context: DeparserContext): string;
261
+ PublicationTable(node: any, context: DeparserContext): string;
262
+ CreateAmStmt(node: any, context: DeparserContext): string;
263
+ IntoClause(node: any, context: DeparserContext): string;
264
+ OnConflictExpr(node: any, context: DeparserContext): string;
265
+ ScanToken(node: any, context: DeparserContext): string;
266
+ CreateOpClassItem(node: any, context: DeparserContext): string;
267
+ private quoteDefElemArg;
268
+ private formatOptionValue;
269
+ Var(node: any, context: DeparserContext): string;
270
+ TableFunc(node: any, context: DeparserContext): string;
271
+ RangeTableFunc(node: any, context: DeparserContext): string;
272
+ private formatXmlTableExpr;
273
+ RangeTableFuncCol(node: any, context: DeparserContext): string;
274
+ formatJsonFormat(format: any): string | null;
275
+ formatJsonOutput(output: any, context: DeparserContext): string | null;
276
+ formatJsonNullClause(absentOnNull: boolean | undefined): string;
277
+ formatJsonUniqueClause(unique: boolean | undefined): string | null;
278
+ JsonValueExpr(node: any, context: DeparserContext): string;
279
+ JsonKeyValue(node: any, context: DeparserContext): string;
280
+ JsonObjectConstructor(node: any, context: DeparserContext): string;
281
+ JsonArrayConstructor(node: any, context: DeparserContext): string;
282
+ JsonArrayQueryConstructor(node: any, context: DeparserContext): string;
283
+ formatJsonAggSuffix(ctor: any, context: DeparserContext): string;
284
+ JsonObjectAgg(node: any, context: DeparserContext): string;
285
+ JsonArrayAgg(node: any, context: DeparserContext): string;
286
+ JsonParseExpr(node: any, context: DeparserContext): string;
287
+ JsonScalarExpr(node: any, context: DeparserContext): string;
288
+ JsonSerializeExpr(node: any, context: DeparserContext): string;
289
+ JsonIsPredicate(node: any, context: DeparserContext): string;
290
+ RangeFunction(node: any, context: DeparserContext): string;
291
+ XmlExpr(node: any, context: DeparserContext): string;
292
+ schemaname(node: any, context: DeparserContext): string;
293
+ RangeTableSample(node: any, context: DeparserContext): string;
294
+ XmlSerialize(node: any, context: DeparserContext): string;
295
+ ctes(node: any, context: DeparserContext): string;
296
+ RuleStmt(node: any, context: DeparserContext): string;
297
+ RangeSubselect(node: any, context: DeparserContext): string;
298
+ relname(node: any, context: DeparserContext): string;
299
+ rel(node: any, context: DeparserContext): string;
300
+ objname(node: any, context: DeparserContext): string;
301
+ SQLValueFunction(node: any, context: DeparserContext): string;
302
+ GroupingFunc(node: any, context: DeparserContext): string;
303
+ MultiAssignRef(node: any, context: DeparserContext): string;
304
+ SetToDefault(node: any, context: DeparserContext): string;
305
+ CurrentOfExpr(node: any, context: DeparserContext): string;
306
+ TableLikeClause(node: any, context: DeparserContext): string;
307
+ AlterFunctionStmt(node: any, context: DeparserContext): string;
308
+ AlterObjectSchemaStmt(node: any, context: DeparserContext): string;
309
+ AlterRoleSetStmt(node: any, context: DeparserContext): string;
310
+ CreateForeignTableStmt(node: any, context: DeparserContext): string;
311
+ }