pgsql-deparser 13.16.0 → 13.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.
Files changed (50) hide show
  1. package/README.md +94 -45
  2. package/deparser/deparser.d.ts +302 -0
  3. package/deparser/deparser.js +10451 -0
  4. package/deparser/index.d.ts +9 -0
  5. package/deparser/index.js +17 -0
  6. package/deparser/utils/list-utils.d.ts +8 -0
  7. package/deparser/utils/list-utils.js +30 -0
  8. package/deparser/utils/quote-utils.d.ts +24 -0
  9. package/deparser/utils/quote-utils.js +89 -0
  10. package/deparser/utils/sql-formatter.d.ts +16 -0
  11. package/deparser/utils/sql-formatter.js +40 -0
  12. package/deparser/visitors/base.d.ts +68 -0
  13. package/deparser/visitors/base.js +122 -0
  14. package/esm/deparser/deparser.js +10447 -0
  15. package/esm/deparser/index.js +13 -0
  16. package/esm/deparser/utils/list-utils.js +26 -0
  17. package/esm/deparser/utils/quote-utils.js +85 -0
  18. package/esm/deparser/utils/sql-formatter.js +36 -0
  19. package/esm/deparser/visitors/base.js +117 -0
  20. package/esm/index.js +15 -0
  21. package/esm/v13-to-v14.js +2750 -0
  22. package/esm/v13-to-v17-direct.js +78 -0
  23. package/esm/v14-to-v15.js +1223 -0
  24. package/esm/v15-to-v16.js +2940 -0
  25. package/esm/v16-to-v17.js +1488 -0
  26. package/index.d.ts +9 -0
  27. package/index.js +19 -0
  28. package/package.json +26 -75
  29. package/v13-to-v14.d.ts +253 -0
  30. package/v13-to-v14.js +2754 -0
  31. package/v13-to-v17-direct.d.ts +24 -0
  32. package/v13-to-v17-direct.js +82 -0
  33. package/v14-to-v15.d.ts +616 -0
  34. package/v14-to-v15.js +1227 -0
  35. package/v15-to-v16.d.ts +633 -0
  36. package/v15-to-v16.js +2944 -0
  37. package/v16-to-v17.d.ts +638 -0
  38. package/v16-to-v17.js +1492 -0
  39. package/main/deparser.js +0 -3495
  40. package/main/index.js +0 -10
  41. package/main/utils/index.js +0 -97
  42. package/module/deparser.js +0 -3492
  43. package/module/index.js +0 -3
  44. package/module/utils/index.js +0 -90
  45. package/src/deparser.ts +0 -4234
  46. package/src/index.ts +0 -3
  47. package/src/utils/index.ts +0 -92
  48. package/types/deparser.d.ts +0 -119
  49. package/types/index.d.ts +0 -3
  50. package/types/utils/index.d.ts +0 -4
