@pgplex/pgconsole 1.0.0 → 1.0.2

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.
@@ -1 +1 @@
1
- import{_ as e,a as t,c as n,d as r,f as i,g as a,h as o,i as s,l as c,m as l,n as u,o as d,p as f,r as p,s as m,t as h,u as g}from"./index-Cb7lRHeB.js";export{o as ensureModuleLoaded};
1
+ import{_ as e,a as t,c as n,d as r,f as i,g as a,h as o,i as s,l as c,m as l,n as u,o as d,p as f,r as p,s as m,t as h,u as g}from"./index-CRV3ELJ0.js";export{o as ensureModuleLoaded};
@@ -9,8 +9,8 @@
9
9
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
10
10
  <link href="https://fonts.googleapis.com/css2?family=Geist+Mono:wght@100..900&display=swap" rel="stylesheet" />
11
11
  <title>pgconsole</title>
12
- <script type="module" crossorigin src="/assets/index-Cb7lRHeB.js"></script>
13
- <link rel="stylesheet" crossorigin href="/assets/index-DUHQjBL7.css">
12
+ <script type="module" crossorigin src="/assets/index-CRV3ELJ0.js"></script>
13
+ <link rel="stylesheet" crossorigin href="/assets/index-C8bwjbrl.css">
14
14
  </head>
15
15
  <body>
16
16
  <div id="root"></div>
package/dist/server.mjs CHANGED
@@ -57892,6 +57892,7 @@ function transformSelect(raw) {
57892
57892
  return {
57893
57893
  kind: "select",
57894
57894
  distinct: false,
57895
+ distinctOn: null,
57895
57896
  columns: [],
57896
57897
  from: null,
57897
57898
  where: null,
@@ -57900,28 +57901,35 @@ function transformSelect(raw) {
57900
57901
  orderBy: null,
57901
57902
  limit: null,
57902
57903
  offset: null,
57904
+ windowClause: null,
57903
57905
  withClause: null,
57904
57906
  setOp: {
57905
57907
  op: opType,
57906
57908
  all: !!raw.all,
57907
57909
  left: transformSelect(raw.larg),
57908
57910
  right: transformSelect(raw.rarg)
57909
- }
57911
+ },
57912
+ lockingClause: null
57910
57913
  };
57911
57914
  }
57915
+ const distinctClause = raw.distinctClause;
57916
+ const hasDistinctOn = distinctClause && distinctClause.length > 0 && Object.keys(distinctClause[0]).length > 0;
57912
57917
  return {
57913
57918
  kind: "select",
57914
- distinct: !!raw.distinctClause,
57919
+ distinct: !!distinctClause,
57920
+ distinctOn: hasDistinctOn ? distinctClause.map(transformExpr) : null,
57915
57921
  columns: transformTargetList(raw.targetList),
57916
57922
  from: transformFromClause(raw.fromClause),
57917
57923
  where: raw.whereClause ? transformExpr(raw.whereClause) : null,
57918
- groupBy: raw.groupClause ? raw.groupClause.map(transformExpr) : null,
57924
+ groupBy: raw.groupClause ? raw.groupClause.map(transformGroupByItem) : null,
57919
57925
  having: raw.havingClause ? transformExpr(raw.havingClause) : null,
57920
57926
  orderBy: transformSortClause(raw.sortClause),
57921
57927
  limit: raw.limitCount ? transformExpr(raw.limitCount) : null,
57922
57928
  offset: raw.limitOffset ? transformExpr(raw.limitOffset) : null,
57929
+ windowClause: transformWindowClause(raw.windowClause),
57923
57930
  withClause: transformWithClause(raw.withClause),
57924
- setOp: null
57931
+ setOp: null,
57932
+ lockingClause: transformLockingClause(raw.lockingClause)
57925
57933
  };
57926
57934
  }
57927
57935
  function transformTargetList(list) {
@@ -57961,11 +57969,73 @@ function transformSortClause(list) {
57961
57969
  };
57962
57970
  });
