pgsql-deparser 14.0.1 → 14.1.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/README.md CHANGED
@@ -1,20 +1,20 @@
1
1
  # pgsql-deparser
2
2
 
3
3
  <p align="center" width="100%">
4
- <img height="120" src="https://github.com/launchql/pgsql-parser/assets/545047/6440fa7d-918b-4a3b-8d1b-755d85de8bea" />
4
+ <img height="120" src="https://github.com/constructive-io/pgsql-parser/assets/545047/6440fa7d-918b-4a3b-8d1b-755d85de8bea" />
5
5
  </p>
6
6
 
7
7
  <p align="center" width="100%">
8
- <a href="https://github.com/launchql/pgsql-parser/actions/workflows/run-tests.yaml">
9
- <img height="20" src="https://github.com/launchql/pgsql-parser/actions/workflows/run-tests.yaml/badge.svg" />
8
+ <a href="https://github.com/constructive-io/pgsql-parser/actions/workflows/run-tests.yaml">
9
+ <img height="20" src="https://github.com/constructive-io/pgsql-parser/actions/workflows/run-tests.yaml/badge.svg" />
10
10
  </a>
11
11
  <a href="https://www.npmjs.com/package/pgsql-deparser"><img height="20" src="https://img.shields.io/npm/dt/pgsql-deparser"></a>
12
12
  <a href="https://www.npmjs.com/package/pgsql-deparser"><img height="20" src="https://img.shields.io/npm/dw/pgsql-deparser"/></a>
13
- <a href="https://github.com/launchql/pgsql-parser/blob/main/LICENSE-MIT"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/></a>
14
- <a href="https://www.npmjs.com/package/pgsql-deparser"><img height="20" src="https://img.shields.io/github/package-json/v/launchql/pgsql-parser?filename=packages%2Fdeparser%2Fpackage.json"/></a>
13
+ <a href="https://github.com/constructive-io/pgsql-parser/blob/main/LICENSE-MIT"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/></a>
14
+ <a href="https://www.npmjs.com/package/pgsql-deparser"><img height="20" src="https://img.shields.io/github/package-json/v/constructive-io/pgsql-parser?filename=packages%2Fdeparser%2Fpackage.json"/></a>
15
15
  </p>
16
16
 
