neonctl 2.37.0 → 2.38.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.
Files changed (160) hide show
  1. package/{LICENSE.md → LICENSE} +27 -3
  2. package/README.md +15 -700
  3. package/bin/cli.js +3 -0
  4. package/package.json +8 -75
  5. package/dist/analytics.js +0 -168
  6. package/dist/api.js +0 -720
  7. package/dist/auth.js +0 -125
  8. package/dist/callback.html +0 -51
  9. package/dist/cli.js +0 -9
  10. package/dist/commands/api.js +0 -278
  11. package/dist/commands/auth.js +0 -214
  12. package/dist/commands/bootstrap.js +0 -481
  13. package/dist/commands/branches.js +0 -488
  14. package/dist/commands/bucket.js +0 -549
  15. package/dist/commands/checkout.js +0 -321
  16. package/dist/commands/config.js +0 -626
  17. package/dist/commands/connection_string.js +0 -172
  18. package/dist/commands/data_api.js +0 -284
  19. package/dist/commands/databases.js +0 -82
  20. package/dist/commands/deploy.js +0 -26
  21. package/dist/commands/dev.js +0 -698
  22. package/dist/commands/diff.js +0 -222
  23. package/dist/commands/env.js +0 -189
  24. package/dist/commands/functions.js +0 -373
  25. package/dist/commands/index.js +0 -62
  26. package/dist/commands/init.js +0 -73
  27. package/dist/commands/inspect.js +0 -65
  28. package/dist/commands/ip_allow.js +0 -137
  29. package/dist/commands/link.js +0 -1121
  30. package/dist/commands/neon_auth.js +0 -1028
  31. package/dist/commands/operations.js +0 -28
  32. package/dist/commands/orgs.js +0 -24
  33. package/dist/commands/projects.js +0 -413
  34. package/dist/commands/psql.js +0 -62
  35. package/dist/commands/roles.js +0 -65
  36. package/dist/commands/schema_diff.js +0 -151
  37. package/dist/commands/set_context.js +0 -29
  38. package/dist/commands/snapshots.js +0 -455
  39. package/dist/commands/status.js +0 -40
  40. package/dist/commands/user.js +0 -15
  41. package/dist/commands/vpc_endpoints.js +0 -134
  42. package/dist/config.js +0 -11
  43. package/dist/config_format.js +0 -72
  44. package/dist/context.js +0 -231
  45. package/dist/current_branch_fast_path.js +0 -55
  46. package/dist/dev/env.js +0 -244
  47. package/dist/dev/functions.js +0 -70
  48. package/dist/dev/inputs.js +0 -63
  49. package/dist/dev/runtime.js +0 -146
  50. package/dist/env.js +0 -36
  51. package/dist/env_file.js +0 -159
  52. package/dist/errors.js +0 -80
  53. package/dist/functions_api.js +0 -48
  54. package/dist/help.js +0 -146
  55. package/dist/index.js +0 -240
  56. package/dist/log.js +0 -18
  57. package/dist/parameters.gen.js +0 -480
  58. package/dist/pkg.js +0 -25
  59. package/dist/psql/cli.js +0 -53
  60. package/dist/psql/command/cmd_cond.js +0 -437
  61. package/dist/psql/command/cmd_connect.js +0 -820
  62. package/dist/psql/command/cmd_copy.js +0 -1035
  63. package/dist/psql/command/cmd_describe.js +0 -1815
  64. package/dist/psql/command/cmd_format.js +0 -948
  65. package/dist/psql/command/cmd_io.js +0 -2193
  66. package/dist/psql/command/cmd_lo.js +0 -393
  67. package/dist/psql/command/cmd_meta.js +0 -969
  68. package/dist/psql/command/cmd_misc.js +0 -187
  69. package/dist/psql/command/cmd_pipeline.js +0 -1148
  70. package/dist/psql/command/cmd_restrict.js +0 -171
  71. package/dist/psql/command/cmd_show.js +0 -766
  72. package/dist/psql/command/dispatch.js +0 -343
  73. package/dist/psql/command/inputQueue.js +0 -42
  74. package/dist/psql/command/shared.js +0 -71
  75. package/dist/psql/complete/filenames.js +0 -139
  76. package/dist/psql/complete/index.js +0 -104
  77. package/dist/psql/complete/matcher.js +0 -315
  78. package/dist/psql/complete/psqlVars.js +0 -249
  79. package/dist/psql/complete/queries.js +0 -493
  80. package/dist/psql/complete/rules.js +0 -2424
  81. package/dist/psql/core/common.js +0 -1253
  82. package/dist/psql/core/help.js +0 -576
  83. package/dist/psql/core/mainloop.js +0 -1360
  84. package/dist/psql/core/prompt.js +0 -439
  85. package/dist/psql/core/settings.js +0 -686
  86. package/dist/psql/core/sqlHelp.js +0 -1066
  87. package/dist/psql/core/startup.js +0 -846
  88. package/dist/psql/core/syncVars.js +0 -116
  89. package/dist/psql/core/variables.js +0 -287
  90. package/dist/psql/describe/formatters.js +0 -1330
  91. package/dist/psql/describe/processNamePattern.js +0 -270
  92. package/dist/psql/describe/queries.js +0 -2452
  93. package/dist/psql/describe/versionGate.js +0 -44
  94. package/dist/psql/index.js +0 -2030
  95. package/dist/psql/io/history.js +0 -299
  96. package/dist/psql/io/input.js +0 -120
  97. package/dist/psql/io/lineEditor/buffer.js +0 -325
  98. package/dist/psql/io/lineEditor/complete.js +0 -227
  99. package/dist/psql/io/lineEditor/filename.js +0 -159
  100. package/dist/psql/io/lineEditor/index.js +0 -893
  101. package/dist/psql/io/lineEditor/keymap.js +0 -745
  102. package/dist/psql/io/lineEditor/vt100.js +0 -363
  103. package/dist/psql/io/pgpass.js +0 -202
  104. package/dist/psql/io/pgservice.js +0 -194
  105. package/dist/psql/io/psqlrc.js +0 -422
  106. package/dist/psql/print/aligned.js +0 -1748
  107. package/dist/psql/print/asciidoc.js +0 -230
  108. package/dist/psql/print/crosstab.js +0 -463
  109. package/dist/psql/print/csv.js +0 -76
  110. package/dist/psql/print/html.js +0 -240
  111. package/dist/psql/print/json.js +0 -96
  112. package/dist/psql/print/latex.js +0 -379
  113. package/dist/psql/print/pager.js +0 -267
  114. package/dist/psql/print/troff.js +0 -240
  115. package/dist/psql/print/unaligned.js +0 -99
  116. package/dist/psql/print/units.js +0 -188
  117. package/dist/psql/scanner/slash.js +0 -515
  118. package/dist/psql/scanner/sql.js +0 -914
  119. package/dist/psql/scanner/stringutils.js +0 -394
  120. package/dist/psql/types/backslash.js +0 -1
  121. package/dist/psql/types/connection.js +0 -1
  122. package/dist/psql/types/index.js +0 -7
  123. package/dist/psql/types/printer.js +0 -1
  124. package/dist/psql/types/repl.js +0 -1
  125. package/dist/psql/types/scanner.js +0 -24
  126. package/dist/psql/types/settings.js +0 -1
  127. package/dist/psql/types/variables.js +0 -1
  128. package/dist/psql/wire/connection.js +0 -2857
  129. package/dist/psql/wire/copy.js +0 -108
  130. package/dist/psql/wire/notify.js +0 -59
  131. package/dist/psql/wire/pipeline.js +0 -521
  132. package/dist/psql/wire/protocol.js +0 -466
  133. package/dist/psql/wire/sasl.js +0 -294
  134. package/dist/psql/wire/tls.js +0 -602
  135. package/dist/storage_api.js +0 -147
  136. package/dist/test_utils/fixtures.js +0 -121
  137. package/dist/test_utils/oauth_server.js +0 -9
  138. package/dist/types.js +0 -1
  139. package/dist/utils/ai_gateway_notice.js +0 -180
  140. package/dist/utils/api_enums.js +0 -33
  141. package/dist/utils/auth.js +0 -5
  142. package/dist/utils/branch_notice.js +0 -22
  143. package/dist/utils/branch_picker.js +0 -103
  144. package/dist/utils/compute_units.js +0 -28
  145. package/dist/utils/config_diff.js +0 -185
  146. package/dist/utils/enrichers.js +0 -161
  147. package/dist/utils/esbuild.js +0 -158
  148. package/dist/utils/formats.js +0 -18
  149. package/dist/utils/git_diff.js +0 -90
  150. package/dist/utils/inspect_db.js +0 -153
  151. package/dist/utils/inspect_queries.js +0 -372
  152. package/dist/utils/middlewares.js +0 -20
  153. package/dist/utils/openapi.js +0 -114
  154. package/dist/utils/package_manager.js +0 -68
  155. package/dist/utils/point_in_time.js +0 -56
  156. package/dist/utils/psql.js +0 -120
  157. package/dist/utils/string.js +0 -5
  158. package/dist/utils/ui.js +0 -59
  159. package/dist/utils/zip.js +0 -4
  160. package/dist/writer.js +0 -97
