neonctl 2.22.0 → 2.23.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/README.md +242 -16
- package/analytics.js +5 -2
- package/commands/branches.js +9 -1
- package/commands/checkout.js +249 -0
- package/commands/connection_string.js +15 -2
- package/commands/data_api.js +286 -0
- package/commands/functions.js +277 -0
- package/commands/index.js +12 -0
- package/commands/link.js +667 -0
- package/commands/neon_auth.js +1013 -0
- package/commands/projects.js +9 -1
- package/commands/psql.js +62 -0
- package/commands/set_context.js +7 -2
- package/context.js +86 -14
- package/functions_api.js +44 -0
- package/index.js +3 -0
- package/package.json +60 -51
- package/psql/cli.js +51 -0
- package/psql/command/cmd_cond.js +437 -0
- package/psql/command/cmd_connect.js +815 -0
- package/psql/command/cmd_copy.js +1025 -0
- package/psql/command/cmd_describe.js +1810 -0
- package/psql/command/cmd_format.js +909 -0
- package/psql/command/cmd_io.js +2187 -0
- package/psql/command/cmd_lo.js +385 -0
- package/psql/command/cmd_meta.js +970 -0
- package/psql/command/cmd_misc.js +187 -0
- package/psql/command/cmd_pipeline.js +1141 -0
- package/psql/command/cmd_restrict.js +171 -0
- package/psql/command/cmd_show.js +751 -0
- package/psql/command/dispatch.js +343 -0
- package/psql/command/inputQueue.js +42 -0
- package/psql/command/shared.js +71 -0
- package/psql/complete/filenames.js +139 -0
- package/psql/complete/index.js +104 -0
- package/psql/complete/matcher.js +314 -0
- package/psql/complete/psqlVars.js +247 -0
- package/psql/complete/queries.js +491 -0
- package/psql/complete/rules.js +2387 -0
- package/psql/core/common.js +1250 -0
- package/psql/core/help.js +576 -0
- package/psql/core/mainloop.js +1353 -0
- package/psql/core/prompt.js +437 -0
- package/psql/core/settings.js +684 -0
- package/psql/core/sqlHelp.js +1066 -0
- package/psql/core/startup.js +840 -0
- package/psql/core/syncVars.js +116 -0
- package/psql/core/variables.js +287 -0
- package/psql/describe/formatters.js +1277 -0
- package/psql/describe/processNamePattern.js +270 -0
- package/psql/describe/queries.js +2373 -0
- package/psql/describe/versionGate.js +43 -0
- package/psql/index.js +2005 -0
- package/psql/io/history.js +299 -0
- package/psql/io/input.js +120 -0
- package/psql/io/lineEditor/buffer.js +323 -0
- package/psql/io/lineEditor/complete.js +227 -0
- package/psql/io/lineEditor/filename.js +159 -0
- package/psql/io/lineEditor/index.js +891 -0
- package/psql/io/lineEditor/keymap.js +738 -0
- package/psql/io/lineEditor/vt100.js +363 -0
- package/psql/io/pgpass.js +202 -0
- package/psql/io/pgservice.js +194 -0
- package/psql/io/psqlrc.js +422 -0
- package/psql/print/aligned.js +1756 -0
- package/psql/print/asciidoc.js +248 -0
- package/psql/print/crosstab.js +460 -0
- package/psql/print/csv.js +92 -0
- package/psql/print/html.js +258 -0
- package/psql/print/json.js +96 -0
- package/psql/print/latex.js +396 -0
- package/psql/print/pager.js +265 -0
- package/psql/print/troff.js +258 -0
- package/psql/print/unaligned.js +118 -0
- package/psql/print/units.js +135 -0
- package/psql/scanner/slash.js +513 -0
- package/psql/scanner/sql.js +910 -0
- package/psql/scanner/stringutils.js +390 -0
- package/psql/types/backslash.js +1 -0
- package/psql/types/connection.js +1 -0
- package/psql/types/index.js +7 -0
- package/psql/types/printer.js +1 -0
- package/psql/types/repl.js +1 -0
- package/psql/types/scanner.js +24 -0
- package/psql/types/settings.js +1 -0
- package/psql/types/variables.js +1 -0
- package/psql/wire/connection.js +2844 -0
- package/psql/wire/copy.js +108 -0
- package/psql/wire/notify.js +59 -0
- package/psql/wire/pipeline.js +519 -0
- package/psql/wire/protocol.js +466 -0
- package/psql/wire/sasl.js +296 -0
- package/psql/wire/tls.js +596 -0
- package/test_utils/fixtures.js +1 -0
- package/utils/enrichers.js +18 -1
- package/utils/esbuild.js +147 -0
- package/utils/middlewares.js +1 -1
- package/utils/psql.js +107 -11
- package/utils/zip.js +4 -0
- package/writer.js +1 -1
- package/commands/auth.test.js +0 -211
- package/commands/branches.test.js +0 -460
- package/commands/connection_string.test.js +0 -196
- package/commands/databases.test.js +0 -39
- package/commands/help.test.js +0 -9
- package/commands/init.test.js +0 -56
- package/commands/ip_allow.test.js +0 -59
- package/commands/operations.test.js +0 -7
- package/commands/orgs.test.js +0 -7
- package/commands/projects.test.js +0 -144
- package/commands/roles.test.js +0 -37
- package/commands/set_context.test.js +0 -159
- package/commands/vpc_endpoints.test.js +0 -69
- package/env.test.js +0 -55
- package/utils/formats.test.js +0 -32
- package/writer.test.js +0 -104
|
@@ -0,0 +1,840 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* psql startup-args parser + applier.
|
|
3
|
+
*
|
|
4
|
+
* TypeScript port of `parse_psql_options()` / the top of `main()` in
|
|
5
|
+
* `src/bin/psql/startup.c`. Two responsibilities:
|
|
6
|
+
*
|
|
7
|
+
* 1. `parseStartupArgs(argv)` — hand-written getopt_long-equivalent that
|
|
8
|
+
* walks the argv array once, decoding short (`-c`) and long (`--command`)
|
|
9
|
+
* options, and accumulates an ordered list of `-c`/`-f` actions plus a
|
|
10
|
+
* bag of settings flags. Positional arguments follow the upstream
|
|
11
|
+
* `[DBNAME [USERNAME]]` rule.
|
|
12
|
+
*
|
|
13
|
+
* We hand-roll the parser instead of pulling in `yargs` (or similar)
|
|
14
|
+
* because upstream psql has subtle precedence rules — actions are
|
|
15
|
+
* ordered, `-v NAME` without `=` deletes the variable, `-X` interacts
|
|
16
|
+
* with `.psqlrc` discovery, etc. The parser stays under ~250 LOC and is
|
|
17
|
+
* fully covered by unit tests.
|
|
18
|
+
*
|
|
19
|
+
* 2. `applyStartupArgs(args, settings, baseConnect)` — mutates `settings`
|
|
20
|
+
* (and its var store) in-place to reflect parsed flags, then returns
|
|
21
|
+
* the connect options the caller should use plus the ordered list of
|
|
22
|
+
* pre-REPL actions to execute (currently just `-c` / `-f`).
|
|
23
|
+
*
|
|
24
|
+
* Out-of-scope for WP-26 but the table mentions them so they're listed below:
|
|
25
|
+
* - `-1` / `--single-transaction` — we accept and record on the args but
|
|
26
|
+
* do not wire its semantics in the caller. Tracked for a follow-up.
|
|
27
|
+
* - `-C` — accepted as a no-op (since-PG17 connection-check skip).
|
|
28
|
+
* - `-l` / `--list` — recorded; the caller may use it later to short-circuit
|
|
29
|
+
* the REPL with a `\l` and exit. Not wired here.
|
|
30
|
+
* - `-L logfile`, `-o output` — recorded on args. Routing into the printer
|
|
31
|
+
* is owned by other WPs (logfile streaming and output redirection).
|
|
32
|
+
* - `--help[=topic]` — returns a ParseError with `kind: 'help'` and the
|
|
33
|
+
* help text already rendered as `message`. Caller writes and exits 0.
|
|
34
|
+
* - `-V` / `--version` — returns `kind: 'version'` with the version string.
|
|
35
|
+
* Caller writes and exits 0.
|
|
36
|
+
*
|
|
37
|
+
* Help/version text is rendered through `./help.ts` so the formatting stays
|
|
38
|
+
* in lock-step with `\?` output (WP-18). The version string mirrors upstream
|
|
39
|
+
* `psql (PostgreSQL) PG_VERSION` and is currently hard-coded — the embedded
|
|
40
|
+
* psql doesn't have a build-system PG_VERSION constant. A follow-up could
|
|
41
|
+
* surface the real PG version from a const, but for now we expose the
|
|
42
|
+
* embedded build's version label.
|
|
43
|
+
*/
|
|
44
|
+
import { envConnectionDefaults, libpqConnectionDefaults, looksLikeConnectionString, mergeConnectOptions, parseConninfo, parseConnectionUriPartial, serviceEntryToConnectOptions, } from '../index.js';
|
|
45
|
+
import { lookupPgPass } from '../io/pgpass.js';
|
|
46
|
+
import { setStartupVars } from './syncVars.js';
|
|
47
|
+
import { helpVariables, slashUsage, usage } from './help.js';
|
|
48
|
+
// ---------------------------------------------------------------------------
|
|
49
|
+
// Internal helpers.
|
|
50
|
+
// ---------------------------------------------------------------------------
|
|
51
|
+
/** Short options that consume the next argv slot (or attached value). */
|
|
52
|
+
const SHORT_WITH_ARG = new Set([
|
|
53
|
+
'c',
|
|
54
|
+
'd',
|
|
55
|
+
'f',
|
|
56
|
+
'F',
|
|
57
|
+
'h',
|
|
58
|
+
'L',
|
|
59
|
+
'o',
|
|
60
|
+
'p',
|
|
61
|
+
'P',
|
|
62
|
+
'R',
|
|
63
|
+
'T',
|
|
64
|
+
'U',
|
|
65
|
+
'v',
|
|
66
|
+
]);
|
|
67
|
+
/** Short flags (no argument). */
|
|
68
|
+
const SHORT_NO_ARG = new Set([
|
|
69
|
+
'a',
|
|
70
|
+
'A',
|
|
71
|
+
'b',
|
|
72
|
+
'C',
|
|
73
|
+
'e',
|
|
74
|
+
'E',
|
|
75
|
+
'H',
|
|
76
|
+
'l',
|
|
77
|
+
'n',
|
|
78
|
+
'q',
|
|
79
|
+
's',
|
|
80
|
+
'S',
|
|
81
|
+
't',
|
|
82
|
+
'V',
|
|
83
|
+
'w',
|
|
84
|
+
'W',
|
|
85
|
+
'x',
|
|
86
|
+
'X',
|
|
87
|
+
'z',
|
|
88
|
+
'0',
|
|
89
|
+
'1',
|
|
90
|
+
'?',
|
|
91
|
+
]);
|
|
92
|
+
/** Long option → canonical short equivalent (or sentinel string). */
|
|
93
|
+
const LONG_MAP = {
|
|
94
|
+
'echo-all': 'a',
|
|
95
|
+
'no-align': 'A',
|
|
96
|
+
command: 'c',
|
|
97
|
+
dbname: 'd',
|
|
98
|
+
'echo-queries': 'e',
|
|
99
|
+
'echo-errors': 'b',
|
|
100
|
+
'echo-hidden': 'E',
|
|
101
|
+
file: 'f',
|
|
102
|
+
'field-separator': 'F',
|
|
103
|
+
'field-separator-zero': 'z',
|
|
104
|
+
host: 'h',
|
|
105
|
+
html: 'H',
|
|
106
|
+
list: 'l',
|
|
107
|
+
'log-file': 'L',
|
|
108
|
+
'no-readline': 'n',
|
|
109
|
+
'single-transaction': '1',
|
|
110
|
+
output: 'o',
|
|
111
|
+
port: 'p',
|
|
112
|
+
pset: 'P',
|
|
113
|
+
quiet: 'q',
|
|
114
|
+
'record-separator': 'R',
|
|
115
|
+
'record-separator-zero': '0',
|
|
116
|
+
'single-step': 's',
|
|
117
|
+
'single-line': 'S',
|
|
118
|
+
'tuples-only': 't',
|
|
119
|
+
'table-attr': 'T',
|
|
120
|
+
username: 'U',
|
|
121
|
+
set: 'v',
|
|
122
|
+
variable: 'v',
|
|
123
|
+
version: 'V',
|
|
124
|
+
'no-password': 'w',
|
|
125
|
+
password: 'W',
|
|
126
|
+
expanded: 'x',
|
|
127
|
+
'no-psqlrc': 'X',
|
|
128
|
+
'no-pager': '__no_pager__',
|
|
129
|
+
'on-error-stop': '__on_error_stop__',
|
|
130
|
+
help: '__help__',
|
|
131
|
+
csv: '__csv__',
|
|
132
|
+
};
|
|
133
|
+
/** Long options that REQUIRE an attached value (or one in the next argv). */
|
|
134
|
+
const LONG_WITH_ARG = new Set([
|
|
135
|
+
'command',
|
|
136
|
+
'dbname',
|
|
137
|
+
'file',
|
|
138
|
+
'field-separator',
|
|
139
|
+
'host',
|
|
140
|
+
'log-file',
|
|
141
|
+
'output',
|
|
142
|
+
'port',
|
|
143
|
+
'pset',
|
|
144
|
+
'record-separator',
|
|
145
|
+
'table-attr',
|
|
146
|
+
'username',
|
|
147
|
+
'set',
|
|
148
|
+
'variable',
|
|
149
|
+
]);
|
|
150
|
+
/** Long options whose value is optional (only attached with `=`). */
|
|
151
|
+
const LONG_OPTIONAL_ARG = new Set(['help', 'echo-hidden']);
|
|
152
|
+
const blankArgs = () => ({
|
|
153
|
+
actions: [],
|
|
154
|
+
variables: [],
|
|
155
|
+
noPsqlrc: false,
|
|
156
|
+
noReadline: false,
|
|
157
|
+
echoAll: false,
|
|
158
|
+
echoHidden: 'off',
|
|
159
|
+
echoErrors: false,
|
|
160
|
+
echoQueries: false,
|
|
161
|
+
quiet: false,
|
|
162
|
+
singleline: false,
|
|
163
|
+
singlestep: false,
|
|
164
|
+
noAlign: false,
|
|
165
|
+
noPager: false,
|
|
166
|
+
htmlMode: false,
|
|
167
|
+
tuplesOnly: false,
|
|
168
|
+
expanded: false,
|
|
169
|
+
csvOutput: false,
|
|
170
|
+
onErrorStop: false,
|
|
171
|
+
fieldSepZero: false,
|
|
172
|
+
recordSepZero: false,
|
|
173
|
+
pset: [],
|
|
174
|
+
list: false,
|
|
175
|
+
singleTransaction: false,
|
|
176
|
+
help: false,
|
|
177
|
+
version: false,
|
|
178
|
+
positional: [],
|
|
179
|
+
});
|
|
180
|
+
const renderToString = (fn) => {
|
|
181
|
+
const chunks = [];
|
|
182
|
+
const sink = {
|
|
183
|
+
write(chunk) {
|
|
184
|
+
chunks.push(typeof chunk === 'string' ? chunk : Buffer.from(chunk).toString('utf8'));
|
|
185
|
+
return true;
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
fn(sink);
|
|
189
|
+
return chunks.join('');
|
|
190
|
+
};
|
|
191
|
+
const renderHelp = (topic) => {
|
|
192
|
+
if (topic === undefined || topic === 'options') {
|
|
193
|
+
return renderToString((out) => {
|
|
194
|
+
usage(out);
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
if (topic === 'commands') {
|
|
198
|
+
return renderToString((out) => {
|
|
199
|
+
slashUsage(out, false);
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
if (topic === 'variables') {
|
|
203
|
+
return renderToString((out) => {
|
|
204
|
+
helpVariables(out);
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
return '';
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* Version label for the embedded TypeScript psql. This is the "client"
|
|
211
|
+
* identifier — the analogue of upstream psql's compiled-in `PG_VERSION`.
|
|
212
|
+
* The embedded psql is not a real PostgreSQL build, so we track our own
|
|
213
|
+
* implementation version here. It seeds the `VERSION_NAME` psql var (and,
|
|
214
|
+
* via {@link setStartupVars}, the numeric `VERSION_NUM`); keep it as a
|
|
215
|
+
* `MAJOR.MINOR.PATCH` string so the numeric mapping stays meaningful. Bump
|
|
216
|
+
* alongside meaningful behaviour changes to the embedded psql.
|
|
217
|
+
*/
|
|
218
|
+
export const CLIENT_VERSION = '1.0.0';
|
|
219
|
+
// `psql --version` / `-V` output. Mirrors upstream's `psql (PostgreSQL)
|
|
220
|
+
// <PG_VERSION>` SHAPE (tools parse the leading `psql (PostgreSQL)`), with an
|
|
221
|
+
// `embedded-ts` label in place of a real PG build number since this is a
|
|
222
|
+
// reimplementation, not a compiled psql. Distinct from the `:VERSION` psql
|
|
223
|
+
// variable (the client-identity string seeded from CLIENT_VERSION).
|
|
224
|
+
const VERSION_STRING = `psql (PostgreSQL) embedded-ts (neonctl ${CLIENT_VERSION})`;
|
|
225
|
+
const pushAction = (acts, a) => {
|
|
226
|
+
acts.push(a);
|
|
227
|
+
};
|
|
228
|
+
const pushVariable = (vars, raw) => {
|
|
229
|
+
const eq = raw.indexOf('=');
|
|
230
|
+
if (eq < 0) {
|
|
231
|
+
// psql treats `-v NAME` (no value) as "delete this variable". We surface
|
|
232
|
+
// an empty value; the caller decides whether to set or unset. Tests
|
|
233
|
+
// verify both shapes.
|
|
234
|
+
vars.push({ name: raw, value: '' });
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
vars.push({ name: raw.slice(0, eq), value: raw.slice(eq + 1) });
|
|
238
|
+
};
|
|
239
|
+
/**
|
|
240
|
+
* `-d VALUE` resolution. libpq accepts three shapes for the value:
|
|
241
|
+
*
|
|
242
|
+
* 1. Bare database name (no `=`, no `postgres[ql]://` prefix) — set
|
|
243
|
+
* `args.database` directly. This is by far the common case.
|
|
244
|
+
* 2. Connection URI (`postgresql://…` / `postgres://…`) — parse it and
|
|
245
|
+
* lift the fields it specifies onto `args` (host, port, user, etc.).
|
|
246
|
+
* 3. Conninfo key=value pairs separated by whitespace — same, but parsed
|
|
247
|
+
* via `parseConninfo`.
|
|
248
|
+
*
|
|
249
|
+
* The test corpus for upstream `001_basic.pl` uses shape (3) to open a
|
|
250
|
+
* walsender connection: `-d "dbname=postgres replication=database"`. We
|
|
251
|
+
* fold any conninfo-only fields (currently only `replication`) onto a
|
|
252
|
+
* dedicated `args.replication` slot that `applyStartupArgs` threads into
|
|
253
|
+
* `ConnectOptions.replication`.
|
|
254
|
+
*/
|
|
255
|
+
const applyDashD = (args, value) => {
|
|
256
|
+
if (!looksLikeConnectionString(value)) {
|
|
257
|
+
args.database = value;
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
// Use the *partial* URI parser, NOT parseConnectionUri: the latter applies
|
|
261
|
+
// libpq's lowest-priority OS-user fallback (`user = $USER`, `database =
|
|
262
|
+
// user`) eagerly, and those non-undefined defaults would then land in the
|
|
263
|
+
// top-priority argv layer and override `PGUSER` / `PGDATABASE` (review #7).
|
|
264
|
+
// The partial parser returns only the keys the URI actually specified.
|
|
265
|
+
const parsed = value.startsWith('postgresql://') || value.startsWith('postgres://')
|
|
266
|
+
? parseConnectionUriPartial(value)
|
|
267
|
+
: parseConninfo(value);
|
|
268
|
+
// Keep the whole partial (incl. ssl*/channelBinding/hostaddr/requireAuth)
|
|
269
|
+
// so the connection layer carries it (review #6).
|
|
270
|
+
args.dashD = { ...(args.dashD ?? {}), ...parsed };
|
|
271
|
+
// Continue to mirror the core target fields onto the flag slots so the
|
|
272
|
+
// positional-arg / dbname-username precedence logic below sees them. Only
|
|
273
|
+
// when not already set by an explicit flag (flags win over -d).
|
|
274
|
+
if (parsed.host !== undefined && args.host === undefined) {
|
|
275
|
+
args.host = parsed.host;
|
|
276
|
+
}
|
|
277
|
+
if (parsed.port !== undefined && args.port === undefined) {
|
|
278
|
+
args.port = parsed.port;
|
|
279
|
+
}
|
|
280
|
+
if (parsed.user !== undefined && args.user === undefined) {
|
|
281
|
+
args.user = parsed.user;
|
|
282
|
+
}
|
|
283
|
+
if (parsed.password !== undefined && args.password === undefined) {
|
|
284
|
+
args.password = parsed.password;
|
|
285
|
+
}
|
|
286
|
+
if (parsed.database !== undefined && args.database === undefined) {
|
|
287
|
+
args.database = parsed.database;
|
|
288
|
+
}
|
|
289
|
+
if (parsed.replication !== undefined) {
|
|
290
|
+
args.replication = parsed.replication;
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
// ---------------------------------------------------------------------------
|
|
294
|
+
// parseStartupArgs.
|
|
295
|
+
// ---------------------------------------------------------------------------
|
|
296
|
+
export const parseStartupArgs = (argv) => {
|
|
297
|
+
const args = blankArgs();
|
|
298
|
+
const actions = [];
|
|
299
|
+
const variables = [];
|
|
300
|
+
const pset = [];
|
|
301
|
+
let i = 0;
|
|
302
|
+
const n = argv.length;
|
|
303
|
+
const needValue = (flagDisplay) => {
|
|
304
|
+
if (i + 1 >= n) {
|
|
305
|
+
return {
|
|
306
|
+
kind: 'missing-arg',
|
|
307
|
+
message: `option requires an argument -- ${flagDisplay}`,
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
i += 1;
|
|
311
|
+
return argv[i];
|
|
312
|
+
};
|
|
313
|
+
const applyShort = (letter, attachedValue, flagDisplay) => {
|
|
314
|
+
// Resolve the value: either attached (already next to the flag) or the
|
|
315
|
+
// next argv slot. If the flag does not take an argument, attachedValue
|
|
316
|
+
// must be undefined.
|
|
317
|
+
const takesArg = SHORT_WITH_ARG.has(letter);
|
|
318
|
+
let value;
|
|
319
|
+
if (takesArg) {
|
|
320
|
+
if (attachedValue !== undefined) {
|
|
321
|
+
value = attachedValue;
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
const v = needValue(flagDisplay);
|
|
325
|
+
if (typeof v !== 'string')
|
|
326
|
+
return v;
|
|
327
|
+
value = v;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
else if (attachedValue !== undefined) {
|
|
331
|
+
// A value was attached to a short flag that doesn't accept one. Treat
|
|
332
|
+
// this as an invalid-option error (matches `getopt_long` behaviour
|
|
333
|
+
// for clusters like `-Xy` where `X` doesn't take an argument — flex
|
|
334
|
+
// continues to `y`; we keep it strict for clarity).
|
|
335
|
+
return {
|
|
336
|
+
kind: 'invalid-option',
|
|
337
|
+
message: `option does not take an argument -- ${letter}`,
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
switch (letter) {
|
|
341
|
+
case 'a':
|
|
342
|
+
args.echoAll = true;
|
|
343
|
+
return null;
|
|
344
|
+
case 'A':
|
|
345
|
+
args.noAlign = true;
|
|
346
|
+
return null;
|
|
347
|
+
case 'b':
|
|
348
|
+
args.echoErrors = true;
|
|
349
|
+
return null;
|
|
350
|
+
case 'C':
|
|
351
|
+
// Since-PG17 "skip connection check" — no-op for our use.
|
|
352
|
+
return null;
|
|
353
|
+
case 'c':
|
|
354
|
+
pushAction(actions, { kind: 'command', sql: value });
|
|
355
|
+
return null;
|
|
356
|
+
case 'd':
|
|
357
|
+
applyDashD(args, value);
|
|
358
|
+
return null;
|
|
359
|
+
case 'e':
|
|
360
|
+
args.echoQueries = true;
|
|
361
|
+
return null;
|
|
362
|
+
case 'E':
|
|
363
|
+
args.echoHidden = 'on';
|
|
364
|
+
return null;
|
|
365
|
+
case 'f':
|
|
366
|
+
pushAction(actions, { kind: 'file', path: value });
|
|
367
|
+
return null;
|
|
368
|
+
case 'F':
|
|
369
|
+
args.fieldSep = value;
|
|
370
|
+
args.fieldSepZero = false;
|
|
371
|
+
return null;
|
|
372
|
+
case 'h':
|
|
373
|
+
args.host = value;
|
|
374
|
+
return null;
|
|
375
|
+
case 'H':
|
|
376
|
+
args.htmlMode = true;
|
|
377
|
+
return null;
|
|
378
|
+
case 'l':
|
|
379
|
+
args.list = true;
|
|
380
|
+
return null;
|
|
381
|
+
case 'L':
|
|
382
|
+
args.log = value;
|
|
383
|
+
return null;
|
|
384
|
+
case 'n':
|
|
385
|
+
args.noReadline = true;
|
|
386
|
+
return null;
|
|
387
|
+
case 'o':
|
|
388
|
+
args.output = value;
|
|
389
|
+
return null;
|
|
390
|
+
case 'p': {
|
|
391
|
+
const p = Number.parseInt(value, 10);
|
|
392
|
+
if (!Number.isFinite(p) || p <= 0 || p > 65535) {
|
|
393
|
+
return {
|
|
394
|
+
kind: 'invalid-value',
|
|
395
|
+
message: `invalid port number: "${value}"`,
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
args.port = p;
|
|
399
|
+
return null;
|
|
400
|
+
}
|
|
401
|
+
case 'P':
|
|
402
|
+
pset.push(value);
|
|
403
|
+
return null;
|
|
404
|
+
case 'q':
|
|
405
|
+
args.quiet = true;
|
|
406
|
+
return null;
|
|
407
|
+
case 'R':
|
|
408
|
+
args.recordSep = value;
|
|
409
|
+
args.recordSepZero = false;
|
|
410
|
+
return null;
|
|
411
|
+
case 's':
|
|
412
|
+
args.singlestep = true;
|
|
413
|
+
return null;
|
|
414
|
+
case 'S':
|
|
415
|
+
args.singleline = true;
|
|
416
|
+
return null;
|
|
417
|
+
case 't':
|
|
418
|
+
args.tuplesOnly = true;
|
|
419
|
+
return null;
|
|
420
|
+
case 'T':
|
|
421
|
+
// -T TEXT → push a synthetic pset directive so it routes through
|
|
422
|
+
// the same `\pset tableattr` plumbing.
|
|
423
|
+
pset.push(`tableattr=${value}`);
|
|
424
|
+
return null;
|
|
425
|
+
case 'U':
|
|
426
|
+
args.user = value;
|
|
427
|
+
return null;
|
|
428
|
+
case 'v':
|
|
429
|
+
pushVariable(variables, value);
|
|
430
|
+
return null;
|
|
431
|
+
case 'V':
|
|
432
|
+
return {
|
|
433
|
+
kind: 'version',
|
|
434
|
+
message: VERSION_STRING,
|
|
435
|
+
};
|
|
436
|
+
case 'w':
|
|
437
|
+
args.promptPassword = false;
|
|
438
|
+
return null;
|
|
439
|
+
case 'W':
|
|
440
|
+
args.promptPassword = true;
|
|
441
|
+
return null;
|
|
442
|
+
case 'x':
|
|
443
|
+
args.expanded = true;
|
|
444
|
+
return null;
|
|
445
|
+
case 'X':
|
|
446
|
+
args.noPsqlrc = true;
|
|
447
|
+
return null;
|
|
448
|
+
case 'z':
|
|
449
|
+
args.fieldSepZero = true;
|
|
450
|
+
return null;
|
|
451
|
+
case '0':
|
|
452
|
+
args.recordSepZero = true;
|
|
453
|
+
return null;
|
|
454
|
+
case '1':
|
|
455
|
+
args.singleTransaction = true;
|
|
456
|
+
return null;
|
|
457
|
+
case '?':
|
|
458
|
+
return {
|
|
459
|
+
kind: 'help',
|
|
460
|
+
message: renderHelp(undefined),
|
|
461
|
+
};
|
|
462
|
+
default:
|
|
463
|
+
return {
|
|
464
|
+
kind: 'invalid-option',
|
|
465
|
+
message: `invalid option -- ${letter}`,
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
// ---- Main loop. -------------------------------------------------------
|
|
470
|
+
while (i < n) {
|
|
471
|
+
const tok = argv[i];
|
|
472
|
+
if (tok === '--') {
|
|
473
|
+
// End of options. Everything after is positional.
|
|
474
|
+
i += 1;
|
|
475
|
+
while (i < n) {
|
|
476
|
+
args.positional.push(argv[i]);
|
|
477
|
+
i += 1;
|
|
478
|
+
}
|
|
479
|
+
break;
|
|
480
|
+
}
|
|
481
|
+
if (tok.startsWith('--')) {
|
|
482
|
+
// Long option: `--name` or `--name=value`.
|
|
483
|
+
const eq = tok.indexOf('=');
|
|
484
|
+
const name = eq < 0 ? tok.slice(2) : tok.slice(2, eq);
|
|
485
|
+
const attached = eq < 0 ? undefined : tok.slice(eq + 1);
|
|
486
|
+
// Special-case the long-only synthetic options first.
|
|
487
|
+
if (name === 'csv') {
|
|
488
|
+
if (attached !== undefined) {
|
|
489
|
+
return {
|
|
490
|
+
kind: 'invalid-option',
|
|
491
|
+
message: `option does not take an argument: --${name}`,
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
args.csvOutput = true;
|
|
495
|
+
i += 1;
|
|
496
|
+
continue;
|
|
497
|
+
}
|
|
498
|
+
if (name === 'no-pager') {
|
|
499
|
+
if (attached !== undefined) {
|
|
500
|
+
return {
|
|
501
|
+
kind: 'invalid-option',
|
|
502
|
+
message: `option does not take an argument: --${name}`,
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
args.noPager = true;
|
|
506
|
+
i += 1;
|
|
507
|
+
continue;
|
|
508
|
+
}
|
|
509
|
+
if (name === 'on-error-stop') {
|
|
510
|
+
if (attached !== undefined) {
|
|
511
|
+
return {
|
|
512
|
+
kind: 'invalid-option',
|
|
513
|
+
message: `option does not take an argument: --${name}`,
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
args.onErrorStop = true;
|
|
517
|
+
variables.push({ name: 'ON_ERROR_STOP', value: 'on' });
|
|
518
|
+
i += 1;
|
|
519
|
+
continue;
|
|
520
|
+
}
|
|
521
|
+
if (name === 'help') {
|
|
522
|
+
const topic = attached;
|
|
523
|
+
if (topic !== undefined &&
|
|
524
|
+
topic !== 'options' &&
|
|
525
|
+
topic !== 'commands' &&
|
|
526
|
+
topic !== 'variables') {
|
|
527
|
+
return {
|
|
528
|
+
kind: 'invalid-option',
|
|
529
|
+
message: `unrecognized help topic: ${topic}`,
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
return { kind: 'help', message: renderHelp(topic) };
|
|
533
|
+
}
|
|
534
|
+
if (name === 'echo-hidden') {
|
|
535
|
+
if (attached === undefined) {
|
|
536
|
+
args.echoHidden = 'on';
|
|
537
|
+
}
|
|
538
|
+
else if (attached === 'noexec') {
|
|
539
|
+
args.echoHidden = 'noexec';
|
|
540
|
+
}
|
|
541
|
+
else if (attached === '' || attached === 'on') {
|
|
542
|
+
args.echoHidden = 'on';
|
|
543
|
+
}
|
|
544
|
+
else {
|
|
545
|
+
return {
|
|
546
|
+
kind: 'invalid-value',
|
|
547
|
+
message: `invalid value for --echo-hidden: "${attached}"`,
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
i += 1;
|
|
551
|
+
continue;
|
|
552
|
+
}
|
|
553
|
+
const short = LONG_MAP[name];
|
|
554
|
+
if (short === undefined) {
|
|
555
|
+
return {
|
|
556
|
+
kind: 'invalid-option',
|
|
557
|
+
message: `unrecognized option: --${name}`,
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
const requiresArg = LONG_WITH_ARG.has(name);
|
|
561
|
+
const optionalArg = LONG_OPTIONAL_ARG.has(name);
|
|
562
|
+
let value = attached;
|
|
563
|
+
if (requiresArg && value === undefined) {
|
|
564
|
+
if (i + 1 >= n) {
|
|
565
|
+
return {
|
|
566
|
+
kind: 'missing-arg',
|
|
567
|
+
message: `option requires an argument: --${name}`,
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
i += 1;
|
|
571
|
+
value = argv[i];
|
|
572
|
+
}
|
|
573
|
+
else if (!requiresArg && !optionalArg && value !== undefined) {
|
|
574
|
+
return {
|
|
575
|
+
kind: 'invalid-option',
|
|
576
|
+
message: `option does not take an argument: --${name}`,
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
const err = applyShort(short, value, `--${name}`);
|
|
580
|
+
if (err)
|
|
581
|
+
return err;
|
|
582
|
+
i += 1;
|
|
583
|
+
continue;
|
|
584
|
+
}
|
|
585
|
+
if (tok.startsWith('-') && tok.length > 1) {
|
|
586
|
+
// Short option cluster. Each char might consume the rest of the token
|
|
587
|
+
// (or the next argv) as its value.
|
|
588
|
+
let k = 1;
|
|
589
|
+
while (k < tok.length) {
|
|
590
|
+
const letter = tok[k];
|
|
591
|
+
if (!SHORT_WITH_ARG.has(letter) && !SHORT_NO_ARG.has(letter)) {
|
|
592
|
+
return {
|
|
593
|
+
kind: 'invalid-option',
|
|
594
|
+
message: `invalid option -- ${letter}`,
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
if (SHORT_WITH_ARG.has(letter)) {
|
|
598
|
+
// Consume the rest of this token as the value if anything remains,
|
|
599
|
+
// otherwise pull from the next argv.
|
|
600
|
+
const remainder = tok.slice(k + 1);
|
|
601
|
+
const value = remainder.length > 0 ? remainder : undefined;
|
|
602
|
+
const err = applyShort(letter, value, letter);
|
|
603
|
+
if (err)
|
|
604
|
+
return err;
|
|
605
|
+
k = tok.length; // Consumed the rest.
|
|
606
|
+
break;
|
|
607
|
+
}
|
|
608
|
+
const err = applyShort(letter, undefined, letter);
|
|
609
|
+
if (err)
|
|
610
|
+
return err;
|
|
611
|
+
k += 1;
|
|
612
|
+
}
|
|
613
|
+
i += 1;
|
|
614
|
+
continue;
|
|
615
|
+
}
|
|
616
|
+
// Positional.
|
|
617
|
+
args.positional.push(tok);
|
|
618
|
+
i += 1;
|
|
619
|
+
}
|
|
620
|
+
// Upstream consumes only DBNAME and USERNAME from positionals; extras are
|
|
621
|
+
// warned about and ignored. We surface them all on `positional` so the
|
|
622
|
+
// caller can warn/log; applyStartupArgs takes care of the first two.
|
|
623
|
+
return {
|
|
624
|
+
...args,
|
|
625
|
+
actions,
|
|
626
|
+
variables,
|
|
627
|
+
pset,
|
|
628
|
+
};
|
|
629
|
+
};
|
|
630
|
+
export const applyStartupArgs = (args, settings, baseConnectOpts, resolution) => {
|
|
631
|
+
// -------- 0) Constant client-version vars. -----------------------------
|
|
632
|
+
// Seed VERSION / VERSION_NAME / VERSION_NUM once (upstream seeds these from
|
|
633
|
+
// its compiled-in PG_VERSION before reading psqlrc / CLI vars). Done before
|
|
634
|
+
// the `-v` loop so a user-supplied `-v VERSION=…` still wins.
|
|
635
|
+
setStartupVars(settings.vars, CLIENT_VERSION);
|
|
636
|
+
// -------- 1) Variable assignments. -------------------------------------
|
|
637
|
+
for (const v of args.variables) {
|
|
638
|
+
if (v.value === '') {
|
|
639
|
+
// Mirror upstream `-v NAME` (no `=`): DeleteVariable.
|
|
640
|
+
settings.vars.unset(v.name);
|
|
641
|
+
}
|
|
642
|
+
else {
|
|
643
|
+
settings.vars.set(v.name, v.value);
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
// -------- 2) Settings flags. -------------------------------------------
|
|
647
|
+
if (args.echoAll)
|
|
648
|
+
settings.vars.set('ECHO', 'all');
|
|
649
|
+
if (args.echoErrors)
|
|
650
|
+
settings.vars.set('ECHO', 'errors');
|
|
651
|
+
if (args.echoQueries)
|
|
652
|
+
settings.vars.set('ECHO', 'queries');
|
|
653
|
+
if (args.echoHidden !== 'off') {
|
|
654
|
+
settings.echoHidden = args.echoHidden;
|
|
655
|
+
settings.vars.set('ECHO_HIDDEN', args.echoHidden === 'noexec' ? 'noexec' : 'on');
|
|
656
|
+
}
|
|
657
|
+
if (args.quiet) {
|
|
658
|
+
settings.quiet = true;
|
|
659
|
+
settings.vars.set('QUIET', 'on');
|
|
660
|
+
}
|
|
661
|
+
if (args.singleline) {
|
|
662
|
+
settings.singleline = true;
|
|
663
|
+
settings.vars.set('SINGLELINE', 'on');
|
|
664
|
+
}
|
|
665
|
+
if (args.singlestep) {
|
|
666
|
+
settings.singlestep = true;
|
|
667
|
+
settings.vars.set('SINGLESTEP', 'on');
|
|
668
|
+
}
|
|
669
|
+
if (args.onErrorStop) {
|
|
670
|
+
settings.onErrorStop = true;
|
|
671
|
+
settings.vars.set('ON_ERROR_STOP', 'on');
|
|
672
|
+
}
|
|
673
|
+
// -------- 3) Output formatting. ----------------------------------------
|
|
674
|
+
if (args.noAlign) {
|
|
675
|
+
settings.popt.topt.format = 'unaligned';
|
|
676
|
+
}
|
|
677
|
+
if (args.htmlMode) {
|
|
678
|
+
settings.popt.topt.format = 'html';
|
|
679
|
+
}
|
|
680
|
+
if (args.csvOutput) {
|
|
681
|
+
settings.popt.topt.format = 'csv';
|
|
682
|
+
}
|
|
683
|
+
if (args.tuplesOnly) {
|
|
684
|
+
settings.popt.topt.tuplesOnly = true;
|
|
685
|
+
}
|
|
686
|
+
if (args.expanded) {
|
|
687
|
+
settings.popt.topt.expanded = 'on';
|
|
688
|
+
}
|
|
689
|
+
if (args.fieldSepZero) {
|
|
690
|
+
settings.popt.topt.fieldSep = '\0';
|
|
691
|
+
}
|
|
692
|
+
else if (args.fieldSep !== undefined) {
|
|
693
|
+
settings.popt.topt.fieldSep = args.fieldSep;
|
|
694
|
+
}
|
|
695
|
+
if (args.recordSepZero) {
|
|
696
|
+
settings.popt.topt.recordSep = '\0';
|
|
697
|
+
}
|
|
698
|
+
else if (args.recordSep !== undefined) {
|
|
699
|
+
settings.popt.topt.recordSep = args.recordSep;
|
|
700
|
+
}
|
|
701
|
+
if (args.noPager) {
|
|
702
|
+
settings.popt.topt.pager = 'off';
|
|
703
|
+
}
|
|
704
|
+
// -------- 4) pset directives. ------------------------------------------
|
|
705
|
+
// We don't have a parsed `do_pset` here yet (lives in command/cmd_format),
|
|
706
|
+
// so we surface them as raw strings and let the integration layer feed
|
|
707
|
+
// them through once parsed. For tableattr (the most common -T use), apply
|
|
708
|
+
// directly.
|
|
709
|
+
for (const directive of args.pset) {
|
|
710
|
+
const eq = directive.indexOf('=');
|
|
711
|
+
if (eq >= 0) {
|
|
712
|
+
const key = directive.slice(0, eq);
|
|
713
|
+
const val = directive.slice(eq + 1);
|
|
714
|
+
if (key === 'tableattr' || key === 'T') {
|
|
715
|
+
settings.popt.topt.tableAttr = val.length > 0 ? val : null;
|
|
716
|
+
}
|
|
717
|
+
else if (key === 'pager') {
|
|
718
|
+
if (val === 'on' || val === 'off' || val === 'always') {
|
|
719
|
+
settings.popt.topt.pager = val;
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
// Other directives left to the broader -P plumbing.
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
// -------- 5) Connection overrides. -------------------------------------
|
|
726
|
+
// Positional args follow upstream: positional[0] → dbname, positional[1] →
|
|
727
|
+
// username (if not already set by a flag).
|
|
728
|
+
let dbname = args.database;
|
|
729
|
+
let username = args.user;
|
|
730
|
+
if (args.positional[0] && !dbname)
|
|
731
|
+
dbname = args.positional[0];
|
|
732
|
+
if (args.positional[1] && !username)
|
|
733
|
+
username = args.positional[1];
|
|
734
|
+
// The argv flag layer mirrors the highest-priority CLI inputs (`-h`/`-p`
|
|
735
|
+
// / positional DBNAME / etc). Only populated entries end up in the layer
|
|
736
|
+
// so they don't accidentally clobber URI/env values.
|
|
737
|
+
// Seed with the full `-d` partial (carries ssl*/channelBinding/hostaddr/
|
|
738
|
+
// requireAuth — review #6), then overlay the explicit flag/positional
|
|
739
|
+
// values so `-h`/`-p`/`-U`/`-W`/positional still take precedence over `-d`.
|
|
740
|
+
const argvLayer = { ...(args.dashD ?? {}) };
|
|
741
|
+
if (args.host !== undefined)
|
|
742
|
+
argvLayer.host = args.host;
|
|
743
|
+
if (args.port !== undefined)
|
|
744
|
+
argvLayer.port = args.port;
|
|
745
|
+
if (username !== undefined)
|
|
746
|
+
argvLayer.user = username;
|
|
747
|
+
if (dbname !== undefined)
|
|
748
|
+
argvLayer.database = dbname;
|
|
749
|
+
if (args.password !== undefined)
|
|
750
|
+
argvLayer.password = args.password;
|
|
751
|
+
if (args.replication !== undefined)
|
|
752
|
+
argvLayer.replication = args.replication;
|
|
753
|
+
// Two modes:
|
|
754
|
+
// - LEGACY: no `resolution` provided → behave exactly like before, with
|
|
755
|
+
// `baseConnectOpts` supplying every default and argv overriding it.
|
|
756
|
+
// - LAYERED: `resolution` provided → run the full vanilla-psql chain.
|
|
757
|
+
let connect;
|
|
758
|
+
if (resolution === undefined) {
|
|
759
|
+
const base = baseConnectOpts ?? {
|
|
760
|
+
host: 'localhost',
|
|
761
|
+
port: 5432,
|
|
762
|
+
user: '',
|
|
763
|
+
database: '',
|
|
764
|
+
ssl: 'prefer',
|
|
765
|
+
};
|
|
766
|
+
connect = { ...base, ...argvLayer };
|
|
767
|
+
}
|
|
768
|
+
else {
|
|
769
|
+
connect = resolveLayeredConnect(argvLayer, resolution, baseConnectOpts);
|
|
770
|
+
}
|
|
771
|
+
return { connect, preActions: args.actions };
|
|
772
|
+
};
|
|
773
|
+
/**
|
|
774
|
+
* Run the layered connection-parameter merge.
|
|
775
|
+
*
|
|
776
|
+
* argv > URI partial > PG* env > .pgpass (password only) > service > libpq defaults
|
|
777
|
+
*
|
|
778
|
+
* `baseConnectOpts` (the legacy `ConnectOptions` argument) is treated as a
|
|
779
|
+
* pre-baked URI partial when the resolution path is used WITHOUT an explicit
|
|
780
|
+
* `uriPartial`. This keeps the door open for callers that still want to
|
|
781
|
+
* pass a fully-defaulted URI shape from `parseConnectionUri`.
|
|
782
|
+
*/
|
|
783
|
+
const resolveLayeredConnect = (argvLayer, resolution, legacyBase) => {
|
|
784
|
+
const env = resolution.env ?? {};
|
|
785
|
+
const uriPartial = resolution.uriPartial ??
|
|
786
|
+
(legacyBase !== undefined ? legacyBase : {});
|
|
787
|
+
// Pick the service entry: explicit `serviceName` argument first, else fall
|
|
788
|
+
// back to `$PGSERVICE`. The URI parser threads `?service=` through to its
|
|
789
|
+
// caller via this same field, so callers should populate `serviceName`
|
|
790
|
+
// from there before invoking us.
|
|
791
|
+
const serviceName = resolution.serviceName ?? env.PGSERVICE;
|
|
792
|
+
let serviceEntry;
|
|
793
|
+
if (serviceName !== undefined && serviceName !== '') {
|
|
794
|
+
serviceEntry = resolution.services?.get(serviceName);
|
|
795
|
+
if (serviceEntry === undefined) {
|
|
796
|
+
// Mirror libpq: if the user explicitly named a service (via
|
|
797
|
+
// `?service=`, conninfo `service=`, or `$PGSERVICE`) and it isn't
|
|
798
|
+
// found in any loaded service file, fail fast with the exact
|
|
799
|
+
// upstream wording. Without this the empty service layer would
|
|
800
|
+
// silently degrade to a different connection target — surprising
|
|
801
|
+
// and very hard to debug.
|
|
802
|
+
throw new Error(`definition of service "${serviceName}" not found`);
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
const serviceLayer = serviceEntry !== undefined
|
|
806
|
+
? serviceEntryToConnectOptions(serviceEntry)
|
|
807
|
+
: {};
|
|
808
|
+
// Build the layer stack (highest priority first).
|
|
809
|
+
const envLayer = envConnectionDefaults(env);
|
|
810
|
+
const defaults = libpqConnectionDefaults(env);
|
|
811
|
+
const layers = [
|
|
812
|
+
argvLayer,
|
|
813
|
+
uriPartial,
|
|
814
|
+
envLayer,
|
|
815
|
+
serviceLayer,
|
|
816
|
+
];
|
|
817
|
+
// First-pass merge (without pgpass) so we know what host/port/db/user
|
|
818
|
+
// ended up as. pgpass is a password-only layer that depends on the
|
|
819
|
+
// resolved target.
|
|
820
|
+
let merged = mergeConnectOptions(layers, defaults);
|
|
821
|
+
if (merged.password === undefined) {
|
|
822
|
+
const pgpassPwd = lookupPgPass(resolution.pgpassEntries ?? [], {
|
|
823
|
+
host: merged.host,
|
|
824
|
+
port: merged.port,
|
|
825
|
+
database: merged.database !== '' ? merged.database : merged.user,
|
|
826
|
+
user: merged.user,
|
|
827
|
+
});
|
|
828
|
+
if (pgpassPwd !== undefined) {
|
|
829
|
+
// Re-merge with pgpass slotted in just above libpq defaults so any
|
|
830
|
+
// explicit `password=` in env / service still wins.
|
|
831
|
+
const pgpassLayer = { password: pgpassPwd };
|
|
832
|
+
merged = mergeConnectOptions([...layers, pgpassLayer], defaults);
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
return merged;
|
|
836
|
+
};
|
|
837
|
+
// ---------------------------------------------------------------------------
|
|
838
|
+
// Error-formatting helper for the integration layer.
|
|
839
|
+
// ---------------------------------------------------------------------------
|
|
840
|
+
export const formatParseError = (err) => err.message;
|