@@ -0,0 +1,13 @@
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 { Deparser } from "./deparser";
6
+ const deparseMethod = Deparser.deparse;
7
+ // Export the original sync version as deparseSync
8
+ export const deparseSync = deparseMethod;
9
+ // Create an async wrapper for deparse
10
+ export const deparse = async (...args) => {
11
+ return deparseMethod(...args);
12
+ };
13
+ export { Deparser };
@@ -0,0 +1,26 @@
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 ListUtils {
6
+ static unwrapList(obj) {
7
+ if (obj === undefined || obj === null) {
8
+ return [];
9
+ }
10
+ if (obj.List !== undefined) {
11
+ return obj.List.items || [];
12
+ }
13
+ if (Array.isArray(obj)) {
14
+ return obj;
15
+ }
16
+ return [obj];
17
+ }
18
+ static formatList(items, separator = ', ', prefix = '', formatter) {
19
+ if (!items || items.length === 0) {
20
+ return '';
21
+ }
22
+ return items
23
+ .map(item => `${prefix}${formatter(item)}`)
24
+ .join(separator);
25
+ }
26
+ }
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Auto-generated file with types stripped for better tree-shaking
3
+ * DO NOT EDIT - Generated by strip-deparser-types.ts
4
+ */
5
+ const RESERVED_WORDS = new Set([
6
+ 'all', 'analyse', 'analyze', 'and', 'any', 'array', 'as', 'asc', 'asymmetric',
7
+ 'authorization', 'binary', 'both', 'case', 'cast', 'check', 'collate', 'collation',
8
+ 'column', 'concurrently', 'constraint', 'create', 'cross', 'current_catalog',
9
+ 'current_date', 'current_role', 'current_schema', 'current_time', 'current_timestamp',
10
+ 'current_user', 'default', 'deferrable', 'desc', 'distinct', 'do', 'else', 'end',
11
+ 'except', 'false', 'fetch', 'for', 'foreign', 'freeze', 'from', 'full', 'grant',
12
+ 'group', 'having', 'ilike', 'in', 'initially', 'inner', 'intersect', 'into', 'is',
13
+ 'isnull', 'join', 'lateral', 'leading', 'left', 'like', 'limit', 'localtime',
14
+ 'localtimestamp', 'natural', 'not', 'notnull', 'null', 'offset', 'on', 'only',
15
+ 'or', 'order', 'outer', 'overlaps', 'placing', 'primary', 'references', 'returning',
16
+ 'right', 'select', 'session_user', 'similar', 'some', 'symmetric', 'table', 'tablesample',
17
+ 'then', 'to', 'trailing', 'true', 'union', 'unique', 'user', 'using', 'variadic',
18
+ 'verbose', 'when', 'where', 'window', 'with'
19
+ ]);
20
+ export class QuoteUtils {
21
+ static needsQuotes(value) {
22
+ if (!value || typeof value !== 'string') {
23
+ return false;
24
+ }
25
+ const lowerValue = value.toLowerCase();
26
+ if (RESERVED_WORDS.has(lowerValue)) {
27
+ return true;
28
+ }
29
+ if (!/^[a-z_][a-z0-9_$]*$/i.test(value)) {
30
+ return true;
31
+ }
32
+ if (value !== value.toLowerCase()) {
33
+ return true;
34
+ }
35
+ return false;
36
+ }
37
+ static quote(value) {
38
+ if (value == null) {
39
+ return null;
40
+ }
41
+ if (Array.isArray(value)) {
42
+ return value.map(v => this.quote(v));
43
+ }
44
+ if (typeof value !== 'string') {
45
+ return value;
46
+ }
47
+ if (this.needsQuotes(value)) {
48
+ return `"${value}"`;
49
+ }
50
+ return value;
51
+ }
52
+ static escape(literal) {
53
+ return `'${literal.replace(/'/g, "''")}'`;
54
+ }
55
+ /**
56
+ * Escapes a string value for use in E-prefixed string literals
57
+ * Handles both backslashes and single quotes properly
58
+ */
59
+ static escapeEString(value) {
60
+ return value.replace(/\\/g, '\\\\').replace(/'/g, "''");
61
+ }
62
+ /**
63
+ * Formats a string as an E-prefixed string literal with proper escaping
64
+ * This wraps the complete E-prefix logic including detection and formatting
65
+ */
66
+ static formatEString(value) {
67
+ const needsEscape = QuoteUtils.needsEscapePrefix(value);
68
+ if (needsEscape) {
69
+ const escapedValue = QuoteUtils.escapeEString(value);
70
+ return `E'${escapedValue}'`;
71
+ }
72
+ else {
73
+ return QuoteUtils.escape(value);
74
+ }
75
+ }
76
+ /**
77
+ * Determines if a string value needs E-prefix for escaped string literals
78
+ * Detects backslash escape sequences that require E-prefix in PostgreSQL
79
+ */
80
+ static needsEscapePrefix(value) {
81
+ // Always use E'' if the string contains any backslashes,
82
+ // unless it's a raw \x... bytea-style literal.
83
+ return !/^\\x[0-9a-fA-F]+$/i.test(value) && value.includes('\\');
84
+ }
85
+ }
@@ -0,0 +1,36 @@
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 SqlFormatter {
6
+ newlineChar;
7
+ tabChar;
8
+ prettyMode;
9
+ constructor(newlineChar = '\n', tabChar = ' ', prettyMode = true) {
10
+ this.newlineChar = newlineChar;
11
+ this.tabChar = tabChar;
12
+ this.prettyMode = prettyMode;
13
+ }
14
+ format(parts, separator = ' ') {
15
+ return parts.filter(part => part !== null && part !== undefined && part !== '').join(separator);
16
+ }
17
+ indent(text, count = 1) {
18
+ if (!this.prettyMode) {
19
+ return text;
20
+ }
21
+ const indentation = this.tabChar.repeat(count);
22
+ return text.split(this.newlineChar).map(line => line.trim() ? indentation + line : line).join(this.newlineChar);
23
+ }
24
+ parens(content) {
25
+ return `(${content})`;
26
+ }
27
+ newline() {
28
+ return this.newlineChar;
29
+ }
30
+ tab() {
31
+ return this.tabChar;
32
+ }
33
+ isPretty() {
34
+ return this.prettyMode;
35
+ }
36
+ }
@@ -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
+ }
package/esm/index.js ADDED
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Deparser for PostgreSQL version 13
3
+ * Auto-generated by generate-version-deparsers.ts
4
+ */
5
+ import { deparse as deparse17, deparseSync as deparseSync17 } from './deparser';
6
+ import { PG13ToPG17Transformer } from './v13-to-v17-direct';
7
+ const tx = new PG13ToPG17Transformer();
8
+ export async function deparse(query, opts) {
9
+ const ast17 = tx.transform(query);
10
+ return await deparse17(ast17, opts);
11
+ }
12
+ export function deparseSync(query, opts) {
13
+ const ast17 = tx.transform(query);
14
+ return deparseSync17(ast17, opts);
15
+ }