@@ -1,439 +0,0 @@
1
- /**
2
- * psql Prompt renderer.
3
- *
4
- * TypeScript port of `get_prompt()` from `src/bin/psql/prompt.c`. Walks the
5
- * prompt template (PROMPT1/PROMPT2/PROMPT3) and expands `%`-escapes against
6
- * a `PromptContext` snapshot.
7
- *
8
- * Differences from upstream:
9
- *
10
- * - Upstream takes `promptStatus_t status, ConditionalStack cstack` and
11
- * pulls everything else off `pset`. We accept an explicit `PromptContext`
12
- * so the renderer is a pure function (easier to test, no module-level
13
- * state).
14
- * - `%s` ("service name") is provided from `settings.vars.SERVICE` per
15
- * upstream. We keep that behaviour. The WP-07 spec mentions a "current
16
- * timestamp" semantic for `%s`/`%S` — that is NOT what psql does today,
17
- * so we follow upstream rather than the spec note.
18
- * - `%S` is `search_path` from the connection's GUC report (upstream uses
19
- * `PQparameterStatus(pset.db, "search_path")`). With no Connection yet,
20
- * we fall back to `?`.
21
- * - `%#` checks the `IS_SUPERUSER` psql variable (set by upstream's
22
- * `is_superuser()` via the connect-time hook). Without a Connection we
23
- * default to non-superuser (`>`).
24
- * - `%P` outputs `off`/`on`/`abort` to match upstream's literal strings.
25
- * - `%i` outputs `primary` / `standby` / `?` (upstream reads the GUC
26
- * `in_hot_standby`); when no connection, `?`. The WP-07 spec asked for
27
- * "if-state from CondStack" — that conflicts with upstream `%i` and we
28
- * follow upstream. `%?` remains a no-op marker in upstream too.
29
- * - `%[`/`%]` are upstream's readline non-printing markers. We strip them
30
- * (emit nothing) for now; a future WP wiring readline integration can
31
- * re-introduce them.
32
- * - Backtick command interpolation (`%`\``cmd`\``) is executed synchronously
33
- * via `child_process.execSync` on `sh -c <cmd>`. Output is substituted
34
- * verbatim minus one trailing newline. Errors print to stderr and yield
35
- * an empty substitution — matching upstream's `get_prompt`, which re-runs
36
- * the command on every render rather than caching.
37
- * - Unknown `%X` escapes pass through as literal `X` (the upstream
38
- * `default:` branch). `%w` width is computed from PROMPT1 when present
39
- * and consumed by a subsequent PROMPT2 render via the optional
40
- * `lastPrompt1Width` field on the context.
41
- */
42
- import { execSync } from "node:child_process";
43
- /**
44
- * Test seam for the prompt-level backtick executor. The default
45
- * implementation calls `execSync(cmd, { shell: '/bin/sh' })`; tests can
46
- * replace `.current` with a synchronous mock to avoid actually spawning
47
- * a child. Same pattern as `BACKTICK_EXECUTOR` in `scanner/slash.ts`.
48
- */
49
- export const PROMPT_BACKTICK_EXECUTOR = {
50
- current: (cmd) => execSync(cmd, {
51
- shell: "/bin/sh",
52
- encoding: "utf8",
53
- stdio: ["ignore", "pipe", "inherit"],
54
- // Keep prompt rendering responsive — a heavy backtick command should
55
- // not be able to fill arbitrary memory or hang the prompt forever.
56
- maxBuffer: 1 << 16,
57
- }),
58
- };
59
- /**
60
- * Run a single backtick command and return its stdout, with one trailing
61
- * newline trimmed. On failure (non-zero exit / spawn error) print the
62
- * error to stderr and return the empty string so the prompt still renders.
63
- */
64
- const runPromptBacktick = (cmd) => {
65
- if (cmd.length === 0)
66
- return "";
67
- try {
68
- const out = PROMPT_BACKTICK_EXECUTOR.current(cmd);
69
- return out.endsWith("\n") ? out.slice(0, -1) : out;
70
- }
71
- catch (err) {
72
- const msg = err instanceof Error ? err.message : String(err);
73
- process.stderr.write(`psql: error: \\!: ${cmd}: ${msg}\n`);
74
- return "";
75
- }
76
- };
77
- /**
78
- * Render a prompt by name. Selects the template from
79
- * `settings.prompt{1,2,3}` and delegates to the escape-walking core.
80
- */
81
- export const renderPromptByName = (name, ctx) => {
82
- const template = name === "PROMPT1"
83
- ? ctx.settings.prompt1
84
- : name === "PROMPT2"
85
- ? ctx.settings.prompt2
86
- : ctx.settings.prompt3;
87
- const isPrompt1 = name === "PROMPT1";
88
- const out = renderPrompt(template, ctx);
89
- if (isPrompt1) {
90
- // Stash the visible width on the context so a subsequent PROMPT2 render
91
- // sharing this context object can line up with `%w`.
92
- ctx.lastPrompt1Width = visibleWidth(out);
93
- }
94
- return out;
95
- };
96
- /**
97
- * Render an arbitrary prompt template. Pure function over `(template, ctx)`.
98
- */
99
- export const renderPrompt = (template, ctx) => {
100
- let out = "";
101
- let i = 0;
102
- while (i < template.length) {
103
- const ch = template[i];
104
- if (ch !== "%") {
105
- out += ch;
106
- i += 1;
107
- continue;
108
- }
109
- // We have `%X`; advance past the `%` and resolve.
110
- i += 1;
111
- if (i >= template.length) {
112
- // Trailing `%` — emit nothing, matches upstream (esc stays true and
113
- // the loop exits without strlcat).
114
- break;
115
- }
116
- const escape = template[i];
117
- const { text, consumed } = expandEscape(escape, template, i, ctx);
118
- out += text;
119
- i += consumed;
120
- }
121
- return out;
122
- };
123
- const expandEscape = (escape, template,
124
- /** Index of `escape` within `template`. */
125
- start, ctx) => {
126
- const { settings } = ctx;
127
- const db = settings.db;
128
- switch (escape) {
129
- case "%":
130
- return { text: "%", consumed: 1 };
131
- case "/":
132
- // Current database.
133
- return { text: db ? currentDatabase(ctx) : "", consumed: 1 };
134
- case "~": {
135
- // Like %/, but "~" when current_db matches the user's default db.
136
- // Upstream compares PQdb(pset.db) against PQuser(pset.db) and
137
- // against $PGDATABASE.
138
- if (!db)
139
- return { text: "", consumed: 1 };
140
- const cdb = currentDatabase(ctx);
141
- const user = currentUser(ctx);
142
- const pgdb = process.env.PGDATABASE;
143
- if (cdb === user || (pgdb !== undefined && pgdb === cdb)) {
144
- return { text: "~", consumed: 1 };
145
- }
146
- return { text: cdb, consumed: 1 };
147
- }
148
- case "M":
149
- case "m":
150
- return {
151
- text: db ? hostString(ctx, escape === "m") : "",
152
- consumed: 1,
153
- };
154
- case ">":
155
- return { text: db ? portString(ctx) : "", consumed: 1 };
156
- case "n":
157
- return { text: db ? currentUser(ctx) : "", consumed: 1 };
158
- case "p": {
159
- if (!db)
160
- return { text: "", consumed: 1 };
161
- const pid = backendPid(ctx);
162
- return { text: pid !== null ? String(pid) : "", consumed: 1 };
163
- }
164
- case "P": {
165
- if (!db)
166
- return { text: "", consumed: 1 };
167
- // Upstream emits "off" / "on" / "abort" (no trailing 'ed').
168
- const state = ctx.pipelineState ?? "off";
169
- const text = state === "on" ? "on" : state === "aborted" ? "abort" : "off";
170
- return { text, consumed: 1 };
171
- }
172
- case "i": {
173
- // Hot-standby indicator. Upstream reads in_hot_standby GUC.
174
- if (!db)
175
- return { text: "", consumed: 1 };
176
- const hs = parameterStatus(ctx, "in_hot_standby");
177
- if (hs === undefined)
178
- return { text: "?", consumed: 1 };
179
- return { text: hs === "on" ? "standby" : "primary", consumed: 1 };
180
- }
181
- case "s": {
182
- // service name from psql var SERVICE (upstream prompt.c).
183
- const svc = settings.vars.get("SERVICE");
184
- return { text: svc ?? "", consumed: 1 };
185
- }
186
- case "S": {
187
- // search_path; `?` when unavailable (older servers or no conn).
188
- if (!db)
189
- return { text: "?", consumed: 1 };
190
- const sp = parameterStatus(ctx, "search_path");
191
- return { text: sp ?? "?", consumed: 1 };
192
- }
193
- case "l":
194
- return { text: String(ctx.lineNumber), consumed: 1 };
195
- case "w": {
196
- // Whitespace padding the width of the last PROMPT1 render.
197
- const width = Math.max(0, ctx.lastPrompt1Width ?? 0);
198
- return { text: db ? " ".repeat(width) : "", consumed: 1 };
199
- }
200
- case "a":
201
- // Bell. Upstream falls into default, which is just literal 'a' (no
202
- // bell handling in get_prompt). The WP-07 spec explicitly asks for
203
- // ^G though, and emitting BEL is harmless. Honour the spec.
204
- return { text: "\x07", consumed: 1 };
205
- case "R": {
206
- const text = expandR(ctx);
207
- return { text, consumed: 1 };
208
- }
209
- case "x": {
210
- if (!db)
211
- return { text: "?", consumed: 1 };
212
- const tx = ctx.inTransaction ?? "idle";
213
- if (tx === "in-block")
214
- return { text: "*", consumed: 1 };
215
- if (tx === "failed")
216
- return { text: "!", consumed: 1 };
217
- if (tx === "unknown")
218
- return { text: "?", consumed: 1 };
219
- return { text: "", consumed: 1 };
220
- }
221
- case "#": {
222
- // Superuser indicator. Upstream calls is_superuser() which checks
223
- // pset.vars["IS_SUPERUSER"] === "on".
224
- const isSuper = settings.vars.get("IS_SUPERUSER") === "on";
225
- return { text: isSuper ? "#" : ">", consumed: 1 };
226
- }
227
- case "?":
228
- // Reserved by upstream ("not here yet"). Emit nothing.
229
- return { text: "", consumed: 1 };
230
- case "[":
231
- case "]":
232
- // Readline non-printing markers. Strip — no terminal info embedded.
233
- return { text: "", consumed: 1 };
234
- case "`": {
235
- // Backtick command: read until the matching `` ` `` after the opening
236
- // backtick, then run the body through `sh -c` and substitute its
237
- // stdout. Upstream `get_prompt` re-runs the command on every render
238
- // rather than caching, so we do the same — callers who want caching
239
- // should stash the rendered prompt themselves.
240
- const close = template.indexOf("`", start + 1);
241
- if (close === -1) {
242
- // Unterminated — consume the rest defensively without spawning.
243
- return { text: "", consumed: template.length - start };
244
- }
245
- const body = template.slice(start + 1, close);
246
- return {
247
- text: runPromptBacktick(body),
248
- consumed: close - start + 1,
249
- };
250
- }
251
- case ":": {
252
- // Variable interpolation %:name:
253
- const close = template.indexOf(":", start + 1);
254
- if (close === -1) {
255
- return { text: "", consumed: template.length - start };
256
- }
257
- const name = template.slice(start + 1, close);
258
- const val = settings.vars.get(name);
259
- return { text: val ?? "", consumed: close - start + 1 };
260
- }
261
- case "0":
262
- case "1":
263
- case "2":
264
- case "3":
265
- case "4":
266
- case "5":
267
- case "6":
268
- case "7": {
269
- // Octal byte value `%nnn`. Upstream uses strtol(p, &p, 8), which
270
- // greedily consumes 1–3 octal digits.
271
- let consumed = 1;
272
- let body = escape;
273
- while (consumed < 3 && start + consumed < template.length) {
274
- const next = template[start + consumed];
275
- if (next >= "0" && next <= "7") {
276
- body += next;
277
- consumed += 1;
278
- }
279
- else {
280
- break;
281
- }
282
- }
283
- const byte = parseInt(body, 8);
284
- return { text: String.fromCharCode(byte), consumed };
285
- }
286
- default:
287
- // Unknown escape → literal character (matches upstream default:).
288
- return { text: escape, consumed: 1 };
289
- }
290
- };
291
- /**
292
- * Expand `%R`. PROMPT1 reflects the connection / cond-stack / singleline
293
- * state. PROMPT2 reflects the scanner's promptStatus — upstream renders a
294
- * mnemonic character for *why* the parser is still hanging on for more
295
- * input:
296
- *
297
- * - `-` plain continuation (default)
298
- * - `'` inside a single-quoted string
299
- * - `"` inside a double-quoted identifier
300
- * - `$` inside a dollar-quoted block
301
- * - `*` inside a block comment
302
- * - `(` inside unmatched parens
303
- *
304
- * PROMPT3 is the COPY indicator; upstream falls into the `default` branch
305
- * and emits nothing — we do the same.
306
- */
307
- const expandR = (ctx) => {
308
- const { promptStatus, cond, settings } = ctx;
309
- switch (promptStatus) {
310
- case "ready": {
311
- if (!isConditionalActive(cond))
312
- return "@";
313
- if (!settings.db)
314
- return "!";
315
- if (!settings.singleline)
316
- return "=";
317
- return "^";
318
- }
319
- case "continue":
320
- return "-";
321
- case "continue-quote":
322
- return "'";
323
- case "continue-dquote":
324
- return '"';
325
- case "continue-dollar":
326
- return "$";
327
- case "comment":
328
- return "*";
329
- case "paren":
330
- return "(";
331
- case "copy":
332
- // PROMPT3 / COPY path — upstream emits nothing for %R here.
333
- return "";
334
- default:
335
- return "";
336
- }
337
- };
338
- /**
339
- * Return `false` if the current `\if` branch is non-active (we're inside a
340
- * skipped block). Mirrors upstream `conditional_active`. Inactive states are
341
- * `false`, `else-false`, and `ignored`; everything else (including the
342
- * sentinel `none` for "no \if active") is treated as active.
343
- */
344
- const isConditionalActive = (cond) => {
345
- const top = cond.top();
346
- if (!top)
347
- return true;
348
- const inactive = ["false", "else-false", "ignored"];
349
- return !inactive.includes(top.state);
350
- };
351
- /**
352
- * Visible width of a rendered prompt — used to seed `%w` on PROMPT2. We
353
- * subtract ANSI escape sequences and the unicode width is approximated by
354
- * code-point count (full Unicode width tables live in the printer WP).
355
- */
356
- const visibleWidth = (s) => {
357
- // Strip CSI escapes (ESC `[` … letter). Conservative — only trims the
358
- // common ANSI color form psql emits. Newlines reset the count.
359
- const stripped = s.replace(/\x1b\[[0-9;]*[A-Za-z]/g, "");
360
- const lastNl = stripped.lastIndexOf("\n");
361
- const tail = lastNl === -1 ? stripped : stripped.slice(lastNl + 1);
362
- // Code-unit count — good enough for ASCII prompts; CJK / surrogate-pair
363
- // width handling is a printer-WP concern.
364
- return tail.length;
365
- };
366
- const currentDatabase = (ctx) => {
367
- const db = ctx.settings.db;
368
- if (!db)
369
- return "";
370
- // Prefer a libpq-style accessor if the runtime Connection exposes one;
371
- // otherwise fall back to the application's GUC view.
372
- const meta = db;
373
- if (typeof meta.database === "string" && meta.database.length > 0) {
374
- return meta.database;
375
- }
376
- return parameterStatus(ctx, "database") ?? "";
377
- };
378
- const currentUser = (ctx) => {
379
- const db = ctx.settings.db;
380
- if (!db)
381
- return "";
382
- const meta = db;
383
- if (typeof meta.user === "string" && meta.user.length > 0) {
384
- return meta.user;
385
- }
386
- return parameterStatus(ctx, "session_authorization") ?? "";
387
- };
388
- const hostString = (ctx, short) => {
389
- const db = ctx.settings.db;
390
- if (!db)
391
- return "";
392
- const meta = db;
393
- const host = typeof meta.host === "string" ? meta.host : "";
394
- if (host.length === 0 || host.startsWith("/")) {
395
- // UNIX socket / unknown — upstream emits "[local]" or "[local:path]".
396
- if (host.length === 0 || short)
397
- return "[local]";
398
- return `[local:${host}]`;
399
- }
400
- if (short) {
401
- const dot = host.indexOf(".");
402
- return dot === -1 ? host : host.slice(0, dot);
403
- }
404
- return host;
405
- };
406
- const portString = (ctx) => {
407
- const db = ctx.settings.db;
408
- if (!db)
409
- return "";
410
- const meta = db;
411
- if (typeof meta.port === "number" && Number.isFinite(meta.port)) {
412
- return String(meta.port);
413
- }
414
- if (typeof meta.port === "string" && meta.port.length > 0) {
415
- return meta.port;
416
- }
417
- return "";
418
- };
419
- const backendPid = (ctx) => {
420
- const db = ctx.settings.db;
421
- if (!db)
422
- return null;
423
- const meta = db;
424
- if (typeof meta.pid === "number" && Number.isFinite(meta.pid)) {
425
- return meta.pid;
426
- }
427
- return null;
428
- };
429
- const parameterStatus = (ctx, name) => {
430
- const db = ctx.settings.db;
431
- if (!db)
432
- return undefined;
433
- try {
434
- return db.parameterStatus(name);
435
- }
436
- catch {
437
- return undefined;
438
- }
439
- };