pgsql-deparser 17.8.1 → 17.8.3

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.
@@ -1,3 +1,90 @@
1
+ import { SqlFormatter } from '../utils/sql-formatter';
2
+ export class DeparserContext {
3
+ indentLevel;
4
+ prettyMode;
5
+ isStringLiteral;
6
+ parentNodeTypes;
7
+ formatter;
8
+ select;
9
+ from;
10
+ group;
11
+ sort;
12
+ insertColumns;
13
+ update;
14
+ bool;
15
+ isColumnConstraint;
16
+ isDomainConstraint;
17
+ alterColumnOptions;
18
+ alterTableOptions;
19
+ isEnumValue;
20
+ objtype;
21
+ subtype;
22
+ constructor({ indentLevel = 0, prettyMode = false, isStringLiteral, parentNodeTypes = [], formatter, select, from, group, sort, insertColumns, update, bool, isColumnConstraint, isDomainConstraint, alterColumnOptions, alterTableOptions, isEnumValue, objtype, subtype, ...rest } = {}) {
23
+ this.indentLevel = indentLevel;
24
+ this.prettyMode = prettyMode;
25
+ this.isStringLiteral = isStringLiteral;
26
+ this.parentNodeTypes = parentNodeTypes;
27
+ this.formatter = formatter || new SqlFormatter('\n', ' ', prettyMode);
28
+ this.select = select;
29
+ this.from = from;
30
+ this.group = group;
31
+ this.sort = sort;
32
+ this.insertColumns = insertColumns;
33
+ this.update = update;
34
+ this.bool = bool;
35
+ this.isColumnConstraint = isColumnConstraint;
36
+ this.isDomainConstraint = isDomainConstraint;
37
+ this.alterColumnOptions = alterColumnOptions;
38
+ this.alterTableOptions = alterTableOptions;
39
+ this.isEnumValue = isEnumValue;
40
+ this.objtype = objtype;
41
+ this.subtype = subtype;
42
+ Object.assign(this, rest);
43
+ }
44
+ spawn(nodeType, overrides = {}) {
45
+ return new DeparserContext({
46
+ indentLevel: this.indentLevel,
47
+ prettyMode: this.prettyMode,
48
+ isStringLiteral: this.isStringLiteral,
49
+ parentNodeTypes: [...this.parentNodeTypes, nodeType],
50
+ formatter: this.formatter,
51
+ select: this.select,
52
+ from: this.from,
53
+ group: this.group,
54
+ sort: this.sort,
55
+ insertColumns: this.insertColumns,
56
+ update: this.update,
57
+ bool: this.bool,
58
+ isColumnConstraint: this.isColumnConstraint,
59
+ isDomainConstraint: this.isDomainConstraint,
60
+ alterColumnOptions: this.alterColumnOptions,
61
+ alterTableOptions: this.alterTableOptions,
62
+ isEnumValue: this.isEnumValue,
63
+ objtype: this.objtype,
64
+ subtype: this.subtype,
65
+ ...overrides,
66
+ });
67
+ }
68
+ indent(text, count) {
69
+ if (!this.prettyMode) {
70
+ return text;
71
+ }
72
+ const indentCount = count !== undefined ? count : this.indentLevel + 1;
73
+ return this.formatter.indent(text, indentCount);
74
+ }
75
+ newline() {
76
+ return this.formatter.newline();
77
+ }
78
+ parens(content) {
79
+ return this.formatter.parens(content);
80
+ }
81
+ format(parts, separator) {
82
+ return this.formatter.format(parts, separator);
83
+ }
84
+ isPretty() {
85
+ return this.formatter.isPretty();
86
+ }
87
+ }
1
88
  export class BaseVisitor {
2
89
  getNodeType(node) {
3
90
  return Object.keys(node)[0];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pgsql-deparser",
3
- "version": "17.8.1",
3
+ "version": "17.8.3",
4
4
  "author": "Dan Lynch <pyramation@gmail.com>",
5
5
  "description": "PostgreSQL AST Deparser",
6
6
  "main": "index.js",
@@ -46,10 +46,10 @@
46
46
  "database"
47
47
  ],
48
48
  "devDependencies": {
49
- "libpg-query": "17.5.2"
49
+ "libpg-query": "17.5.5"
50
50
  },
51
51
  "dependencies": {
52
52
  "@pgsql/types": "^17.6.1"
53
53
  },
54
- "gitHead": "cffd419f76ad6975c89e7e4f79972f7f27b0eab7"
54
+ "gitHead": "de35365d6a05e91c77c04dea213d5aadfa8b19a6"
55
55
  }
@@ -1,9 +1,56 @@
1
1
  import { Node } from '@pgsql/types';
