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