pgsql-deparser 14.0.0 → 14.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/README.md +12 -6
  2. package/{dist/deparser → deparser}/deparser.d.ts +4 -3
  3. package/{dist/deparser → deparser}/deparser.js +883 -437
  4. package/{dist/deparser → deparser}/utils/sql-formatter.js +1 -1
  5. package/deparser/visitors/base.d.ts +68 -0
  6. package/deparser/visitors/base.js +122 -0
  7. package/{dist/esm → esm}/deparser/deparser.js +883 -437
  8. package/{dist/esm → esm}/deparser/utils/sql-formatter.js +1 -1
  9. package/esm/deparser/visitors/base.js +117 -0
  10. package/{dist/esm → esm}/v14-to-v15.js +3 -0
  11. package/{dist/esm → esm}/v15-to-v16.js +60 -1
  12. package/package.json +1 -2
  13. package/{dist/v14-to-v15.js → v14-to-v15.js} +3 -0
  14. package/{dist/v15-to-v16.d.ts → v15-to-v16.d.ts} +6 -0
  15. package/{dist/v15-to-v16.js → v15-to-v16.js} +60 -1
  16. package/dist/README.md +0 -160
  17. package/dist/deparser/visitors/base.d.ts +0 -21
  18. package/dist/deparser/visitors/base.js +0 -34
  19. package/dist/esm/deparser/visitors/base.js +0 -30
  20. package/dist/package.json +0 -42
  21. package/src/deparser/deparser.ts +0 -10026
  22. package/src/deparser/index.ts +0 -14
  23. package/src/deparser/utils/list-utils.ts +0 -27
  24. package/src/deparser/utils/quote-utils.ts +0 -86
  25. package/src/deparser/utils/sql-formatter.ts +0 -37
  26. package/src/deparser/visitors/base.ts +0 -40
  27. package/src/index.ts +0 -27
  28. package/src/v14-to-v15.ts +0 -1621
  29. package/src/v14-to-v17-direct.ts +0 -68
  30. package/src/v15-to-v16.ts +0 -3290
  31. package/src/v16-to-v17.ts +0 -1897
  32. package/tsconfig.esm.json +0 -8
  33. package/tsconfig.json +0 -26
  34. /package/{dist/LICENSE → LICENSE} +0 -0
  35. /package/{dist/deparser → deparser}/index.d.ts +0 -0
  36. /package/{dist/deparser → deparser}/index.js +0 -0
  37. /package/{dist/deparser → deparser}/utils/list-utils.d.ts +0 -0
  38. /package/{dist/deparser → deparser}/utils/list-utils.js +0 -0
  39. /package/{dist/deparser → deparser}/utils/quote-utils.d.ts +0 -0
  40. /package/{dist/deparser → deparser}/utils/quote-utils.js +0 -0
  41. /package/{dist/deparser → deparser}/utils/sql-formatter.d.ts +0 -0
  42. /package/{dist/esm → esm}/deparser/index.js +0 -0
  43. /package/{dist/esm → esm}/deparser/utils/list-utils.js +0 -0
  44. /package/{dist/esm → esm}/deparser/utils/quote-utils.js +0 -0
  45. /package/{dist/esm → esm}/index.js +0 -0
  46. /package/{dist/esm → esm}/v14-to-v17-direct.js +0 -0
  47. /package/{dist/esm → esm}/v16-to-v17.js +0 -0
  48. /package/{dist/index.d.ts → index.d.ts} +0 -0
  49. /package/{dist/index.js → index.js} +0 -0
  50. /package/{dist/v14-to-v15.d.ts → v14-to-v15.d.ts} +0 -0
  51. /package/{dist/v14-to-v17-direct.d.ts → v14-to-v17-direct.d.ts} +0 -0
  52. /package/{dist/v14-to-v17-direct.js → v14-to-v17-direct.js} +0 -0
  53. /package/{dist/v16-to-v17.d.ts → v16-to-v17.d.ts} +0 -0
  54. /package/{dist/v16-to-v17.js → v16-to-v17.js} +0 -0