2
- export interface DeparserContext {
2
+ import { SqlFormatter } from '../utils/sql-formatter';
3
+ export interface DeparserContextOptions {
3
4
  isStringLiteral?: boolean;
4
- parentNodeTypes: string[];
5
+ parentNodeTypes?: string[];
6
+ indentLevel?: number;
7
+ prettyMode?: boolean;
8
+ formatter?: SqlFormatter;
9
+ select?: boolean;
10
+ from?: boolean;
11
+ group?: boolean;
12
+ sort?: boolean;
13
+ insertColumns?: boolean;
14
+ update?: boolean;
15
+ bool?: boolean;
16
+ isColumnConstraint?: boolean;
17
+ isDomainConstraint?: boolean;
18
+ alterColumnOptions?: boolean;
19
+ alterTableOptions?: boolean;
20
+ isEnumValue?: boolean;
21
+ objtype?: string;
22
+ subtype?: string;
5
23
  [key: string]: any;
6
24
  }
25
+ export declare class DeparserContext {
26
+ readonly indentLevel: number;
27
+ readonly prettyMode: boolean;
28
+ readonly isStringLiteral?: boolean;
29
+ readonly parentNodeTypes: string[];
30
+ private readonly formatter;
31
+ readonly select?: boolean;
32
+ readonly from?: boolean;
33
+ readonly group?: boolean;
34
+ readonly sort?: boolean;
35
+ readonly insertColumns?: boolean;
36
+ readonly update?: boolean;
37
+ readonly bool?: boolean;
38
+ readonly isColumnConstraint?: boolean;
39
+ readonly isDomainConstraint?: boolean;
40
+ readonly alterColumnOptions?: boolean;
41
+ readonly alterTableOptions?: boolean;
42
+ readonly isEnumValue?: boolean;
43
+ readonly objtype?: string;
44
+ readonly subtype?: string;
45
+ readonly [key: string]: any;
46
+ constructor({ indentLevel, prettyMode, isStringLiteral, parentNodeTypes, formatter, select, from, group, sort, insertColumns, update, bool, isColumnConstraint, isDomainConstraint, alterColumnOptions, alterTableOptions, isEnumValue, objtype, subtype, ...rest }?: DeparserContextOptions);
47
+ spawn(nodeType: string, overrides?: Partial<DeparserContextOptions>): DeparserContext;
48
+ indent(text: string, count?: number): string;
49
+ newline(): string;
50
+ parens(content: string): string;
51
+ format(parts: string[], separator?: string): string;
52
+ isPretty(): boolean;
53
+ }
7
54
  export interface DeparserVisitor {
8
55
  visit(node: Node, context?: DeparserContext): string;
9
56
  }
package/visitors/base.js CHANGED
@@ -1,6 +1,94 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseVisitor = void 0;
3
+ exports.BaseVisitor = exports.DeparserContext = void 0;
4
+ const sql_formatter_1 = require("../utils/sql-formatter");
5
+ class DeparserContext {
6
+ indentLevel;
7
+ prettyMode;
8
+ isStringLiteral;
9
+ parentNodeTypes;
10
+ formatter;
11
+ select;
12
+ from;
13
+ group;
14
+ sort;
15
+ insertColumns;
16
+ update;
17
+ bool;
18
+ isColumnConstraint;
19
+ isDomainConstraint;
20
+ alterColumnOptions;
21
+ alterTableOptions;
22
+ isEnumValue;
23
+ objtype;
24
+ subtype;
25
+ constructor({ indentLevel = 0, prettyMode = false, isStringLiteral, parentNodeTypes = [], formatter, select, from, group, sort, insertColumns, update, bool, isColumnConstraint, isDomainConstraint, alterColumnOptions, alterTableOptions, isEnumValue, objtype, subtype, ...rest } = {}) {
26
+ this.indentLevel = indentLevel;
27
+ this.prettyMode = prettyMode;
28
+ this.isStringLiteral = isStringLiteral;
29
+ this.parentNodeTypes = parentNodeTypes;
30
+ this.formatter = formatter || new sql_formatter_1.SqlFormatter('\n', ' ', prettyMode);
31
+ this.select = select;
32
+ this.from = from;
33
+ this.group = group;
34
+ this.sort = sort;
35
+ this.insertColumns = insertColumns;
36
+ this.update = update;
37
+ this.bool = bool;
38
+ this.isColumnConstraint = isColumnConstraint;
39
+ this.isDomainConstraint = isDomainConstraint;
40
+ this.alterColumnOptions = alterColumnOptions;
41
+ this.alterTableOptions = alterTableOptions;
42
+ this.isEnumValue = isEnumValue;
43
+ this.objtype = objtype;
44
+ this.subtype = subtype;
45
+ Object.assign(this, rest);
46
+ }
47
+ spawn(nodeType, overrides = {}) {
48
+ return new DeparserContext({
49
+ indentLevel: this.indentLevel,
50
+ prettyMode: this.prettyMode,
51
+ isStringLiteral: this.isStringLiteral,
52
+ parentNodeTypes: [...this.parentNodeTypes, nodeType],
53
+ formatter: this.formatter,
54
+ select: this.select,
55
+ from: this.from,
56
+ group: this.group,
57
+ sort: this.sort,
58
+ insertColumns: this.insertColumns,
59
+ update: this.update,
60
+ bool: this.bool,
61
+ isColumnConstraint: this.isColumnConstraint,
62
+ isDomainConstraint: this.isDomainConstraint,
63
+ alterColumnOptions: this.alterColumnOptions,
64
+ alterTableOptions: this.alterTableOptions,
65
+ isEnumValue: this.isEnumValue,
66
+ objtype: this.objtype,
67
+ subtype: this.subtype,
68
+ ...overrides,
69
+ });
70
+ }
71
+ indent(text, count) {
72
+ if (!this.prettyMode) {
73
+ return text;
74
+ }
75
+ const indentCount = count !== undefined ? count : this.indentLevel + 1;
76
+ return this.formatter.indent(text, indentCount);
77
+ }
78
+ newline() {
79
+ return this.formatter.newline();
80
+ }
81
+ parens(content) {
82
+ return this.formatter.parens(content);
83
+ }
84
+ format(parts, separator) {
85
+ return this.formatter.format(parts, separator);
86
+ }
87
+ isPretty() {
88
+ return this.formatter.isPretty();
89
+ }
90
+ }
91
+ exports.DeparserContext = DeparserContext;
4
92
  class BaseVisitor {
5
93
  getNodeType(node) {
6
94
  return Object.keys(node)[0];