pgsql-deparser 17.17.2 → 17.18.1

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/esm/deparser.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { DeparserContext } from './visitors/base';
2
2
  import { SqlFormatter } from './utils/sql-formatter';
3
- import { QuoteUtils } from './utils/quote-utils';
3
+ import { QuoteUtils } from '@pgsql/quotes';
4
4
  import { ListUtils } from './utils/list-utils';
5
5
  /**
6
6
  * List of real PostgreSQL built-in types as they appear in pg_catalog.pg_type.typname.
@@ -505,9 +505,7 @@ export class Deparser {
505
505
  output.push('VALUES');
506
506
  const lists = ListUtils.unwrapList(node.valuesLists).map(list => {
507
507
  const values = ListUtils.unwrapList(list).map(val => this.visit(val, context));
508
- // Put each value on its own line for pretty printing
509
- const indentedValues = values.map(val => context.indent(val));
510
- return '(\n' + indentedValues.join(',\n') + '\n)';
508
+ return context.parens(values.join(', '));
511
509
  });
512
510
  const indentedTuples = lists.map(tuple => {
513
511
  if (this.containsMultilineStringLiteral(tuple)) {
@@ -1761,7 +1759,7 @@ export class Deparser {
1761
1759
  }
1762
1760
  return output.join(' ');
1763
1761
  }
1764
- let result = mods(typeName, args);
1762
+ let result = mods(QuoteUtils.quoteIdentifierTypeName(typeName), args);
1765
1763
  if (node.arrayBounds && node.arrayBounds.length > 0) {
1766
1764
  result += formatArrayBounds(node.arrayBounds);
1767
1765
  }
@@ -2873,6 +2871,10 @@ export class Deparser {
2873
2871
  });
2874
2872
  output.push(`(${exclusionElements.join(', ')})`);
2875
2873
  }
2874
+ if (node.where_clause) {
2875
+ output.push('WHERE');
2876
+ output.push(context.parens(this.visit(node.where_clause, context)));
2877
+ }
2876
2878
  break;
2877
2879
  }
2878
2880
  // Handle deferrable constraints for all constraint types that support it
@@ -3006,6 +3008,8 @@ export class Deparser {
3006
3008
  if (!node.frameOptions)
3007
3009
  return null;
3008
3010
  const frameOptions = node.frameOptions;
3011
+ const EXCLUDE_MASK = 0x8000 | 0x10000 | 0x20000;
3012
+ const baseFrameOptions = frameOptions & ~EXCLUDE_MASK;
3009
3013
  const frameParts = [];
3010
3014
  if (frameOptions & 0x01) { // FRAMEOPTION_NONDEFAULT
3011
3015
  if (frameOptions & 0x02) { // FRAMEOPTION_RANGE
@@ -3022,31 +3026,31 @@ export class Deparser {
3022
3026
  return null;
3023
3027
  const boundsParts = [];
3024
3028
  // Handle specific frameOptions values that have known mappings
3025
- if (frameOptions === 789) {
3029
+ if (baseFrameOptions === 789) {
3026
3030
  boundsParts.push('CURRENT ROW');
3027
3031
  boundsParts.push('AND UNBOUNDED FOLLOWING');
3028
3032
  }
3029
- else if (frameOptions === 1077) {
3033
+ else if (baseFrameOptions === 1077) {
3030
3034
  boundsParts.push('UNBOUNDED PRECEDING');
3031
3035
  boundsParts.push('AND CURRENT ROW');
3032
3036
  }
3033
- else if (frameOptions === 18453) {
3037
+ else if (baseFrameOptions === 18453) {
3034
3038
  if (node.startOffset && node.endOffset) {
3035
3039
  boundsParts.push(`${this.visit(node.startOffset, context)} PRECEDING`);
3036
3040
  boundsParts.push(`AND ${this.visit(node.endOffset, context)} FOLLOWING`);
3037
3041
  }
3038
3042
  }
3039
- else if (frameOptions === 1557) {
3043
+ else if (baseFrameOptions === 1557) {
3040
3044
  boundsParts.push('CURRENT ROW');
3041
3045
  boundsParts.push('AND CURRENT ROW');
3042
3046
  }
3043
- else if (frameOptions === 16917) {
3047
+ else if (baseFrameOptions === 16917) {
3044
3048
  boundsParts.push('CURRENT ROW');
3045
3049
  if (node.endOffset) {
3046
3050
  boundsParts.push(`AND ${this.visit(node.endOffset, context)} FOLLOWING`);
3047
3051
  }
3048
3052
  }
3049
- else if (frameOptions === 1058) {
3053
+ else if (baseFrameOptions === 1058) {
3050
3054
  return null;
3051
3055
  }
3052
3056
  else {
@@ -3100,6 +3104,16 @@ export class Deparser {
3100
3104
  frameParts.push('BETWEEN');
3101
3105
  frameParts.push(boundsParts.join(' '));
3102
3106
  }
3107
+ // EXCLUDE clause
3108
+ if (frameOptions & 0x8000) { // FRAMEOPTION_EXCLUDE_CURRENT_ROW
3109
+ frameParts.push('EXCLUDE CURRENT ROW');
3110
+ }
3111
+ else if (frameOptions & 0x10000) { // FRAMEOPTION_EXCLUDE_GROUP
3112
+ frameParts.push('EXCLUDE GROUP');
3113
+ }
3114
+ else if (frameOptions & 0x20000) { // FRAMEOPTION_EXCLUDE_TIES
3115
+ frameParts.push('EXCLUDE TIES');
3116
+ }
3103
3117
  return frameParts.join(' ');
3104
3118
  }
3105
3119
  SortBy(node, context) {
package/esm/index.js CHANGED
@@ -7,4 +7,4 @@ export const deparse = async (...args) => {
7
7
  return deparseMethod(...args);
8
8
  };
9
9
  export { Deparser };
10
- export { QuoteUtils } from './utils/quote-utils';
10
+ export { QuoteUtils } from '@pgsql/quotes';
package/index.d.ts CHANGED
@@ -3,4 +3,4 @@ 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>>;
5
5
  export { Deparser, DeparserOptions };
6
- export { QuoteUtils } from './utils/quote-utils';
6
+ export { QuoteUtils } from '@pgsql/quotes';
package/index.js CHANGED
@@ -11,5 +11,5 @@ const deparse = async (...args) => {
11
11
  return deparseMethod(...args);
12
12
  };
13
13
  exports.deparse = deparse;
14
- var quote_utils_1 = require("./utils/quote-utils");
15
- Object.defineProperty(exports, "QuoteUtils", { enumerable: true, get: function () { return quote_utils_1.QuoteUtils; } });
14
+ var quotes_1 = require("@pgsql/quotes");
15
+ Object.defineProperty(exports, "QuoteUtils", { enumerable: true, get: function () { return quotes_1.QuoteUtils; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pgsql-deparser",
3
- "version": "17.17.2",
3
+ "version": "17.18.1",
4
4
  "author": "Constructive <developers@constructive.io>",
5
5
  "description": "PostgreSQL AST Deparser",
6
6
  "main": "index.js",
@@ -40,8 +40,7 @@
40
40
  "organize-transformers": "ts-node scripts/organize-transformers-by-version.ts",
41
41
  "generate-version-deparsers": "ts-node scripts/generate-version-deparsers.ts",
42
42
  "generate-packages": "ts-node scripts/generate-version-packages.ts",
43
- "prepare-versions": "npm run strip-transformer-types && npm run strip-direct-transformer-types && npm run strip-deparser-types && npm run organize-transformers && npm run generate-version-deparsers && npm run generate-packages",
44
- "keywords": "ts-node scripts/keywords.ts"
43
+ "prepare-versions": "npm run strip-transformer-types && npm run strip-direct-transformer-types && npm run strip-deparser-types && npm run organize-transformers && npm run generate-version-deparsers && npm run generate-packages"
45
44
  },
46
45
  "keywords": [
47
46
  "sql",
@@ -58,7 +57,8 @@
58
57
  "makage": "^0.1.8"
59
58
  },
60
59
  "dependencies": {
60
+ "@pgsql/quotes": "17.1.0",
61
61
  "@pgsql/types": "^17.6.2"
62
62
  },
63
- "gitHead": "65aeb17fd6ba57c698831988bb8e4efb942ca4e1"
63
+ "gitHead": "58ddefe11a5d002db6645fa7bc2f284123d48470"
64
64
  }
package/esm/kwlist.js DELETED
@@ -1,531 +0,0 @@
1
- /* eslint-disable */
2
- /**
3
- * Generated from PostgreSQL kwlist.h
4
- * DO NOT EDIT BY HAND.
5
- */
6
- export const kwlist = {
7
- UNRESERVED_KEYWORD: [
8
- "abort",
9
- "absent",
10
- "absolute",
11
- "access",
12
- "action",
13
- "add",
14
- "admin",
15
- "after",
16
- "aggregate",
17
- "also",
18
- "alter",
19
- "always",
20
- "asensitive",
21
- "assertion",
22
- "assignment",
23
- "at",
24
- "atomic",
25
- "attach",
26
- "attribute",
27
- "backward",
28
- "before",
29
- "begin",
30
- "breadth",
31
- "by",
32
- "cache",
33
- "call",
34
- "called",
35
- "cascade",
36
- "cascaded",
37
- "catalog",
38
- "chain",
39
- "characteristics",
40
- "checkpoint",
41
- "class",
42
- "close",
43
- "cluster",
44
- "columns",
45
- "comment",
46
- "comments",
47
- "commit",
48
- "committed",
49
- "compression",
50
- "conditional",
51
- "configuration",
52
- "conflict",
53
- "connection",
54
- "constraints",
55
- "content",
56
- "continue",
57
- "conversion",
58
- "copy",
59
- "cost",
60
- "csv",
61
- "cube",
62
- "current",
63
- "cursor",
64
- "cycle",
65
- "data",
66
- "database",
67
- "day",
68
- "deallocate",
69
- "declare",
70
- "defaults",
71
- "deferred",
72
- "definer",
73
- "delete",
74
- "delimiter",
75
- "delimiters",
76
- "depends",
77
- "depth",
78
- "detach",
79
- "dictionary",
80
- "disable",
81
- "discard",
82
- "document",
83
- "domain",
84
- "double",
85
- "drop",
86
- "each",
87
- "empty",
88
- "enable",
89
- "encoding",
90
- "encrypted",
91
- "enforced",
92
- "enum",
93
- "error",
94
- "escape",
95
- "event",
96
- "exclude",
97
- "excluding",
98
- "exclusive",
99
- "execute",
100
- "explain",
101
- "expression",
102
- "extension",
103
- "external",
104
- "family",
105
- "filter",
106
- "finalize",
107
- "first",
108
- "following",
109
- "force",
110
- "format",
111
- "forward",
112
- "function",
113
- "functions",
114
- "generated",
115
- "global",
116
- "granted",
117
- "groups",
118
- "handler",
119
- "header",
120
- "hold",
121
- "hour",
122
- "identity",
123
- "if",
124
- "ignore",
125
- "immediate",
126
- "immutable",
127
- "implicit",
128
- "import",
129
- "include",
130
- "including",
131
- "increment",
132
- "indent",
133
- "index",
134
- "indexes",
135
- "inherit",
136
- "inherits",
137
- "inline",
138
- "input",
139
- "insensitive",
140
- "insert",
141
- "instead",
142
- "invoker",
143
- "isolation",
144
- "keep",
145
- "key",
146
- "keys",
147
- "label",
148
- "language",
149
- "large",
150
- "last",
151
- "leakproof",
152
- "level",
153
- "listen",
154
- "load",
155
- "local",
156
- "location",
157
- "lock",
158
- "locked",
159
- "logged",
160
- "lsn",
161
- "mapping",
162
- "match",
163
- "matched",
164
- "materialized",
165
- "maxvalue",
166
- "merge",
167
- "method",
168
- "minute",
169
- "minvalue",
170
- "mode",
171
- "month",
172
- "move",
173
- "name",
174
- "names",
175
- "nested",
176
- "new",
177
- "next",
178
- "nfc",
179
- "nfd",
180
- "nfkc",
181
- "nfkd",
182
- "no",
183
- "normalized",
184
- "nothing",
185
- "notify",
186
- "nowait",
187
- "nulls",
188
- "object",
189
- "objects",
190
- "of",
191
- "off",
192
- "oids",
193
- "old",
194
- "omit",
195
- "operator",
196
- "option",
197
- "options",
198
- "ordinality",
199
- "others",
200
- "over",
201
- "overriding",
202
- "owned",
203
- "owner",
204
- "parallel",
205
- "parameter",
206
- "parser",
207
- "partial",
208
- "partition",
209
- "partitions",
210
- "passing",
211
- "password",
212
- "path",
213
- "period",
214
- "plan",
215
- "plans",
216
- "policy",
217
- "preceding",
218
- "prepare",
219
- "prepared",
220
- "preserve",
221
- "prior",
222
- "privileges",
223
- "procedural",
224
- "procedure",
225
- "procedures",
226
- "program",
227
- "publication",
228
- "quote",
229
- "quotes",
230
- "range",
231
- "read",
232
- "reassign",
233
- "recursive",
234
- "ref",
235
- "referencing",
236
- "refresh",
237
- "reindex",
238
- "relative",
239
- "release",
240
- "rename",
241
- "repeatable",
242
- "replace",
243
- "replica",
244
- "reset",
245
- "respect",
246
- "restart",
247
- "restrict",
248
- "return",
249
- "returns",
250
- "revoke",
251
- "role",
252
- "rollback",
253
- "rollup",
254
- "routine",
255
- "routines",
256
- "rows",
257
- "rule",
258
- "savepoint",
259
- "scalar",
260
- "schema",
261
- "schemas",
262
- "scroll",
263
- "search",
264
- "second",
265
- "security",
266
- "sequence",
267
- "sequences",
268
- "serializable",
269
- "server",
270
- "session",
271
- "set",
272
- "sets",
273
- "share",
274
- "show",
275
- "simple",
276
- "skip",
277
- "snapshot",
278
- "source",
279
- "split",
280
- "sql",
281
- "stable",
282
- "standalone",
283
- "start",
284
- "statement",
285
- "statistics",
286
- "stdin",
287
- "stdout",
288
- "storage",
289
- "stored",
290
- "strict",
291
- "string",
292
- "strip",
293
- "subscription",
294
- "support",
295
- "sysid",
296
- "system",
297
- "tables",
298
- "tablespace",
299
- "target",
300
- "temp",
301
- "template",
302
- "temporary",
303
- "text",
304
- "ties",
305
- "transaction",
306
- "transform",
307
- "trigger",
308
- "truncate",
309
- "trusted",
310
- "type",
311
- "types",
312
- "uescape",
313
- "unbounded",
314
- "uncommitted",
315
- "unconditional",
316
- "unencrypted",
317
- "unknown",
318
- "unlisten",
319
- "unlogged",
320
- "until",
321
- "update",
322
- "vacuum",
323
- "valid",
324
- "validate",
325
- "validator",
326
- "value",
327
- "varying",
328
- "version",
329
- "view",
330
- "views",
331
- "virtual",
332
- "volatile",
333
- "wait",
334
- "whitespace",
335
- "within",
336
- "without",
337
- "work",
338
- "wrapper",
339
- "write",
340
- "xml",
341
- "year",
342
- "yes",
343
- "zone"
344
- ],
345
- RESERVED_KEYWORD: [
346
- "all",
347
- "analyse",
348
- "analyze",
349
- "and",
350
- "any",
351
- "array",
352
- "as",
353
- "asc",
354
- "asymmetric",
355
- "both",
356
- "case",
357
- "cast",
358
- "check",
359
- "collate",
360
- "column",
361
- "constraint",
362
- "create",
363
- "current_catalog",
364
- "current_date",
365
- "current_role",
366
- "current_time",
367
- "current_timestamp",
368
- "current_user",
369
- "default",
370
- "deferrable",
371
- "desc",
372
- "distinct",
373
- "do",
374
- "else",
375
- "end",
376
- "except",
377
- "false",
378
- "fetch",
379
- "for",
380
- "foreign",
381
- "from",
382
- "grant",
383
- "group",
384
- "having",
385
- "in",
386
- "initially",
387
- "intersect",
388
- "into",
389
- "lateral",
390
- "leading",
391
- "limit",
392
- "localtime",
393
- "localtimestamp",
394
- "not",
395
- "null",
396
- "offset",
397
- "on",
398
- "only",
399
- "or",
400
- "order",
401
- "placing",
402
- "primary",
403
- "references",
404
- "returning",
405
- "select",
406
- "session_user",
407
- "some",
408
- "symmetric",
409
- "system_user",
410
- "table",
411
- "then",
412
- "to",
413
- "trailing",
414
- "true",
415
- "union",
416
- "unique",
417
- "user",
418
- "using",
419
- "variadic",
420
- "when",
421
- "where",
422
- "window",
423
- "with"
424
- ],
425
- TYPE_FUNC_NAME_KEYWORD: [
426
- "authorization",
427
- "binary",
428
- "collation",
429
- "concurrently",
430
- "cross",
431
- "current_schema",
432
- "freeze",
433
- "full",
434
- "ilike",
435
- "inner",
436
- "is",
437
- "isnull",
438
- "join",
439
- "left",
440
- "like",
441
- "natural",
442
- "notnull",
443
- "outer",
444
- "overlaps",
445
- "right",
446
- "similar",
447
- "tablesample",
448
- "verbose"
449
- ],
450
- COL_NAME_KEYWORD: [
451
- "between",
452
- "bigint",
453
- "bit",
454
- "boolean",
455
- "char",
456
- "character",
457
- "coalesce",
458
- "dec",
459
- "decimal",
460
- "exists",
461
- "extract",
462
- "float",
463
- "greatest",
464
- "grouping",
465
- "inout",
466
- "int",
467
- "integer",
468
- "interval",
469
- "json",
470
- "json_array",
471
- "json_arrayagg",
472
- "json_exists",
473
- "json_object",
474
- "json_objectagg",
475
- "json_query",
476
- "json_scalar",
477
- "json_serialize",
478
- "json_table",
479
- "json_value",
480
- "least",
481
- "merge_action",
482
- "national",
483
- "nchar",
484
- "none",
485
- "normalize",
486
- "nullif",
487
- "numeric",
488
- "out",
489
- "overlay",
490
- "position",
491
- "precision",
492
- "real",
493
- "row",
494
- "setof",
495
- "smallint",
496
- "substring",
497
- "time",
498
- "timestamp",
499
- "treat",
500
- "trim",
501
- "values",
502
- "varchar",
503
- "xmlattributes",
504
- "xmlconcat",
505
- "xmlelement",
506
- "xmlexists",
507
- "xmlforest",
508
- "xmlnamespaces",
509
- "xmlparse",
510
- "xmlpi",
511
- "xmlroot",
512
- "xmlserialize",
513
- "xmltable"
514
- ]
515
- };
516
- export const RESERVED_KEYWORDS = new Set(kwlist.RESERVED_KEYWORD ?? []);
517
- export const UNRESERVED_KEYWORDS = new Set(kwlist.UNRESERVED_KEYWORD ?? []);
518
- export const COL_NAME_KEYWORDS = new Set(kwlist.COL_NAME_KEYWORD ?? []);
519
- export const TYPE_FUNC_NAME_KEYWORDS = new Set(kwlist.TYPE_FUNC_NAME_KEYWORD ?? []);
520
- export function keywordKindOf(word) {
521
- const w = word.toLowerCase();
522
- if (RESERVED_KEYWORDS.has(w))
523
- return "RESERVED_KEYWORD";
524
- if (TYPE_FUNC_NAME_KEYWORDS.has(w))
525
- return "TYPE_FUNC_NAME_KEYWORD";
526
- if (COL_NAME_KEYWORDS.has(w))
527
- return "COL_NAME_KEYWORD";
528
- if (UNRESERVED_KEYWORDS.has(w))
529
- return "UNRESERVED_KEYWORD";
530
- return "NO_KEYWORD";
531
- }