@indiekitai/pg-dash 0.4.3 → 0.4.5

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/dist/cli.js CHANGED
@@ -2741,7 +2741,7 @@ var RANGE_MAP = {
2741
2741
  "7d": 7 * 24 * 60 * 60 * 1e3
2742
2742
  };
2743
2743
  function registerMetricsRoutes(app, store, collector) {
2744
- app.get("/api/metrics", (c) => {
2744
+ app.get("/api/metrics", async (c) => {
2745
2745
  try {
2746
2746
  const metric = c.req.query("metric");
2747
2747
  const range = c.req.query("range") || "1h";
@@ -2754,7 +2754,7 @@ function registerMetricsRoutes(app, store, collector) {
2754
2754
  return c.json({ error: err.message }, 500);
2755
2755
  }
2756
2756
  });
2757
- app.get("/api/metrics/latest", (_c) => {
2757
+ app.get("/api/metrics/latest", async (_c) => {
2758
2758
  try {
2759
2759
  const snapshot = collector.getLastSnapshot();
2760
2760
  return _c.json(snapshot);
@@ -2845,7 +2845,7 @@ function registerAdvisorRoutes(app, pool, longQueryThreshold, store) {
2845
2845
  return c.json({ error: err.message }, 500);
2846
2846
  }
2847
2847
  });
2848
- app.get("/api/advisor/ignored", (c) => {
2848
+ app.get("/api/advisor/ignored", async (c) => {
2849
2849
  try {
2850
2850
  return c.json(getIgnoredIssues());
2851
2851
  } catch (err) {
@@ -2863,7 +2863,7 @@ function registerAdvisorRoutes(app, pool, longQueryThreshold, store) {
2863
2863
  return c.json({ error: err.message }, 500);
2864
2864
  }
2865
2865
  });
2866
- app.delete("/api/advisor/ignore/:issueId", (c) => {
2866
+ app.delete("/api/advisor/ignore/:issueId", async (c) => {
2867
2867
  try {
2868
2868
  const issueId = c.req.param("issueId");
2869
2869
  unignoreIssue(issueId);
@@ -2872,7 +2872,7 @@ function registerAdvisorRoutes(app, pool, longQueryThreshold, store) {
2872
2872
  return c.json({ error: err.message }, 500);
2873
2873
  }
2874
2874
  });
2875
- app.get("/api/advisor/history", (c) => {
2875
+ app.get("/api/advisor/history", async (c) => {
2876
2876
  if (!store) return c.json([]);
2877
2877
  try {
2878
2878
  const range = c.req.query("range") || "24h";
@@ -2953,7 +2953,7 @@ function registerSchemaRoutes(app, pool, schemaTracker) {
2953
2953
  return c.json({ error: err.message }, 500);
2954
2954
  }
2955
2955
  });
2956
- app.get("/api/schema/history", (c) => {
2956
+ app.get("/api/schema/history", async (c) => {
2957
2957
  try {
2958
2958
  const limit = parseInt(c.req.query("limit") || "30");
2959
2959
  return c.json(schemaTracker.getHistory(limit));
@@ -2961,7 +2961,7 @@ function registerSchemaRoutes(app, pool, schemaTracker) {
2961
2961
  return c.json({ error: err.message }, 500);
2962
2962
  }
2963
2963
  });
2964
- app.get("/api/schema/changes", (c) => {
2964
+ app.get("/api/schema/changes", async (c) => {
2965
2965
  try {
2966
2966
  const since = c.req.query("since");
2967
2967
  return c.json(schemaTracker.getChanges(since ? parseInt(since) : void 0));
@@ -2969,14 +2969,14 @@ function registerSchemaRoutes(app, pool, schemaTracker) {
2969
2969
  return c.json({ error: err.message }, 500);
2970
2970
  }
2971
2971
  });
2972
- app.get("/api/schema/changes/latest", (c) => {
2972
+ app.get("/api/schema/changes/latest", async (c) => {
2973
2973
  try {
2974
2974
  return c.json(schemaTracker.getLatestChanges());
2975
2975
  } catch (err) {
2976
2976
  return c.json({ error: err.message }, 500);
2977
2977
  }
2978
2978
  });
2979
- app.get("/api/schema/diff", (c) => {
2979
+ app.get("/api/schema/diff", async (c) => {
2980
2980
  try {
2981
2981
  const from = parseInt(c.req.query("from") || "0");
2982
2982
  const to = parseInt(c.req.query("to") || "0");
@@ -3000,7 +3000,7 @@ function registerSchemaRoutes(app, pool, schemaTracker) {
3000
3000
 
3001
3001
  // src/server/routes/alerts.ts
3002
3002
  function registerAlertsRoutes(app, alertManager) {
3003
- app.get("/api/alerts/rules", (c) => {
3003
+ app.get("/api/alerts/rules", async (c) => {
3004
3004
  try {
3005
3005
  return c.json(alertManager.getRules());
3006
3006
  } catch (err) {
@@ -3027,7 +3027,7 @@ function registerAlertsRoutes(app, alertManager) {
3027
3027
  return c.json({ error: err.message }, 500);
3028
3028
  }
3029
3029
  });
3030
- app.delete("/api/alerts/rules/:id", (c) => {
3030
+ app.delete("/api/alerts/rules/:id", async (c) => {
3031
3031
  try {
3032
3032
  const id = parseInt(c.req.param("id"));
3033
3033
  const ok = alertManager.deleteRule(id);
@@ -3037,7 +3037,7 @@ function registerAlertsRoutes(app, alertManager) {
3037
3037
  return c.json({ error: err.message }, 500);
3038
3038
  }
3039
3039
  });
3040
- app.get("/api/alerts/webhook-info", (c) => {
3040
+ app.get("/api/alerts/webhook-info", async (c) => {
3041
3041
  try {
3042
3042
  const url = alertManager.getWebhookUrl();
3043
3043
  const type = alertManager.getWebhookType();
@@ -3055,7 +3055,7 @@ function registerAlertsRoutes(app, alertManager) {
3055
3055
  return c.json({ error: err.message }, 500);
3056
3056
  }
3057
3057
  });
3058
- app.get("/api/alerts/history", (c) => {
3058
+ app.get("/api/alerts/history", async (c) => {
3059
3059
  try {
3060
3060
  const limit = parseInt(c.req.query("limit") || "50");
3061
3061
  return c.json(alertManager.getHistory(limit));
@@ -3335,8 +3335,13 @@ function registerDiskRoutes(app, pool, store) {
3335
3335
  (SELECT setting FROM pg_settings WHERE name = 'data_directory') AS data_dir
3336
3336
  `);
3337
3337
  const { db_size, data_dir } = dbRes.rows[0];
3338
- const tsRes = await client.query(`SELECT spcname, pg_tablespace_size(oid) AS size FROM pg_tablespace`);
3339
- const tablespaces = tsRes.rows.map((r) => ({
3338
+ const tsRes = await client.query(`
3339
+ SELECT spcname,
3340
+ CASE WHEN has_tablespace_privilege(spcname, 'CREATE')
3341
+ THEN pg_tablespace_size(oid) ELSE NULL END AS size
3342
+ FROM pg_tablespace
3343
+ `);
3344
+ const tablespaces = tsRes.rows.filter((r) => r.size !== null).map((r) => ({
3340
3345
  name: r.spcname,
3341
3346
  size: parseInt(r.size)
3342
3347
  }));
@@ -3369,7 +3374,7 @@ function registerDiskRoutes(app, pool, store) {
3369
3374
  return c.json({ error: err.message }, 500);
3370
3375
  }
3371
3376
  });
3372
- app.get("/api/disk/prediction", (c) => {
3377
+ app.get("/api/disk/prediction", async (c) => {
3373
3378
  try {
3374
3379
  const days = parseInt(c.req.query("days") || "30");
3375
3380
  const maxDisk = c.req.query("maxDisk") ? parseInt(c.req.query("maxDisk")) : void 0;
@@ -3379,7 +3384,7 @@ function registerDiskRoutes(app, pool, store) {
3379
3384
  return c.json({ error: err.message }, 500);
3380
3385
  }
3381
3386
  });
3382
- app.get("/api/disk/table-history/:table", (c) => {
3387
+ app.get("/api/disk/table-history/:table", async (c) => {
3383
3388
  try {
3384
3389
  const table = c.req.param("table");
3385
3390
  const range = c.req.query("range") || "24h";
@@ -3391,7 +3396,7 @@ function registerDiskRoutes(app, pool, store) {
3391
3396
  return c.json({ error: err.message }, 500);
3392
3397
  }
3393
3398
  });
3394
- app.get("/api/disk/history", (c) => {
3399
+ app.get("/api/disk/history", async (c) => {
3395
3400
  try {
3396
3401
  const range = c.req.query("range") || "24h";
3397
3402
  const rangeMs = RANGE_MAP3[range] || RANGE_MAP3["24h"];
@@ -3600,7 +3605,7 @@ var RANGE_MAP4 = {
3600
3605
  "7d": 7 * 24 * 60 * 60 * 1e3
3601
3606
  };
3602
3607
  function registerQueryStatsRoutes(app, store) {
3603
- app.get("/api/query-stats/top", (c) => {
3608
+ app.get("/api/query-stats/top", async (c) => {
3604
3609
  try {
3605
3610
  const range = c.req.query("range") || "1h";
3606
3611
  const orderBy = c.req.query("orderBy") || "total_time";
@@ -3613,7 +3618,7 @@ function registerQueryStatsRoutes(app, store) {
3613
3618
  return c.json({ error: err.message }, 500);
3614
3619
  }
3615
3620
  });
3616
- app.get("/api/query-stats/trend/:queryid", (c) => {
3621
+ app.get("/api/query-stats/trend/:queryid", async (c) => {
3617
3622
  try {
3618
3623
  const queryid = c.req.param("queryid");
3619
3624
  const range = c.req.query("range") || "1h";
@@ -4078,6 +4083,7 @@ pg-dash \u2014 Lightweight PostgreSQL Monitoring Dashboard
4078
4083
  Usage:
4079
4084
  pg-dash <connection-string> Start dashboard
4080
4085
  pg-dash check <connection-string> Run health check and exit
4086
+ pg-dash health <connection-string> Alias for check
4081
4087
  pg-dash check-migration <file> [connection] Analyze migration SQL for risks
4082
4088
  pg-dash diff-env --source <url> --target <url> Compare two environments
4083
4089
  pg-dash schema-diff <connection-string> Show latest schema changes
@@ -4120,7 +4126,7 @@ Environment variables:
4120
4126
  `);
4121
4127
  process.exit(0);
4122
4128
  }
4123
- var KNOWN_SUBCOMMANDS = ["check", "check-migration", "schema-diff", "diff-env"];
4129
+ var KNOWN_SUBCOMMANDS = ["check", "health", "check-migration", "schema-diff", "diff-env"];
4124
4130
  var subcommand = positionals[0];
4125
4131
  function isValidConnectionString(s) {
4126
4132
  return s.startsWith("postgresql://") || s.startsWith("postgres://") || s.includes("@") || // user@host shorthand
@@ -4153,7 +4159,7 @@ Run pg-dash --help for usage.`
4153
4159
  }
4154
4160
  return connStr;
4155
4161
  }
4156
- if (subcommand === "check") {
4162
+ if (subcommand === "check" || subcommand === "health") {
4157
4163
  const connectionString = resolveConnectionString(1);
4158
4164
  const threshold = parseInt(values.threshold || "70", 10);
4159
4165
  const format = values.format || "text";