57963
57971
  }
57972
+ function transformLockingClause(nodes) {
57973
+ if (!nodes || nodes.length === 0) return null;
57974
+ return nodes.map((node) => {
57975
+ const lc = node.LockingClause;
57976
+ const strength = lc.strength;
57977
+ const strengthMap = {
57978
+ "LCS_FORUPDATE": "update",
57979
+ "LCS_FORNOKEYUPDATE": "no_key_update",
57980
+ "LCS_FORSHARE": "share",
57981
+ "LCS_FORKEYSHARE": "key_share"
57982
+ };
57983
+ const waitPolicy = lc.waitPolicy;
57984
+ const waitPolicyMap = {
57985
+ "LockWaitBlock": "block",
57986
+ "LockWaitSkip": "skip_locked",
57987
+ "LockWaitError": "nowait"
57988
+ };
57989
+ const lockedRels = lc.lockedRels;
57990
+ return {
57991
+ strength: strengthMap[strength] || "update",
57992
+ waitPolicy: waitPolicyMap[waitPolicy] || "block",
57993
+ lockedRels: lockedRels ? lockedRels.map((r2) => {
57994
+ const rangeVar = r2.RangeVar;
57995
+ return rangeVar.relname;
57996
+ }) : null
57997
+ };
57998
+ });
57999
+ }
57964
58000
  function transformFromClause(list) {
57965
58001
  if (!list || list.length === 0) return null;
57966
- return transformFromItem(list[0]);
58002
+ if (list.length === 1) {
58003
+ return transformFromItem(list[0]);
58004
+ }
58005
+ let result = transformFromItem(list[0]);
58006
+ for (let i2 = 1; i2 < list.length; i2++) {
58007
+ result = {
58008
+ kind: "join",
58009
+ type: "cross",
58010
+ left: result,
58011
+ right: transformFromItem(list[i2]),
58012
+ on: null,
58013
+ using: null
58014
+ };
58015
+ }
58016
+ return result;
57967
58017
  }
