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 +9 -9
- package/deparser/deparser.d.ts +311 -0
- package/{deparser.js → deparser/deparser.js} +941 -586
- package/deparser/index.d.ts +11 -0
- package/deparser/index.js +21 -0
- package/{utils → deparser/utils}/list-utils.d.ts +4 -0
- package/{utils → deparser/utils}/list-utils.js +4 -0
- package/deparser/utils/sql-formatter.d.ts +24 -0
- package/deparser/utils/sql-formatter.js +143 -0
- package/{visitors → deparser/visitors}/base.d.ts +8 -5
- package/{visitors → deparser/visitors}/base.js +4 -0
- package/esm/{deparser.js → deparser/deparser.js} +942 -587
- package/esm/deparser/index.js +15 -0
- package/esm/{utils → deparser/utils}/list-utils.js +4 -0
- package/esm/deparser/utils/sql-formatter.js +138 -0
- package/esm/{visitors → deparser/visitors}/base.js +4 -0
- package/esm/index.js +23 -9
- package/esm/v17-to-v18-direct.js +43 -0
- package/esm/v17-to-v18.js +209 -0
- package/index.d.ts +15 -5
- package/index.js +27 -10
- package/package.json +14 -36
- package/v17-to-v18-direct.d.ts +21 -0
- package/v17-to-v18-direct.js +47 -0
- package/v17-to-v18.d.ts +55 -0
- package/v17-to-v18.js +213 -0
- package/deparser.d.ts +0 -305
- package/esm/utils/sql-formatter.js +0 -32
- package/utils/sql-formatter.d.ts +0 -12
- package/utils/sql-formatter.js +0 -36
|
@@ -0,0 +1,11 @@
|
|
|
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, DeparserOptions } from './deparser';
|
|
6
|
+
declare const deparseMethod: typeof Deparser.deparse;
|
|
7
|
+
export declare const deparseSync: typeof Deparser.deparse;
|
|
8
|
+
export declare const deparse: (...args: Parameters<typeof deparseMethod>) => Promise<ReturnType<typeof deparseMethod>>;
|
|
9
|
+
export { Deparser, DeparserOptions };
|
|
10
|
+
export { splitSqlLines } from './utils/sql-formatter';
|
|
11
|
+
export { QuoteUtils } from '@pgsql/quotes';
|
|
@@ -0,0 +1,21 @@
|
|
|
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.QuoteUtils = exports.splitSqlLines = exports.Deparser = exports.deparse = exports.deparseSync = void 0;
|
|
8
|
+
const deparser_1 = require("./deparser");
|
|
9
|
+
Object.defineProperty(exports, "Deparser", { enumerable: true, get: function () { return deparser_1.Deparser; } });
|
|
10
|
+
const deparseMethod = deparser_1.Deparser.deparse;
|
|
11
|
+
// Export the original sync version as deparseSync
|
|
12
|
+
exports.deparseSync = deparseMethod;
|
|
13
|
+
// Create an async wrapper for deparse
|
|
14
|
+
const deparse = async (...args) => {
|
|
15
|
+
return deparseMethod(...args);
|
|
16
|
+
};
|
|
17
|
+
exports.deparse = deparse;
|
|
18
|
+
var sql_formatter_1 = require("./utils/sql-formatter");
|
|
19
|
+
Object.defineProperty(exports, "splitSqlLines", { enumerable: true, get: function () { return sql_formatter_1.splitSqlLines; } });
|
|
20
|
+
var quotes_1 = require("@pgsql/quotes");
|
|
21
|
+
Object.defineProperty(exports, "QuoteUtils", { enumerable: true, get: function () { return quotes_1.QuoteUtils; } });
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auto-generated file with types stripped for better tree-shaking
|
|
3
|
+
* DO NOT EDIT - Generated by strip-deparser-types.ts
|
|
4
|
+
*/
|
|
1
5
|
export declare class ListUtils {
|
|
2
6
|
static unwrapList(obj: any): any[];
|
|
3
7
|
static formatList(items: any[], separator: string, prefix: string, formatter: (item: any) => string): string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auto-generated file with types stripped for better tree-shaking
|
|
3
|
+
* DO NOT EDIT - Generated by strip-deparser-types.ts
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Splits SQL text into lines, breaking only at newlines that sit between
|
|
7
|
+
* tokens. A newline inside a string literal ('...', E'...', $tag$...$tag$),
|
|
8
|
+
* a quoted identifier or a block comment is part of that token's value and
|
|
9
|
+
* stays inside its line, so callers can re-indent the lines without changing
|
|
10
|
+
* what the SQL means.
|
|
11
|
+
*/
|
|
12
|
+
export declare function splitSqlLines(text: string, newlineChar?: string): string[];
|
|
13
|
+
export declare class SqlFormatter {
|
|
14
|
+
private newlineChar;
|
|
15
|
+
private tabChar;
|
|
16
|
+
private prettyMode;
|
|
17
|
+
constructor(newlineChar?: string, tabChar?: string, prettyMode?: boolean);
|
|
18
|
+
format(parts: string[], separator?: string): string;
|
|
19
|
+
indent(text: string, count?: number): string;
|
|
20
|
+
parens(content: string): string;
|
|
21
|
+
newline(): string;
|
|
22
|
+
tab(): string;
|
|
23
|
+
isPretty(): boolean;
|
|
24
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
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.SqlFormatter = void 0;
|
|
8
|
+
exports.splitSqlLines = splitSqlLines;
|
|
9
|
+
const isIdentChar = (ch) => ch !== undefined && (/[A-Za-z0-9_$]/.test(ch) || ch.charCodeAt(0) >= 0x80);
|
|
10
|
+
const DOLLAR_TAG = /\$(?:[A-Za-z_\u0080-\uffff][A-Za-z0-9_\u0080-\uffff]*)?\$/y;
|
|
11
|
+
/**
|
|
12
|
+
* Splits SQL text into lines, breaking only at newlines that sit between
|
|
13
|
+
* tokens. A newline inside a string literal ('...', E'...', $tag$...$tag$),
|
|
14
|
+
* a quoted identifier or a block comment is part of that token's value and
|
|
15
|
+
* stays inside its line, so callers can re-indent the lines without changing
|
|
16
|
+
* what the SQL means.
|
|
17
|
+
*/
|
|
18
|
+
function splitSqlLines(text, newlineChar = '\n') {
|
|
19
|
+
if (!newlineChar || !text.includes(newlineChar)) {
|
|
20
|
+
return [text];
|
|
21
|
+
}
|
|
22
|
+
const lines = [];
|
|
23
|
+
const length = text.length;
|
|
24
|
+
let lineStart = 0;
|
|
25
|
+
let i = 0;
|
|
26
|
+
while (i < length) {
|
|
27
|
+
const ch = text[i];
|
|
28
|
+
if (ch === "'") {
|
|
29
|
+
const prev = text[i - 1];
|
|
30
|
+
const backslashEscapes = (prev === 'E' || prev === 'e') && !isIdentChar(text[i - 2]);
|
|
31
|
+
i++;
|
|
32
|
+
while (i < length) {
|
|
33
|
+
if (backslashEscapes && text[i] === '\\') {
|
|
34
|
+
i += 2;
|
|
35
|
+
}
|
|
36
|
+
else if (text[i] === "'") {
|
|
37
|
+
if (text[i + 1] === "'") {
|
|
38
|
+
i += 2;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
i++;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
i++;
|
|
49
|
+
}
|
|
50
|
+
else if (ch === '"') {
|
|
51
|
+
i++;
|
|
52
|
+
while (i < length) {
|
|
53
|
+
if (text[i] === '"') {
|
|
54
|
+
if (text[i + 1] === '"') {
|
|
55
|
+
i += 2;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
i++;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
i++;
|
|
66
|
+
}
|
|
67
|
+
else if (ch === '$' && !isIdentChar(text[i - 1])) {
|
|
68
|
+
DOLLAR_TAG.lastIndex = i;
|
|
69
|
+
const tag = DOLLAR_TAG.exec(text);
|
|
70
|
+
if (tag) {
|
|
71
|
+
const close = text.indexOf(tag[0], i + tag[0].length);
|
|
72
|
+
i = close === -1 ? length : close + tag[0].length;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
i++;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else if (ch === '-' && text[i + 1] === '-') {
|
|
79
|
+
const end = text.indexOf('\n', i);
|
|
80
|
+
i = end === -1 ? length : end;
|
|
81
|
+
}
|
|
82
|
+
else if (ch === '/' && text[i + 1] === '*') {
|
|
83
|
+
let depth = 1;
|
|
84
|
+
i += 2;
|
|
85
|
+
while (i < length && depth > 0) {
|
|
86
|
+
if (text[i] === '/' && text[i + 1] === '*') {
|
|
87
|
+
depth++;
|
|
88
|
+
i += 2;
|
|
89
|
+
}
|
|
90
|
+
else if (text[i] === '*' && text[i + 1] === '/') {
|
|
91
|
+
depth--;
|
|
92
|
+
i += 2;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
i++;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
else if (text.startsWith(newlineChar, i)) {
|
|
100
|
+
lines.push(text.slice(lineStart, i));
|
|
101
|
+
i += newlineChar.length;
|
|
102
|
+
lineStart = i;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
i++;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
lines.push(text.slice(lineStart));
|
|
109
|
+
return lines;
|
|
110
|
+
}
|
|
111
|
+
class SqlFormatter {
|
|
112
|
+
newlineChar;
|
|
113
|
+
tabChar;
|
|
114
|
+
prettyMode;
|
|
115
|
+
constructor(newlineChar = '\n', tabChar = ' ', prettyMode = true) {
|
|
116
|
+
this.newlineChar = newlineChar;
|
|
117
|
+
this.tabChar = tabChar;
|
|
118
|
+
this.prettyMode = prettyMode;
|
|
119
|
+
}
|
|
120
|
+
format(parts, separator = ' ') {
|
|
121
|
+
return parts.filter(part => part !== null && part !== undefined && part !== '').join(separator);
|
|
122
|
+
}
|
|
123
|
+
indent(text, count = 1) {
|
|
124
|
+
if (!this.prettyMode) {
|
|
125
|
+
return text;
|
|
126
|
+
}
|
|
127
|
+
const indentation = this.tabChar.repeat(count);
|
|
128
|
+
return splitSqlLines(text, this.newlineChar).map(line => line.trim() ? indentation + line : line).join(this.newlineChar);
|
|
129
|
+
}
|
|
130
|
+
parens(content) {
|
|
131
|
+
return `(${content})`;
|
|
132
|
+
}
|
|
133
|
+
newline() {
|
|
134
|
+
return this.newlineChar;
|
|
135
|
+
}
|
|
136
|
+
tab() {
|
|
137
|
+
return this.tabChar;
|
|
138
|
+
}
|
|
139
|
+
isPretty() {
|
|
140
|
+
return this.prettyMode;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
exports.SqlFormatter = SqlFormatter;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Auto-generated file with types stripped for better tree-shaking
|
|
3
|
+
* DO NOT EDIT - Generated by strip-deparser-types.ts
|
|
4
|
+
*/
|
|
2
5
|
import { SqlFormatter } from '../utils/sql-formatter';
|
|
3
6
|
export interface DeparserContextOptions {
|
|
4
7
|
isStringLiteral?: boolean;
|
|
@@ -52,12 +55,12 @@ export declare class DeparserContext {
|
|
|
52
55
|
isPretty(): boolean;
|
|
53
56
|
}
|
|
54
57
|
export interface DeparserVisitor {
|
|
55
|
-
visit(node:
|
|
58
|
+
visit(node: any, context?: DeparserContext): string;
|
|
56
59
|
}
|
|
57
60
|
export declare abstract class BaseVisitor implements DeparserVisitor {
|
|
58
|
-
abstract visit(node:
|
|
59
|
-
protected getNodeType(node:
|
|
60
|
-
protected getNodeData(node:
|
|
61
|
+
abstract visit(node: any, context?: DeparserContext): string;
|
|
62
|
+
protected getNodeType(node: any): string;
|
|
63
|
+
protected getNodeData(node: any): any;
|
|
61
64
|
protected formatList(items: any[], separator: string, prefix: string, formatter: (item: any) => string): string;
|
|
62
65
|
protected formatParts(parts: string[], separator?: string): string;
|
|
63
66
|
protected formatParens(content: string): string;
|
|
@@ -1,4 +1,8 @@
|
|
|
1
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
|
+
*/
|
|
2
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
7
|
exports.BaseVisitor = exports.DeparserContext = void 0;
|
|
4
8
|
const sql_formatter_1 = require("../utils/sql-formatter");
|