pgsql-deparser 18.1.1 → 18.3.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/deparser.d.ts +1 -1
- package/deparser.js +36 -22
- package/esm/deparser.js +36 -22
- package/esm/index.js +1 -1
- package/index.d.ts +1 -1
- package/package.json +3 -3
package/deparser.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Node } from '@pgsql/types';
|
|
2
|
-
import { DeparserContext, DeparserVisitor } from './visitors/base';
|
|
3
2
|
import * as t from '@pgsql/types';
|
|
3
|
+
import { DeparserContext, DeparserVisitor } from './visitors/base';
|
|
4
4
|
export interface DeparserOptions {
|
|
5
5
|
newline?: string;
|
|
6
6
|
tab?: string;
|
package/deparser.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Deparser = void 0;
|
|
4
|
-
const base_1 = require("./visitors/base");
|
|
5
|
-
const sql_formatter_1 = require("./utils/sql-formatter");
|
|
6
4
|
const quotes_1 = require("@pgsql/quotes");
|
|
7
5
|
const list_utils_1 = require("./utils/list-utils");
|
|
6
|
+
const sql_formatter_1 = require("./utils/sql-formatter");
|
|
7
|
+
const base_1 = require("./visitors/base");
|
|
8
8
|
/**
|
|
9
9
|
* List of real PostgreSQL built-in types as they appear in pg_catalog.pg_type.typname.
|
|
10
10
|
* These are stored in lowercase in PostgreSQL system catalogs.
|
|
@@ -846,15 +846,15 @@ class Deparser {
|
|
|
846
846
|
getOperatorPrecedence(operator) {
|
|
847
847
|
const precedence = {
|
|
848
848
|
'||': 1, // string concatenation
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
849
|
+
OR: 2, // logical OR
|
|
850
|
+
AND: 3, // logical AND
|
|
851
|
+
NOT: 4, // logical NOT
|
|
852
|
+
IS: 5, // IS NULL, IS NOT NULL, etc.
|
|
853
|
+
IN: 5, // IN, NOT IN
|
|
854
|
+
BETWEEN: 5, // BETWEEN, NOT BETWEEN
|
|
855
|
+
LIKE: 5, // LIKE, ILIKE, SIMILAR TO
|
|
856
|
+
ILIKE: 5,
|
|
857
|
+
SIMILAR: 5,
|
|
858
858
|
'<': 6, // comparison operators
|
|
859
859
|
'<=': 6,
|
|
860
860
|
'>': 6,
|
|
@@ -2331,16 +2331,16 @@ class Deparser {
|
|
|
2331
2331
|
}
|
|
2332
2332
|
preserveOperatorDefElemCase(defName) {
|
|
2333
2333
|
const caseMap = {
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2334
|
+
leftarg: 'Leftarg',
|
|
2335
|
+
rightarg: 'Rightarg',
|
|
2336
|
+
procedure: 'Procedure',
|
|
2337
|
+
function: 'Function',
|
|
2338
|
+
commutator: 'Commutator',
|
|
2339
|
+
negator: 'Negator',
|
|
2340
|
+
restrict: 'Restrict',
|
|
2341
|
+
join: 'Join',
|
|
2342
|
+
hashes: 'Hashes',
|
|
2343
|
+
merges: 'Merges'
|
|
2344
2344
|
};
|
|
2345
2345
|
return caseMap[defName.toLowerCase()] || defName;
|
|
2346
2346
|
}
|
|
@@ -2576,7 +2576,7 @@ class Deparser {
|
|
|
2576
2576
|
Constraint(node, context) {
|
|
2577
2577
|
const output = [];
|
|
2578
2578
|
// Handle constraint name if present
|
|
2579
|
-
if (node.conname && (node.contype === 'CONSTR_CHECK' || node.contype === 'CONSTR_UNIQUE' || node.contype === 'CONSTR_PRIMARY' || node.contype === 'CONSTR_FOREIGN' || node.contype === 'CONSTR_NOTNULL')) {
|
|
2579
|
+
if (node.conname && (node.contype === 'CONSTR_CHECK' || node.contype === 'CONSTR_UNIQUE' || node.contype === 'CONSTR_PRIMARY' || node.contype === 'CONSTR_FOREIGN' || node.contype === 'CONSTR_NOTNULL' || node.contype === 'CONSTR_EXCLUSION')) {
|
|
2580
2580
|
output.push('CONSTRAINT');
|
|
2581
2581
|
output.push(quotes_1.QuoteUtils.quoteIdentifier(node.conname));
|
|
2582
2582
|
}
|
|
@@ -5339,6 +5339,7 @@ class Deparser {
|
|
|
5339
5339
|
if (bodyType === 'List') {
|
|
5340
5340
|
const statements = list_utils_1.ListUtils.unwrapList(node.sql_body);
|
|
5341
5341
|
if (statements.length === 0 || (statements.length === 1 && Object.keys(statements[0]).length === 0)) {
|
|
5342
|
+
// empty body: nothing to emit
|
|
5342
5343
|
}
|
|
5343
5344
|
else {
|
|
5344
5345
|
// Handle nested List structure in BEGIN ATOMIC blocks
|
|
@@ -7769,6 +7770,15 @@ class Deparser {
|
|
|
7769
7770
|
output.push(this.visit(node.object, context));
|
|
7770
7771
|
}
|
|
7771
7772
|
}
|
|
7773
|
+
else if ((node.renameType === 'OBJECT_TYPE' || node.renameType === 'OBJECT_DOMAIN') && node.object.List) {
|
|
7774
|
+
// Qualified type names - join List parts with dots
|
|
7775
|
+
const items = list_utils_1.ListUtils.unwrapList(node.object);
|
|
7776
|
+
const parts = items
|
|
7777
|
+
.map((item) => item.String?.sval)
|
|
7778
|
+
.filter((s) => typeof s === 'string')
|
|
7779
|
+
.map((s) => this.quoteIfNeeded(s));
|
|
7780
|
+
output.push(parts.join('.'));
|
|
7781
|
+
}
|
|
7772
7782
|
else if (node.renameType === 'OBJECT_SCHEMA' && node.object.List) {
|
|
7773
7783
|
// Handle schema names - extract from List structure
|
|
7774
7784
|
const items = list_utils_1.ListUtils.unwrapList(node.object);
|
|
@@ -7908,6 +7918,9 @@ class Deparser {
|
|
|
7908
7918
|
else if (node.objtype === 'OBJECT_LANGUAGE') {
|
|
7909
7919
|
output.push('LANGUAGE');
|
|
7910
7920
|
}
|
|
7921
|
+
else if (node.objtype === 'OBJECT_SEQUENCE') {
|
|
7922
|
+
output.push('SEQUENCE');
|
|
7923
|
+
}
|
|
7911
7924
|
else if (node.objtype === 'OBJECT_FUNCTION') {
|
|
7912
7925
|
output.push('FUNCTION');
|
|
7913
7926
|
}
|
|
@@ -10035,6 +10048,7 @@ class Deparser {
|
|
|
10035
10048
|
rootParts.push('STANDALONE NO VALUE');
|
|
10036
10049
|
}
|
|
10037
10050
|
else if (standaloneArg.A_Const.ival.ival === 3) {
|
|
10051
|
+
// STANDALONE omitted
|
|
10038
10052
|
}
|
|
10039
10053
|
else if (Object.keys(standaloneArg.A_Const.ival).length === 0) {
|
|
10040
10054
|
rootParts.push('STANDALONE YES');
|
package/esm/deparser.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { DeparserContext } from './visitors/base';
|
|
2
|
-
import { SqlFormatter } from './utils/sql-formatter';
|
|
3
1
|
import { QuoteUtils } from '@pgsql/quotes';
|
|
4
2
|
import { ListUtils } from './utils/list-utils';
|
|
3
|
+
import { SqlFormatter } from './utils/sql-formatter';
|
|
4
|
+
import { DeparserContext } from './visitors/base';
|
|
5
5
|
/**
|
|
6
6
|
* List of real PostgreSQL built-in types as they appear in pg_catalog.pg_type.typname.
|
|
7
7
|
* These are stored in lowercase in PostgreSQL system catalogs.
|
|
@@ -843,15 +843,15 @@ export class Deparser {
|
|
|
843
843
|
getOperatorPrecedence(operator) {
|
|
844
844
|
const precedence = {
|
|
845
845
|
'||': 1, // string concatenation
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
846
|
+
OR: 2, // logical OR
|
|
847
|
+
AND: 3, // logical AND
|
|
848
|
+
NOT: 4, // logical NOT
|
|
849
|
+
IS: 5, // IS NULL, IS NOT NULL, etc.
|
|
850
|
+
IN: 5, // IN, NOT IN
|
|
851
|
+
BETWEEN: 5, // BETWEEN, NOT BETWEEN
|
|
852
|
+
LIKE: 5, // LIKE, ILIKE, SIMILAR TO
|
|
853
|
+
ILIKE: 5,
|
|
854
|
+
SIMILAR: 5,
|
|
855
855
|
'<': 6, // comparison operators
|
|
856
856
|
'<=': 6,
|
|
857
857
|
'>': 6,
|
|
@@ -2328,16 +2328,16 @@ export class Deparser {
|
|
|
2328
2328
|
}
|
|
2329
2329
|
preserveOperatorDefElemCase(defName) {
|
|
2330
2330
|
const caseMap = {
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2331
|
+
leftarg: 'Leftarg',
|
|
2332
|
+
rightarg: 'Rightarg',
|
|
2333
|
+
procedure: 'Procedure',
|
|
2334
|
+
function: 'Function',
|
|
2335
|
+
commutator: 'Commutator',
|
|
2336
|
+
negator: 'Negator',
|
|
2337
|
+
restrict: 'Restrict',
|
|
2338
|
+
join: 'Join',
|
|
2339
|
+
hashes: 'Hashes',
|
|
2340
|
+
merges: 'Merges'
|
|
2341
2341
|
};
|
|
2342
2342
|
return caseMap[defName.toLowerCase()] || defName;
|
|
2343
2343
|
}
|
|
@@ -2573,7 +2573,7 @@ export class Deparser {
|
|
|
2573
2573
|
Constraint(node, context) {
|
|
2574
2574
|
const output = [];
|
|
2575
2575
|
// Handle constraint name if present
|
|
2576
|
-
if (node.conname && (node.contype === 'CONSTR_CHECK' || node.contype === 'CONSTR_UNIQUE' || node.contype === 'CONSTR_PRIMARY' || node.contype === 'CONSTR_FOREIGN' || node.contype === 'CONSTR_NOTNULL')) {
|
|
2576
|
+
if (node.conname && (node.contype === 'CONSTR_CHECK' || node.contype === 'CONSTR_UNIQUE' || node.contype === 'CONSTR_PRIMARY' || node.contype === 'CONSTR_FOREIGN' || node.contype === 'CONSTR_NOTNULL' || node.contype === 'CONSTR_EXCLUSION')) {
|
|
2577
2577
|
output.push('CONSTRAINT');
|
|
2578
2578
|
output.push(QuoteUtils.quoteIdentifier(node.conname));
|
|
2579
2579
|
}
|
|
@@ -5336,6 +5336,7 @@ export class Deparser {
|
|
|
5336
5336
|
if (bodyType === 'List') {
|
|
5337
5337
|
const statements = ListUtils.unwrapList(node.sql_body);
|
|
5338
5338
|
if (statements.length === 0 || (statements.length === 1 && Object.keys(statements[0]).length === 0)) {
|
|
5339
|
+
// empty body: nothing to emit
|
|
5339
5340
|
}
|
|
5340
5341
|
else {
|
|
5341
5342
|
// Handle nested List structure in BEGIN ATOMIC blocks
|
|
@@ -7766,6 +7767,15 @@ export class Deparser {
|
|
|
7766
7767
|
output.push(this.visit(node.object, context));
|
|
7767
7768
|
}
|
|
7768
7769
|
}
|
|
7770
|
+
else if ((node.renameType === 'OBJECT_TYPE' || node.renameType === 'OBJECT_DOMAIN') && node.object.List) {
|
|
7771
|
+
// Qualified type names - join List parts with dots
|
|
7772
|
+
const items = ListUtils.unwrapList(node.object);
|
|
7773
|
+
const parts = items
|
|
7774
|
+
.map((item) => item.String?.sval)
|
|
7775
|
+
.filter((s) => typeof s === 'string')
|
|
7776
|
+
.map((s) => this.quoteIfNeeded(s));
|
|
7777
|
+
output.push(parts.join('.'));
|
|
7778
|
+
}
|
|
7769
7779
|
else if (node.renameType === 'OBJECT_SCHEMA' && node.object.List) {
|
|
7770
7780
|
// Handle schema names - extract from List structure
|
|
7771
7781
|
const items = ListUtils.unwrapList(node.object);
|
|
@@ -7905,6 +7915,9 @@ export class Deparser {
|
|
|
7905
7915
|
else if (node.objtype === 'OBJECT_LANGUAGE') {
|
|
7906
7916
|
output.push('LANGUAGE');
|
|
7907
7917
|
}
|
|
7918
|
+
else if (node.objtype === 'OBJECT_SEQUENCE') {
|
|
7919
|
+
output.push('SEQUENCE');
|
|
7920
|
+
}
|
|
7908
7921
|
else if (node.objtype === 'OBJECT_FUNCTION') {
|
|
7909
7922
|
output.push('FUNCTION');
|
|
7910
7923
|
}
|
|
@@ -10032,6 +10045,7 @@ export class Deparser {
|
|
|
10032
10045
|
rootParts.push('STANDALONE NO VALUE');
|
|
10033
10046
|
}
|
|
10034
10047
|
else if (standaloneArg.A_Const.ival.ival === 3) {
|
|
10048
|
+
// STANDALONE omitted
|
|
10035
10049
|
}
|
|
10036
10050
|
else if (Object.keys(standaloneArg.A_Const.ival).length === 0) {
|
|
10037
10051
|
rootParts.push('STANDALONE YES');
|
package/esm/index.js
CHANGED
package/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Deparser, DeparserOptions } from
|
|
1
|
+
import { Deparser, DeparserOptions } from './deparser';
|
|
2
2
|
declare const deparseMethod: typeof Deparser.deparse;
|
|
3
3
|
export declare const deparseSync: typeof Deparser.deparse;
|
|
4
4
|
export declare const deparse: (...args: Parameters<typeof deparseMethod>) => Promise<ReturnType<typeof deparseMethod>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pgsql-deparser",
|
|
3
|
-
"version": "18.
|
|
3
|
+
"version": "18.3.0",
|
|
4
4
|
"author": "Constructive <developers@constructive.io>",
|
|
5
5
|
"description": "PostgreSQL AST Deparser",
|
|
6
6
|
"main": "index.js",
|
|
@@ -57,8 +57,8 @@
|
|
|
57
57
|
"makage": "^0.1.8"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@pgsql/quotes": "18.
|
|
60
|
+
"@pgsql/quotes": "18.2.0",
|
|
61
61
|
"@pgsql/types": "^18.0.0"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "a60df59baaf11fbfe516b0ed25280d5854ad00e9"
|
|
64
64
|
}
|