57968
58018
  function transformFromItem(node) {
58019
+ if ("RangeTableSample" in node) {
58020
+ const rts = node.RangeTableSample;
58021
+ const relation = rts.relation;
58022
+ const rv = relation.RangeVar;
58023
+ const alias = rts.alias;
58024
+ const method = rts.method;
58025
+ const methodName = method.length > 0 ? method[0].String.sval : "BERNOULLI";
58026
+ const args = rts.args;
58027
+ return {
58028
+ kind: "table",
58029
+ schema: rv.schemaname || null,
58030
+ table: rv.relname,
58031
+ alias: alias?.aliasname || null,
58032
+ tablesample: {
58033
+ method: methodName,
58034
+ args: args ? args.map(transformExpr) : [],
58035
+ repeatable: rts.repeatable ? transformExpr(rts.repeatable) : null
58036
+ }
58037
+ };
58038
+ }
57969
58039
  if ("RangeVar" in node) {
57970
58040
  const rv = node.RangeVar;
57971
58041
  const alias = rv.alias;
@@ -57973,7 +58043,8 @@ function transformFromItem(node) {
57973
58043
  kind: "table",
57974
58044
  schema: rv.schemaname || null,
57975
58045
  table: rv.relname,
57976
- alias: alias?.aliasname || null
58046
+ alias: alias?.aliasname || null,
58047
+ tablesample: null
57977
58048
  };
57978
58049
  }
57979
58050
  if ("RangeSubselect" in node) {
@@ -57982,6 +58053,7 @@ function transformFromItem(node) {
57982
58053
  const subquery = rs.subquery;
57983
58054
  return {
57984
58055
  kind: "subquery",
58056
+ lateral: !!rs.lateral,
57985
58057
  query: transformSelect(subquery.SelectStmt),
57986
58058
  alias: alias?.aliasname || ""
57987
58059
  };
@@ -58005,7 +58077,27 @@ function transformFromItem(node) {
58005
58077
  using: using ? using.map((u) => u.String.sval) : null
58006
58078
  };
58007
58079
  }
58008
- return { kind: "table", schema: null, table: "", alias: null };
58080
+ return { kind: "table", schema: null, table: "", alias: null, tablesample: null };
58081
+ }
58082
+ function transformGroupByItem(node) {
58083
+ if (!node || typeof node !== "object") return transformExpr(node);
58084
+ const obj = node;
58085
+ if ("GroupingSet" in obj) {
58086
+ const gs = obj.GroupingSet;
58087
+ const kindMap = {
58088
+ "GROUPING_SET_ROLLUP": "rollup",
58089
+ "GROUPING_SET_CUBE": "cube",
58090
+ "GROUPING_SET_SETS": "sets",
58091
+ "GROUPING_SET_EMPTY": "empty"
58092
+ };
58093
+ const kind = kindMap[gs.kind] || "sets";
58094
+ const content = gs.content;
58095
+ return {
58096
+ kind,
58097
+ content: content ? content.map(transformGroupByItem) : []
58098
+ };
58099
+ }
58100
+ return transformExpr(node);
58009
58101
  }
58010
58102
  function transformExpr(node) {
58011
58103
  if (!node || typeof node !== "object") return { kind: "unknown", raw: node };
@@ -58022,8 +58114,74 @@ function transformExpr(node) {
58022
58114
  if ("CoalesceExpr" in obj) return transformCoalesce(obj.CoalesceExpr);
58023
58115
  if ("CaseExpr" in obj) return transformCase(obj.CaseExpr);
58024
58116
  if ("ParamRef" in obj) return transformParamRef(obj.ParamRef);
58117
+ if ("RowExpr" in obj) return transformRowExpr(obj.RowExpr);
58025
58118
  return { kind: "unknown", raw: node };
58026
58119
  }
58120
+ function transformWindowClause(list) {
58121
+ if (!list || list.length === 0) return null;
58122
+ return list.map((item) => {
58123
+ const w = item.WindowDef;
58124
+ return {
58125
+ name: w.name || null,
58126
+ partitionBy: w.partitionClause ? w.partitionClause.map(transformExpr) : null,
58127
+ orderBy: transformSortClause(w.orderClause),
58128
+ frameClause: transformWindowFrame(w)
58129
+ };
58130
+ });
58131
+ }
58132
+ function transformWindowFrame(overNode) {
58133
+ const frameOptions = overNode.frameOptions;
58134
+ if (!frameOptions || frameOptions === 0) return null;
58135
+ const FRAMEOPTION_ROWS = 4;
58136
+ const FRAMEOPTION_RANGE = 2;
58137
+ const FRAMEOPTION_GROUPS = 8;
58138
+ const FRAMEOPTION_BETWEEN = 16;
58139
+ const FRAMEOPTION_START_UNBOUNDED_PRECEDING = 32;
58140
+ const FRAMEOPTION_START_CURRENT_ROW = 512;
58141
+ const FRAMEOPTION_START_OFFSET_PRECEDING = 2048;
58142
+ const FRAMEOPTION_START_OFFSET_FOLLOWING = 4096;
58143
+ const FRAMEOPTION_END_UNBOUNDED_PRECEDING = 64;
58144
+ const FRAMEOPTION_END_UNBOUNDED_FOLLOWING = 256;
58145
+ const FRAMEOPTION_END_CURRENT_ROW = 1024;
58146
+ const FRAMEOPTION_END_OFFSET_PRECEDING = 8192;
58147
+ const FRAMEOPTION_END_OFFSET_FOLLOWING = 16384;
58148
+ let frameType;
58149
+ if (frameOptions & FRAMEOPTION_ROWS) frameType = "rows";
58150
+ else if (frameOptions & FRAMEOPTION_RANGE) frameType = "range";
58151
+ else if (frameOptions & FRAMEOPTION_GROUPS) frameType = "groups";
58152
+ else return null;
58153
+ let startBound;
58154
+ if (frameOptions & FRAMEOPTION_START_UNBOUNDED_PRECEDING) {
58155
+ startBound = { type: "unbounded_preceding", offset: null };
58156
+ } else if (frameOptions & FRAMEOPTION_START_CURRENT_ROW) {
58157
+ startBound = { type: "current_row", offset: null };
58158
+ } else if (frameOptions & FRAMEOPTION_START_OFFSET_PRECEDING) {
58159
+ startBound = { type: "preceding", offset: overNode.startOffset ? transformExpr(overNode.startOffset) : null };
58160
+ } else if (frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING) {
58161
+ startBound = { type: "following", offset: overNode.startOffset ? transformExpr(overNode.startOffset) : null };
58162
+ } else {
58163
+ return null;
58164
+ }
58165
+ let endBound = null;
58166
+ if (frameOptions & FRAMEOPTION_BETWEEN) {
58167
+ if (frameOptions & FRAMEOPTION_END_UNBOUNDED_FOLLOWING) {
58168
+ endBound = { type: "unbounded_following", offset: null };
58169
+ } else if (frameOptions & FRAMEOPTION_END_CURRENT_ROW) {
58170
+ endBound = { type: "current_row", offset: null };
58171
+ } else if (frameOptions & FRAMEOPTION_END_OFFSET_PRECEDING) {
58172
+ endBound = { type: "preceding", offset: overNode.endOffset ? transformExpr(overNode.endOffset) : null };
58173
+ } else if (frameOptions & FRAMEOPTION_END_OFFSET_FOLLOWING) {
58174
+ endBound = { type: "following", offset: overNode.endOffset ? transformExpr(overNode.endOffset) : null };
58175
+ } else if (frameOptions & FRAMEOPTION_END_UNBOUNDED_PRECEDING) {
58176
+ endBound = { type: "unbounded_preceding", offset: null };
58177
+ }
58178
+ }
58179
+ return {
58180
+ type: frameType,
58181
+ start: startBound,
58182
+ end: endBound
58183
+ };
58184
+ }
58027
58185
  function transformColumnRef(node) {
58028
58186
  const fields = node.fields;
58029
58187
  const parts = fields.map((f3) => {
@@ -58090,8 +58248,10 @@ function transformFuncCall(node) {
58090
58248
  if (node.over) {
58091
58249
  const overNode = node.over;
58092
58250
  over = {
58251
+ name: overNode.name || null,
58093
58252
  partitionBy: overNode.partitionClause ? overNode.partitionClause.map(transformExpr) : null,
58094
- orderBy: transformSortClause(overNode.orderClause)
58253
+ orderBy: transformSortClause(overNode.orderClause),
58254
+ frameClause: transformWindowFrame(overNode)
58095
58255
  };
58096
58256
  }
58097
58257
  return {
@@ -58171,6 +58331,13 @@ function transformParamRef(node) {
58171
58331
  number: node.number
58172
58332
  };
58173
58333
  }
58334
+ function transformRowExpr(node) {
58335
+ const args = node.args || [];
58336
+ return {
58337
+ kind: "row",
58338
+ args: args.map(transformExpr)
58339
+ };
58340
+ }
58174
58341
  function transformInsert(raw) {
58175
58342
  const relation = raw.relation;
58176
58343
  const alias = relation.alias;
@@ -58190,20 +58357,48 @@ function transformInsert(raw) {
58190
58357
  select = transformSelect(innerSelect);
58191
58358
  }
58192
58359
  const returningList = raw.returningList;
58360
+ const onConflictClause = raw.onConflictClause;
58193
58361
  return {
58194
58362
  kind: "insert",
58195
58363
  table: {
58196
58364
  kind: "table",
58197
58365
  schema: relation.schemaname || null,
58198
58366
  table: relation.relname,
58199
- alias: alias?.aliasname || null
58367
+ alias: alias?.aliasname || null,
58368
+ tablesample: null
58200
58369
  },
58201
58370
  columns,
58202
58371
  values,
58203
58372
  select,
58373
+ onConflict: onConflictClause ? transformOnConflict(onConflictClause) : null,
58204
58374
  returning: returningList ? transformTargetList(returningList) : null
58205
58375
  };
58206
58376
  }
58377
+ function transformOnConflict(raw) {
58378
+ const action = raw.action;
58379
+ const actionType = action === "ONCONFLICT_UPDATE" ? "update" : "nothing";
58380
+ const infer = raw.infer;
58381
+ const indexElems = infer?.indexElems;
58382
+ const target = indexElems ? indexElems.map((elem) => {
58383
+ const indexElem = elem.IndexElem;
58384
+ return indexElem.name;
58385
+ }) : null;
58386
+ const targetList = raw.targetList;
58387
+ const assignments = targetList ? targetList.map((item) => {
58388
+ const resTarget = item.ResTarget;
58389
+ return {
58390
+ column: resTarget.name,
58391
+ value: transformExpr(resTarget.val)
58392
+ };
58393
+ }) : null;
58394
+ const whereClause = raw.whereClause ? transformExpr(raw.whereClause) : null;
58395
+ return {
58396
+ action: actionType,
58397
+ target,
58398
+ assignments,
58399
+ where: whereClause
58400
+ };
58401
+ }
58207
58402
  function transformUpdate(raw) {
58208
58403
  const relation = raw.relation;
58209
58404
  const alias = relation.alias;
@@ -58222,7 +58417,8 @@ function transformUpdate(raw) {
58222
58417
  kind: "table",
58223
58418
  schema: relation.schemaname || null,
58224
58419
  table: relation.relname,
58225
- alias: alias?.aliasname || null
58420
+ alias: alias?.aliasname || null,
58421
+ tablesample: null
58226
58422
  },
58227
58423
  assignments,
58228
58424
  from: transformFromClause(raw.fromClause),
@@ -58240,7 +58436,8 @@ function transformDelete(raw) {
58240
58436
  kind: "table",
58241
58437
  schema: relation.schemaname || null,
58242
58438
  table: relation.relname,
58243
- alias: alias?.aliasname || null
58439
+ alias: alias?.aliasname || null,
58440
+ tablesample: null
58244
58441
  },
58245
58442
  using: transformFromClause(raw.usingClause),
58246
58443
  where: raw.whereClause ? transformExpr(raw.whereClause) : null,
@@ -58269,7 +58466,8 @@ function transformCreateTable(raw) {
58269
58466
  kind: "table",
58270
58467
  schema: relation.schemaname || null,
58271
58468
  table: relation.relname,
58272
- alias: null
58469
+ alias: null,
58470
+ tablesample: null
58273
58471
  },
58274
58472
  columns,
58275
58473
  constraints,
@@ -58459,7 +58657,8 @@ function transformAlterTable(raw) {
58459
58657
  kind: "table",
58460
58658
  schema: relation.schemaname || null,
58461
58659
  table: relation.relname,
58462
- alias: null
58660
+ alias: null,
58661
+ tablesample: null
58463
58662
  },
58464
58663
  commands
58465
58664
  };
@@ -58533,7 +58732,8 @@ function transformCreateView(raw, source) {
58533
58732
  kind: "table",
58534
58733
  schema: view.schemaname || null,
58535
58734
  table: view.relname,
58536
- alias: null
58735
+ alias: null,
58736
+ tablesample: null
58537
58737
  },
58538
58738
  query: transformSelect(query.SelectStmt),
58539
58739
  replace: !!raw.replace,
@@ -58552,7 +58752,8 @@ function transformCreateTableAs(raw, source) {
58552
58752
  kind: "table",
58553
58753
  schema: rel.schemaname || null,
58554
58754
  table: rel.relname,
58555
- alias: null
58755
+ alias: null,
58756
+ tablesample: null
58556
58757
  },
58557
58758
  query: transformSelect(query.SelectStmt),
58558
58759
  replace: false,
@@ -58587,7 +58788,8 @@ function transformCreateIndex(raw, source) {
58587
58788
  kind: "table",
58588
58789
  schema: relation.schemaname || null,
58589
58790
  table: relation.relname,
58590
- alias: null
58791
+ alias: null,
58792
+ tablesample: null
58591
58793
  },
58592
58794
  columns,
58593
58795
  unique: !!raw.unique,
@@ -58811,7 +59013,8 @@ function transformTruncate(raw, source) {
58811
59013
  kind: "table",
58812
59014
  schema: rangeVar.schemaname || null,
58813
59015
  table: rangeVar.relname,
58814
- alias: null
59016
+ alias: null,
59017
+ tablesample: null
58815
59018
  });
58816
59019
  }
58817
59020
  }
@@ -62588,13 +62791,37 @@ COMMIT;` : req.sql;
62588
62791
  } catch (err) {
62589
62792
  const errorMessage = err instanceof Error ? err.message : "Query execution failed";
62590
62793
  const executionTimeMs = Date.now() - start2;
62794
+ let fullError = errorMessage;
62795
+ const pgErr = err;
62796
+ const pos = pgErr?.position;
62797
+ if (typeof pos === "string" && pos) {
62798
+ const charPos = parseInt(pos, 10);
62799
+ if (charPos > 0) {
62800
+ const before = req.sql.slice(0, charPos - 1);
62801
+ const lineNumber = before.split("\n").length;
62802
+ const lines = req.sql.split("\n");
62803
+ const offendingLine = lines[lineNumber - 1];
62804
+ if (offendingLine !== void 0) {
62805
+ fullError = `ERROR at Line ${lineNumber}: ${errorMessage}
62806
+ LINE ${lineNumber}: ${offendingLine}`;
62807
+ }
62808
+ }
62809
+ }
62810
+ if (typeof pgErr?.detail === "string" && pgErr.detail) {
62811
+ fullError += `
62812
+ DETAIL: ${pgErr.detail}`;
62813
+ }
62814
+ if (typeof pgErr?.hint === "string" && pgErr.hint) {
62815
+ fullError += `
62816
+ HINT: ${pgErr.hint}`;
62817
+ }
62591
62818
  auditSQL(user.email, req.connectionId, details.database, req.sql, false, executionTimeMs, void 0, errorMessage);
62592
62819
  yield {
62593
62820
  columns: [],
62594
62821
  rows: [],
62595
62822
  rowCount: 0,
62596
62823
  executionTimeMs,
62597
- error: errorMessage,
62824
+ error: fullError,
62598
62825
  backendPid
62599
62826
  };
62600
62827
  } finally {
@@ -92195,7 +92422,15 @@ var TEXT_TO_SQL = {
92195
92422
  2. Use the exact table and column names from the schema
92196
92423
  3. Prefer explicit column names over SELECT *
92197
92424
  4. Include appropriate WHERE clauses when the request implies filtering
92198
- 5. Use proper PostgreSQL {{version}} syntax`,
92425
+ 5. Use proper PostgreSQL {{version}} syntax
92426
+
92427
+ ## Formatting
92428
+
92429
+ Format the SQL with proper indentation and line breaks for readability:
92430
+ - Keywords (SELECT, FROM, WHERE, etc.) on separate lines
92431
+ - Column lists with one column per line (when multiple columns)
92432
+ - Indent clauses with 2 spaces
92433
+ - Use uppercase for SQL keywords`,
92199
92434
  user: ({ prompt }) => prompt
92200
92435
  };
92201
92436
  var EXPLAIN_SQL = {
@@ -92948,7 +93183,7 @@ async function start() {
92948
93183
  \\ \\_\\ /\\____/
92949
93184
  \\/_/ \\_/__/
92950
93185
 
92951
- Version ${"1.0.0"}
93186
+ Version ${"1.0.2"}
92952
93187
  `);
92953
93188
  console.log(`Server running on http://localhost:${port}`);
92954
93189
  const browserUrl = false ? `http://localhost:5173` : getExternalUrl() || `http://localhost:${port}`;