17
- `pgsql-deparser` is the lightning-fast, pure TypeScript solution for converting PostgreSQL ASTs back into SQL queries. Perfect companion to [`pgsql-parser`](https://github.com/launchql/pgsql-parser), this focused tool delivers SQL generation without any native dependencies or WebAssembly overhead.
17
+ `pgsql-deparser` is the lightning-fast, pure TypeScript solution for converting PostgreSQL ASTs back into SQL queries. Perfect companion to [`pgsql-parser`](https://github.com/constructive-io/pgsql-parser), this focused tool delivers SQL generation without any native dependencies or WebAssembly overhead.
18
18
 
19
19
  ## Installation
20
20
 
@@ -33,7 +33,7 @@ npm install pgsql-deparser
33
33
 
34
34
  The `pgsql-deparser` module serializes ASTs to SQL in pure TypeScript, avoiding the full parser's native dependencies. It's useful when only SQL string conversion from ASTs is needed, and is written in pure TypeScript for easy cross-environment deployment.
35
35
 
36
- Here's how you can use the deparser in your TypeScript code, using [`@pgsql/utils`](https://github.com/launchql/pgsql-parser/tree/main/packages/utils) to create an AST for `deparse`:
36
+ Here's how you can use the deparser in your TypeScript code, using [`@pgsql/utils`](https://github.com/constructive-io/pgsql-parser/tree/main/packages/utils) to create an AST for `deparse`:
37
37
 
38
38
  ```ts
39
39
  import * as t from '@pgsql/utils';
@@ -80,12 +80,17 @@ npm install pgsql-deparser
80
80
  While we highly recommend using PG17, for PostgreSQL versions 13-16, use the version-specific packages:
81
81
 
82
82
  ```sh
83
- npm install pgsql-deparser@v13 # PostgreSQL 13
84
- npm install pgsql-deparser@v14 # PostgreSQL 14
85
- npm install pgsql-deparser@v15 # PostgreSQL 15
86
- npm install pgsql-deparser@v16 # PostgreSQL 16
83
+ npm install pgsql-deparser@pg13 # PostgreSQL 13
84
+ npm install pgsql-deparser@pg14 # PostgreSQL 14
85
+ npm install pgsql-deparser@pg15 # PostgreSQL 15
86
+ npm install pgsql-deparser@pg16 # PostgreSQL 16
87
87
  ```
88
88
 
89
+ **Version Status:**
90
+ - **PG17**: 🚀 Recommended (stable + modern AST)
91
+ - **PG14-16**: ⚠️ Experimental (modern AST, hardening in progress)
92
+ - **PG13**: Stable (legacy AST format)
93
+
89
94
  ## Options
90
95
 
91
96
  The deparser accepts optional configuration for formatting and output control:
@@ -94,7 +99,7 @@ The deparser accepts optional configuration for formatting and output control:
94
99
  import { deparseSync as deparse } from 'pgsql-deparser';
95
100
 
96
101
  const options = {
97
- pretty: true, // Enable pretty formatting (default: false)
102
+ pretty: true, // Enable pretty formatting (default: true)
98
103
  newline: '\n', // Newline character (default: '\n')
99
104
  tab: ' ', // Tab/indentation character (default: ' ')
100
105
  semicolons: true // Add semicolons to statements (default: true)
@@ -105,7 +110,7 @@ const sql = deparse(ast, options);
105
110
 
106
111
  | Option | Type | Default | Description |
107
112
  |--------|------|---------|-------------|
108
- | `pretty` | `boolean` | `false` | Enable pretty formatting with indentation and line breaks |
113
+ | `pretty` | `boolean` | `true` | Enable pretty formatting with indentation and line breaks |
109
114
  | `newline` | `string` | `'\n'` | Character(s) used for line breaks |
110
115
  | `tab` | `string` | `' '` | Character(s) used for indentation |
111
116
  | `semicolons` | `boolean` | `true` | Add semicolons to SQL statements |
@@ -126,7 +131,7 @@ const sql2 = deparse(selectAst, { pretty: true });
126
131
  // active = true;
127
132
  ```
128
133
 
129
- For complete documentation and advanced options, see [DEPARSER_USAGE.md](../../DEPARSER_USAGE.md).
134
+ For complete documentation and advanced options, see [DEPARSER_USAGE.md](https://github.com/constructive-io/pgsql-parser/tree/main/packages/deparser/DEPARSER_USAGE.md).
130
135
 
131
136
  ## Why Use `pgsql-deparser`?
132
137
 
@@ -142,6 +147,8 @@ Built on the excellent work of several contributors:
142
147
  * **[Ethan Resnick](https://github.com/ethanresnick)** for the original Node.js N-API bindings
143
148
  * **[Zac McCormick](https://github.com/zhm)** for the foundational [node-pg-query-native](https://github.com/zhm/node-pg-query-native) parser
144
149
 
150
+ **🛠 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).**
151
+
145
152
  ## Related
146
153
 
147
154
  * [pgsql-parser](https://www.npmjs.com/package/pgsql-parser): The real PostgreSQL parser for Node.js, providing symmetric parsing and deparsing of SQL statements with actual PostgreSQL parser integration.
@@ -150,11 +157,12 @@ Built on the excellent work of several contributors:
150
157
  * [@pgsql/types](https://www.npmjs.com/package/@pgsql/types): Offers TypeScript type definitions for PostgreSQL AST nodes, facilitating type-safe construction, analysis, and manipulation of ASTs.
151
158
  * [@pgsql/enums](https://www.npmjs.com/package/@pgsql/enums): Provides TypeScript enum definitions for PostgreSQL constants, enabling type-safe usage of PostgreSQL enums and constants in your applications.
152
159
  * [@pgsql/utils](https://www.npmjs.com/package/@pgsql/utils): A comprehensive utility library for PostgreSQL, offering type-safe AST node creation and enum value conversions, simplifying the construction and manipulation of PostgreSQL ASTs.
160
+ * [@pgsql/traverse](https://www.npmjs.com/package/@pgsql/traverse): PostgreSQL AST traversal utilities for pgsql-parser, providing a visitor pattern for traversing PostgreSQL Abstract Syntax Tree nodes, similar to Babel's traverse functionality but specifically designed for PostgreSQL AST structures.
153
161
  * [pg-proto-parser](https://www.npmjs.com/package/pg-proto-parser): A TypeScript tool that parses PostgreSQL Protocol Buffers definitions to generate TypeScript interfaces, utility functions, and JSON mappings for enums.
154
- * [libpg-query](https://github.com/launchql/libpg-query-node): The real PostgreSQL parser exposed for Node.js, used primarily in `pgsql-parser` for parsing and deparsing SQL queries.
162
+ * [libpg-query](https://github.com/constructive-io/libpg-query-node): The real PostgreSQL parser exposed for Node.js, used primarily in `pgsql-parser` for parsing and deparsing SQL queries.
155
163
 
156
164
  ## Disclaimer
157
165
 
158
166
  AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
159
167
 
160
- 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.
168
+ 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.
@@ -36,7 +36,6 @@ export interface DeparserOptions {
36
36
  * compatibility and wraps them internally for consistent processing.
37
37
  */
38
38
  export declare class Deparser implements DeparserVisitor {
39
- private formatter;
40
39
  private tree;
41
40
  private options;
42
41
  constructor(tree: any | any[] | any, opts?: DeparserOptions);
@@ -59,6 +58,11 @@ export declare class Deparser implements DeparserVisitor {
59
58
  * @returns The delimiter to use
60
59
  */
61
60
  private getFunctionDelimiter;
61
+ /**
62
+ * Maps ObjectType enum values to their corresponding SQL keywords
63
+ * Used by AlterOwnerStmt, AlterObjectSchemaStmt, and other statements that need object type keywords
64
+ */
65
+ private getObjectTypeKeyword;
62
66
  deparse(node: any, context?: DeparserContext): string | null;
63
67
  visit(node: any, context?: DeparserContext): string;
64
68
  getNodeType(node: any): string;
@@ -67,10 +71,11 @@ export declare class Deparser implements DeparserVisitor {
67
71
  RawStmt(node: any, context: DeparserContext): string;
68
72
  SelectStmt(node: any, context: DeparserContext): string;
69
73
  A_Expr(node: any, context: DeparserContext): string;
70
- deparseOperatorName(name: any): string;
74
+ deparseOperatorName(name: any, context: DeparserContext): string;
71
75
  private getOperatorPrecedence;
72
76
  private needsParentheses;
73
77
  private isComplexExpression;
78
+ private isComplexSelectTarget;
74
79
  visitBetweenRange(rexpr: any, context: DeparserContext): string;
75
80
  InsertStmt(node: any, context: DeparserContext): string;
76
81
  UpdateStmt(node: any, context: DeparserContext): string;
@@ -90,6 +95,7 @@ export declare class Deparser implements DeparserVisitor {
90
95
  formatTypeMods(typmods: any, context: DeparserContext): string | null;
91
96
  formatSingleTypeMod(typemod: number, typeName: string): string | null;
92
97
  getPgCatalogTypeName(typeName: string, size: string | null): string;
98
+ isPgCatalogType(typeName: string): boolean;
93
99
  A_ArrayExpr(node: any, context: DeparserContext): string;
94
100
  A_Indices(node: any, context: DeparserContext): string;
95
101
  A_Indirection(node: any, context: DeparserContext): string;
@@ -117,7 +123,7 @@ export declare class Deparser implements DeparserVisitor {
117
123
  SubLink(node: any, context: DeparserContext): string;
118
124
  CaseWhen(node: any, context: DeparserContext): string;
119
125
  WindowDef(node: any, context: DeparserContext): string;
120
- formatWindowFrame(node: any): string | null;
126
+ formatWindowFrame(node: any, context: DeparserContext): string | null;
121
127
  SortBy(node: any, context: DeparserContext): string;
122
128
  GroupingSet(node: any, context: DeparserContext): string;
123
129
  CommonTableExpr(node: any, context: DeparserContext): string;
@@ -171,6 +177,7 @@ export declare class Deparser implements DeparserVisitor {
171
177
  AlterTableSpaceOptionsStmt(node: any, context: DeparserContext): string;
172
178
  CreateExtensionStmt(node: any, context: DeparserContext): string;
173
179
  AlterExtensionStmt(node: any, context: DeparserContext): string;
180
+ AlterExtensionContentsStmt(node: any, context: DeparserContext): string;
174
181
  CreateFdwStmt(node: any, context: DeparserContext): string;
175
182
  SetOperationStmt(node: any, context: DeparserContext): string;
176
183
  ReplicaIdentityStmt(node: any, context: DeparserContext): string;