@@ -6,7 +6,7 @@ export class SqlFormatter {
6
6
  newlineChar;
7
7
  tabChar;
8
8
  prettyMode;
9
- constructor(newlineChar = '\n', tabChar = ' ', prettyMode = false) {
9
+ constructor(newlineChar = '\n', tabChar = ' ', prettyMode = true) {
10
10
  this.newlineChar = newlineChar;
11
11
  this.tabChar = tabChar;
12
12
  this.prettyMode = prettyMode;
@@ -0,0 +1,117 @@
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 { SqlFormatter } from '../utils/sql-formatter';
6
+ export class DeparserContext {
7
+ indentLevel;
8
+ prettyMode;
9
+ isStringLiteral;
10
+ parentNodeTypes;
11
+ formatter;
12
+ select;
13
+ from;
14
+ group;
15
+ sort;
16
+ insertColumns;
17
+ update;
18
+ bool;
19
+ isColumnConstraint;
20
+ isDomainConstraint;
21
+ alterColumnOptions;
22
+ alterTableOptions;
23
+ isEnumValue;
24
+ objtype;
25
+ subtype;
26
+ constructor({ indentLevel = 0, prettyMode = true, isStringLiteral, parentNodeTypes = [], formatter, select, from, group, sort, insertColumns, update, bool, isColumnConstraint, isDomainConstraint, alterColumnOptions, alterTableOptions, isEnumValue, objtype, subtype, ...rest } = {}) {
27
+ this.indentLevel = indentLevel;
28
+ this.prettyMode = prettyMode;
29
+ this.isStringLiteral = isStringLiteral;
30
+ this.parentNodeTypes = parentNodeTypes;
31
+ this.formatter = formatter || new SqlFormatter('\n', ' ', prettyMode);
32
+ this.select = select;
33
+ this.from = from;
34
+ this.group = group;
35
+ this.sort = sort;
36
+ this.insertColumns = insertColumns;
37
+ this.update = update;
38
+ this.bool = bool;
39
+ this.isColumnConstraint = isColumnConstraint;
40
+ this.isDomainConstraint = isDomainConstraint;
41
+ this.alterColumnOptions = alterColumnOptions;
42
+ this.alterTableOptions = alterTableOptions;
43
+ this.isEnumValue = isEnumValue;
44
+ this.objtype = objtype;
45
+ this.subtype = subtype;
46
+ Object.assign(this, rest);
47
+ }
48
+ spawn(nodeType, overrides = {}) {
49
+ return new DeparserContext({
50
+ indentLevel: this.indentLevel,
51
+ prettyMode: this.prettyMode,
52
+ isStringLiteral: this.isStringLiteral,
53
+ parentNodeTypes: [...this.parentNodeTypes, nodeType],
54
+ formatter: this.formatter,
55
+ select: this.select,
56
+ from: this.from,
57
+ group: this.group,
58
+ sort: this.sort,
59
+ insertColumns: this.insertColumns,
60
+ update: this.update,
61
+ bool: this.bool,
62
+ isColumnConstraint: this.isColumnConstraint,
63
+ isDomainConstraint: this.isDomainConstraint,
64
+ alterColumnOptions: this.alterColumnOptions,
65
+ alterTableOptions: this.alterTableOptions,
66
+ isEnumValue: this.isEnumValue,
67
+ objtype: this.objtype,
68
+ subtype: this.subtype,
69
+ ...overrides,
70
+ });
71
+ }
72
+ indent(text, count) {
73
+ if (!this.prettyMode) {
74
+ return text;
75
+ }
76
+ const indentCount = count !== undefined ? count : this.indentLevel + 1;
77
+ return this.formatter.indent(text, indentCount);
78
+ }
79
+ newline() {
80
+ return this.formatter.newline();
81
+ }
82
+ parens(content) {
83
+ return this.formatter.parens(content);
84
+ }
85
+ format(parts, separator) {
86
+ return this.formatter.format(parts, separator);
87
+ }
88
+ isPretty() {
89
+ return this.formatter.isPretty();
90
+ }
91
+ }
92
+ export class BaseVisitor {
93
+ getNodeType(node) {
94
+ return Object.keys(node)[0];
95
+ }
96
+ getNodeData(node) {
97
+ const type = this.getNodeType(node);
98
+ return node[type];
99
+ }
100
+ formatList(items, separator = ', ', prefix = '', formatter) {
101
+ if (!items || items.length === 0) {
102
+ return '';
103
+ }
104
+ return items
105
+ .map(item => `${prefix}${formatter(item)}`)
106
+ .join(separator);
107
+ }
108
+ formatParts(parts, separator = ' ') {
109
+ return parts.filter(part => part !== null && part !== undefined && part !== '').join(separator);
110
+ }
111
+ formatParens(content) {
112
+ return `(${content})`;
113
+ }
114
+ formatIndent(text, count = 1) {
115
+ return text;
116
+ }
117
+ }
@@ -659,6 +659,9 @@ export class V14ToV15Transformer {
659
659
  if (node.name !== undefined) {
660
660
  result.name = node.name;
661
661
  }
662
+ if (node.num !== undefined) {
663
+ result.num = node.num;
664
+ }
662
665
  if (node.newowner !== undefined) {
663
666
  result.newowner = this.transform(node.newowner, context);
664
667
  }
@@ -332,6 +332,18 @@ export class V15ToV16Transformer {
332
332
  { String: { sval: 'json_object' } }
333
333
  ];
334
334
  }
335
+ else if (node.funcname.length === 2 &&
336
+ node.funcname[0]?.String?.sval === 'pg_catalog' &&
337
+ node.funcname[1]?.String?.sval === 'system_user' &&
338
+ node.funcformat === 'COERCE_SQL_SYNTAX') {
339
+ return {
340
+ ColumnRef: {
341
+ fields: [
342
+ { String: { sval: 'system_user' } }
343
+ ]
344
+ }
345
+ };
346
+ }
335
347
  else {
336
348
  result.funcname = Array.isArray(node.funcname)
337
349
  ? node.funcname.map((item) => this.transform(item, context))
@@ -437,6 +449,20 @@ export class V15ToV16Transformer {
437
449
  return { A_Const: result };
438
450
  }
439
451
  ColumnRef(node, context) {
452
+ if (node.fields && Array.isArray(node.fields) && node.fields.length === 1) {
453
+ const field = node.fields[0];
454
+ if (field?.String?.sval === 'system_user') {
455
+ return {
456
+ FuncCall: {
457
+ funcname: [
458
+ { String: { sval: 'pg_catalog' } },
459
+ { String: { sval: 'system_user' } }
460
+ ],
461
+ funcformat: 'COERCE_SQL_SYNTAX'
462
+ }
463
+ };
464
+ }
465
+ }
440
466
  const result = {};
441
467
  if (node.fields !== undefined) {
442
468
  result.fields = Array.isArray(node.fields)
@@ -499,6 +525,30 @@ export class V15ToV16Transformer {
499
525
  return { Alias: result };
500
526
  }
501
527
  RangeVar(node, context) {
528
+ if (node.relname === 'system_user' && node.inh === true && node.relpersistence === 'p') {
529
+ return {
530
+ RangeFunction: {
531
+ functions: [
532
+ {
533
+ List: {
534
+ items: [
535
+ {
536
+ FuncCall: {
537
+ funcname: [
538
+ { String: { sval: 'pg_catalog' } },
539
+ { String: { sval: 'system_user' } }
540
+ ],
541
+ funcformat: 'COERCE_SQL_SYNTAX'
542
+ }
543
+ },
544
+ {}
545
+ ]
546
+ }
547
+ }
548
+ ]
549
+ }
550
+ };
551
+ }
502
552
  const result = {};
503
553
  if (node.catalogname !== undefined) {
504
554
  result.catalogname = node.catalogname;
@@ -706,7 +756,13 @@ export class V15ToV16Transformer {
706
756
  const result = {};
707
757
  if (node.items !== undefined) {
708
758
  result.items = Array.isArray(node.items)
709
- ? node.items.map((item) => this.transform(item, context))
759
+ ? node.items.map((item) => {
760
+ const transformed = this.transform(item, context);
761
+ if (transformed === null) {
762
+ return {};
763
+ }
764
+ return transformed;
765
+ })
710
766
  : this.transform(node.items, context);
711
767
  }
712
768
  return { List: result };
@@ -1633,6 +1689,9 @@ export class V15ToV16Transformer {
1633
1689
  if (node.unique !== undefined) {
1634
1690
  result.unique = node.unique;
1635
1691
  }
1692
+ if (node.nulls_not_distinct !== undefined) {
1693
+ result.nulls_not_distinct = node.nulls_not_distinct;
1694
+ }
1636
1695
  if (node.primary !== undefined) {
1637
1696
  result.primary = node.primary;
1638
1697
  }
package/package.json CHANGED
@@ -9,7 +9,6 @@
9
9
  "scripts": {
10
10
  "copy": "copyfiles -f ../../../../LICENSE README.md package.json dist",
11
11
  "clean": "rimraf dist",
12
- "prepare": "npm run build",
13
12
  "build": "npm run clean && tsc && tsc -p tsconfig.esm.json && npm run copy",
14
13
  "publish:pkg": "npm publish --tag pg14"
15
14
  },
@@ -35,7 +34,7 @@
35
34
  "database"
36
35
  ],
37
36
  "name": "pgsql-deparser",
38
- "version": "14.0.0",
37
+ "version": "14.1.0",
39
38
  "dependencies": {
40
39
  "@pgsql/types": "^14.1.1"
41
40
  }
@@ -662,6 +662,9 @@ class V14ToV15Transformer {
662
662
  if (node.name !== undefined) {
663
663
  result.name = node.name;
664
664
  }
665
+ if (node.num !== undefined) {
666
+ result.num = node.num;
667
+ }
665
668
  if (node.newowner !== undefined) {
666
669
  result.newowner = this.transform(node.newowner, context);
667
670
  }
@@ -41,6 +41,8 @@ export declare class V15ToV16Transformer {
41
41
  };
42
42
  FuncCall(node: any, context: any): {
43
43
  FuncCall: any;
44
+ } | {
45
+ ColumnRef: any;
44
46
  };
45
47
  FuncExpr(node: any, context: any): {
46
48
  FuncExpr: any;
@@ -50,6 +52,8 @@ export declare class V15ToV16Transformer {
50
52
  };
51
53
  ColumnRef(node: any, context: any): {
52
54
  ColumnRef: any;
55
+ } | {
56
+ FuncCall: any;
53
57
  };
54
58
  TypeName(node: any, context: any): {
55
59
  TypeName: any;
@@ -59,6 +63,8 @@ export declare class V15ToV16Transformer {
59
63
  };
60
64
  RangeVar(node: any, context: any): {
61
65
  RangeVar: any;
66
+ } | {
67
+ RangeFunction: any;
62
68
  };
63
69
  A_ArrayExpr(node: any, context: any): {
64
70
  A_ArrayExpr: any;
@@ -335,6 +335,18 @@ class V15ToV16Transformer {
335
335
  { String: { sval: 'json_object' } }
336
336
  ];
337
337
  }
338
+ else if (node.funcname.length === 2 &&
339
+ node.funcname[0]?.String?.sval === 'pg_catalog' &&
340
+ node.funcname[1]?.String?.sval === 'system_user' &&
341
+ node.funcformat === 'COERCE_SQL_SYNTAX') {
342
+ return {
343
+ ColumnRef: {
344
+ fields: [
345
+ { String: { sval: 'system_user' } }
346
+ ]
347
+ }
348
+ };
349
+ }
338
350
  else {
339
351
  result.funcname = Array.isArray(node.funcname)
340
352
  ? node.funcname.map((item) => this.transform(item, context))
@@ -440,6 +452,20 @@ class V15ToV16Transformer {
440
452
  return { A_Const: result };
441
453
  }
442
454
  ColumnRef(node, context) {
455
+ if (node.fields && Array.isArray(node.fields) && node.fields.length === 1) {
456
+ const field = node.fields[0];
457
+ if (field?.String?.sval === 'system_user') {
458
+ return {
459
+ FuncCall: {
460
+ funcname: [
461
+ { String: { sval: 'pg_catalog' } },
462
+ { String: { sval: 'system_user' } }
463
+ ],
464
+ funcformat: 'COERCE_SQL_SYNTAX'
465
+ }
466
+ };
467
+ }
468
+ }
443
469
  const result = {};
444
470
  if (node.fields !== undefined) {
445
471
  result.fields = Array.isArray(node.fields)
@@ -502,6 +528,30 @@ class V15ToV16Transformer {
502
528
  return { Alias: result };
503
529
  }
504
530
  RangeVar(node, context) {
531
+ if (node.relname === 'system_user' && node.inh === true && node.relpersistence === 'p') {
532
+ return {
533
+ RangeFunction: {
534
+ functions: [
535
+ {
536
+ List: {
537
+ items: [
538
+ {
539
+ FuncCall: {
540
+ funcname: [
541
+ { String: { sval: 'pg_catalog' } },
542
+ { String: { sval: 'system_user' } }
543
+ ],
544
+ funcformat: 'COERCE_SQL_SYNTAX'
545
+ }
546
+ },
547
+ {}
548
+ ]
549
+ }
550
+ }
551
+ ]
552
+ }
553
+ };
554
+ }
505
555
  const result = {};
506
556
  if (node.catalogname !== undefined) {
507
557
  result.catalogname = node.catalogname;
@@ -709,7 +759,13 @@ class V15ToV16Transformer {
709
759
  const result = {};
710
760
  if (node.items !== undefined) {
711
761
  result.items = Array.isArray(node.items)
712
- ? node.items.map((item) => this.transform(item, context))
762
+ ? node.items.map((item) => {
763
+ const transformed = this.transform(item, context);
764
+ if (transformed === null) {
765
+ return {};
766
+ }
767
+ return transformed;
768
+ })
713
769
  : this.transform(node.items, context);
714
770
  }
715
771
  return { List: result };
@@ -1636,6 +1692,9 @@ class V15ToV16Transformer {
1636
1692
  if (node.unique !== undefined) {
1637
1693
  result.unique = node.unique;
1638
1694
  }
1695
+ if (node.nulls_not_distinct !== undefined) {
1696
+ result.nulls_not_distinct = node.nulls_not_distinct;
1697
+ }
1639
1698
  if (node.primary !== undefined) {
1640
1699
  result.primary = node.primary;
1641
1700
  }
package/dist/README.md DELETED
@@ -1,160 +0,0 @@
1
- # pgsql-deparser
2
-
3
- <p align="center" width="100%">
4
- <img height="120" src="https://github.com/launchql/pgsql-parser/assets/545047/6440fa7d-918b-4a3b-8d1b-755d85de8bea" />
5
- </p>
6
-
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" />
10
- </a>
11
- <a href="https://www.npmjs.com/package/pgsql-deparser"><img height="20" src="https://img.shields.io/npm/dt/pgsql-deparser"></a>
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>
15
- </p>
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.
18
-
19
- ## Installation
20
-
21
- ```sh
22
- npm install pgsql-deparser
23
- ```
24
-
25
- ## Features
26
-
27
- * ⚡ **Pure TypeScript Performance** – Zero runtime dependencies, no WASM, no compilation - just blazing fast SQL generation
28
- * 🪶 **Ultra Lightweight** – Minimal footprint with laser-focused functionality for AST-to-SQL conversion only
29
- * 🧪 **Battle-Tested Reliability** – Validated against 23,000+ SQL statements ensuring production-grade stability
30
- * 🌍 **Universal Compatibility** – Runs anywhere JavaScript does - browsers, Node.js, edge functions, you name it
31
-
32
- ## Deparser Example
33
-
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
-
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`:
37
-
38
- ```ts
39
- import * as t from '@pgsql/utils';
40
- import { RangeVar, SelectStmt } from '@pgsql/types';
41
- import { deparseSync as deparse } from 'pgsql-deparser';
42
-
43
- // This could have been obtained from any JSON or AST, not necessarily @pgsql/utils
44
- const stmt: { SelectStmt: SelectStmt } = t.nodes.selectStmt({
45
- targetList: [
46
- t.nodes.resTarget({
47
- val: t.nodes.columnRef({
48
- fields: [t.nodes.aStar()]
49
- })
50
- })
51
- ],
52
- fromClause: [
53
- t.nodes.rangeVar({
54
- relname: 'some_table',
55
- inh: true,
56
- relpersistence: 'p'
57
- })
58
- ],
59
- limitOption: 'LIMIT_OPTION_DEFAULT',
60
- op: 'SETOP_NONE'
61
- });
62
-
63
- // Modify the AST if needed
64
- (stmt.SelectStmt.fromClause[0] as {RangeVar: RangeVar}).RangeVar.relname = 'another_table';
65
-
66
- // Deparse the modified AST back to a SQL string
67
- console.log(deparse(stmt));
68
-
69
- // Output: SELECT * FROM another_table
70
- ```
71
-
72
- ### Latest Version (PostgreSQL 17)
73
-
74
- ```sh
75
- npm install pgsql-deparser
76
- ```
77
-
78
- ### Version-Specific Packages (PostgreSQL 13-16)
79
-
80
- While we highly recommend using PG17, for PostgreSQL versions 13-16, use the version-specific packages:
81
-
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
87
- ```
88
-
89
- ## Options
90
-
91
- The deparser accepts optional configuration for formatting and output control:
92
-
93
- ```ts
94
- import { deparseSync as deparse } from 'pgsql-deparser';
95
-
96
- const options = {
97
- pretty: true, // Enable pretty formatting (default: false)
98
- newline: '\n', // Newline character (default: '\n')
99
- tab: ' ', // Tab/indentation character (default: ' ')
100
- semicolons: true // Add semicolons to statements (default: true)
101
- };
102
-
103
- const sql = deparse(ast, options);
104
- ```
105
-
106
- | Option | Type | Default | Description |
107
- |--------|------|---------|-------------|
108
- | `pretty` | `boolean` | `false` | Enable pretty formatting with indentation and line breaks |
109
- | `newline` | `string` | `'\n'` | Character(s) used for line breaks |
110
- | `tab` | `string` | `' '` | Character(s) used for indentation |
111
- | `semicolons` | `boolean` | `true` | Add semicolons to SQL statements |
112
-
113
- **Pretty formatting example:**
114
- ```ts
115
- // Without pretty formatting
116
- const sql1 = deparse(selectAst, { pretty: false });
117
- // "SELECT id, name FROM users WHERE active = true;"
118
-
119
- // With pretty formatting
120
- const sql2 = deparse(selectAst, { pretty: true });
121
- // SELECT
122
- // id,
123
- // name
124
- // FROM users
125
- // WHERE
126
- // active = true;
127
- ```
128
-
129
- For complete documentation and advanced options, see [DEPARSER_USAGE.md](../../DEPARSER_USAGE.md).
130
-
131
- ## Why Use `pgsql-deparser`?
132
-
133
- `pgsql-deparser` is particularly useful in development environments where native dependencies are problematic or in applications where only the deparser functionality is required. Its independence from the full `pgsql-parser` package allows for more focused and lightweight SQL generation tasks.
134
-
135
- ## Credits
136
-
137
- Built on the excellent work of several contributors:
138
-
139
- * **[Dan Lynch](https://github.com/pyramation)** — official maintainer since 2018 and architect of the current implementation
140
- * **[Lukas Fittl](https://github.com/lfittl)** for [libpg_query](https://github.com/pganalyze/libpg_query) — the core PostgreSQL parser that powers this project
141
- * **[Greg Richardson](https://github.com/gregnr)** for AST guidance and pushing the transition to WASM and multiple PG runtimes for better interoperability
142
- * **[Ethan Resnick](https://github.com/ethanresnick)** for the original Node.js N-API bindings
143
- * **[Zac McCormick](https://github.com/zhm)** for the foundational [node-pg-query-native](https://github.com/zhm/node-pg-query-native) parser
144
-
145
- ## Related
146
-
147
- * [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.
148
- * [pgsql-deparser](https://www.npmjs.com/package/pgsql-deparser): A streamlined tool designed for converting PostgreSQL ASTs back into SQL queries, focusing solely on deparser functionality to complement `pgsql-parser`.
149
- * [@pgsql/parser](https://www.npmjs.com/package/@pgsql/parser): Multi-version PostgreSQL parser with dynamic version selection at runtime, supporting PostgreSQL 15, 16, and 17 in a single package.
150
- * [@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
- * [@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
- * [@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.
153
- * [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.
155
-
156
- ## Disclaimer
157
-
158
- AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
159
-
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.
@@ -1,21 +0,0 @@
1
- /**
2
- * Auto-generated file with types stripped for better tree-shaking
3
- * DO NOT EDIT - Generated by strip-deparser-types.ts
4
- */
5
- export interface DeparserContext {
6
- isStringLiteral?: boolean;
7
- parentNodeTypes: string[];
8
- [key: string]: any;
9
- }
10
- export interface DeparserVisitor {
11
- visit(node: any, context?: DeparserContext): string;
12
- }
13
- export declare abstract class BaseVisitor implements DeparserVisitor {
14
- abstract visit(node: any, context?: DeparserContext): string;
15
- protected getNodeType(node: any): string;
16
- protected getNodeData(node: any): any;
17
- protected formatList(items: any[], separator: string, prefix: string, formatter: (item: any) => string): string;
18
- protected formatParts(parts: string[], separator?: string): string;
19
- protected formatParens(content: string): string;
20
- protected formatIndent(text: string, count?: number): string;
21
- }
@@ -1,34 +0,0 @@
1
- "use strict";
2
- /**
3
- * Auto-generated file with types stripped for better tree-shaking
4
- * DO NOT EDIT - Generated by strip-deparser-types.ts
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.BaseVisitor = void 0;
8
- class BaseVisitor {
9
- getNodeType(node) {
10
- return Object.keys(node)[0];
11
- }
12
- getNodeData(node) {
13
- const type = this.getNodeType(node);
14
- return node[type];
15
- }
16
- formatList(items, separator = ', ', prefix = '', formatter) {
17
- if (!items || items.length === 0) {
18
- return '';
19
- }
20
- return items
21
- .map(item => `${prefix}${formatter(item)}`)
22
- .join(separator);
23
- }
24
- formatParts(parts, separator = ' ') {
25
- return parts.filter(part => part !== null && part !== undefined && part !== '').join(separator);
26
- }
27
- formatParens(content) {
28
- return `(${content})`;
29
- }
30
- formatIndent(text, count = 1) {
31
- return text;
32
- }
33
- }
34
- exports.BaseVisitor = BaseVisitor;
@@ -1,30 +0,0 @@
1
- /**
2
- * Auto-generated file with types stripped for better tree-shaking
3
- * DO NOT EDIT - Generated by strip-deparser-types.ts
4
- */
5
- export class BaseVisitor {
6
- getNodeType(node) {
7
- return Object.keys(node)[0];
8
- }
9
- getNodeData(node) {
10
- const type = this.getNodeType(node);
11
- return node[type];
12
- }
13
- formatList(items, separator = ', ', prefix = '', formatter) {
14
- if (!items || items.length === 0) {
15
- return '';
16
- }
17
- return items
18
- .map(item => `${prefix}${formatter(item)}`)
19
- .join(separator);
20
- }
21
- formatParts(parts, separator = ' ') {
22
- return parts.filter(part => part !== null && part !== undefined && part !== '').join(separator);
23
- }
24
- formatParens(content) {
25
- return `(${content})`;
26
- }
27
- formatIndent(text, count = 1) {
28
- return text;
29
- }
30
- }
package/dist/package.json DELETED
@@ -1,42 +0,0 @@
1
- {
2
- "author": "Dan Lynch <pyramation@gmail.com>",
3
- "homepage": "https://github.com/launchql/pgsql-parser",
4
- "license": "MIT",
5
- "main": "index.js",
6
- "module": "esm/index.js",
7
- "types": "index.d.ts",
8
- "description": "PostgreSQL AST Deparser",
9
- "scripts": {
10
- "copy": "copyfiles -f ../../../../LICENSE README.md package.json dist",
11
- "clean": "rimraf dist",
12
- "prepare": "npm run build",
13
- "build": "npm run clean && tsc && tsc -p tsconfig.esm.json && npm run copy",
14
- "publish:pkg": "npm publish --tag pg14"
15
- },
16
- "publishConfig": {
17
- "access": "public",
18
- "directory": "dist"
19
- },
20
- "repository": {
21
- "type": "git",
22
- "url": "https://github.com/launchql/pgsql-parser"
23
- },
24
- "bugs": {
25
- "url": "https://github.com/launchql/pgsql-parser/issues"
26
- },
27
- "keywords": [
28
- "sql",
29
- "postgres",
30
- "postgresql",
31
- "pg",
32
- "query",
33
- "ast",
34
- "deparser",
35
- "database"
36
- ],
37
- "name": "pgsql-deparser",
38
- "version": "14.0.0",
39
- "dependencies": {
40
- "@pgsql/types": "^14.1.1"
41
- }
42
- }