neon 3.1.0 → 3.2.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 +30 -5
- package/dist/{_shared/auth_selection.js → _chunks/auth_selection-DGgq6ifc.js} +3 -3
- package/dist/_chunks/cmd_pipeline-CUbBO9U_.js +2818 -0
- package/dist/{_shared/credentials.js → _chunks/credentials-MYdHdKah.js} +3 -3
- package/dist/_chunks/env-NbA61JR3.js +585 -0
- package/dist/{_shared/env-core/env.js → _chunks/env_services-Tz9G4JeT.js} +179 -43
- package/dist/{_shared/paths.js → _chunks/paths-DMq0Lt7a.js} +2 -2
- package/dist/{_shared/profiles.js → _chunks/profiles-Ir29rqns.js} +4 -13
- package/dist/_chunks/psql-DWH-kc69.js +2169 -0
- package/dist/{_virtual/_rolldown/runtime.js → _chunks/rolldown-runtime-D7D4PA-g.js} +1 -1
- package/dist/{_shared/secure_file.js → _chunks/secure_file-BucZj4yQ.js} +2 -4
- package/dist/analytics.js +2 -2
- package/dist/auth_context.js +1 -1
- package/dist/commands/api.js +2 -2
- package/dist/commands/api_keys.js +2 -2
- package/dist/commands/auth.js +7 -6
- package/dist/commands/bootstrap.js +3 -3
- package/dist/commands/branches.js +2 -2
- package/dist/commands/bucket.js +2 -2
- package/dist/commands/checkout.js +2 -2
- package/dist/commands/config.js +2 -2
- package/dist/commands/connection_string.js +2 -2
- package/dist/commands/data_api.js +2 -2
- package/dist/commands/databases.js +2 -2
- package/dist/commands/deploy.js +2 -2
- package/dist/commands/dev.js +3 -3
- package/dist/commands/diff.js +2 -2
- package/dist/commands/env.js +42 -32
- package/dist/commands/functions.js +2 -2
- package/dist/commands/index.js +35 -33
- package/dist/commands/init.js +3 -3
- package/dist/commands/inspect.js +2 -2
- package/dist/commands/ip_allow.js +2 -2
- package/dist/commands/link.js +2 -2
- package/dist/commands/logs.js +2 -2
- package/dist/commands/neon_auth.js +2 -2
- package/dist/commands/open.js +33 -0
- package/dist/commands/operations.js +2 -2
- package/dist/commands/orgs.js +2 -2
- package/dist/commands/profile.js +7 -7
- package/dist/commands/projects.js +2 -2
- package/dist/commands/psql.js +2 -2
- package/dist/commands/roles.js +2 -2
- package/dist/commands/set_context.js +2 -2
- package/dist/commands/snapshots.js +2 -2
- package/dist/commands/status.js +2 -2
- package/dist/commands/user.js +2 -2
- package/dist/commands/vpc_endpoints.js +2 -2
- package/dist/config.js +1 -1
- package/dist/dev/env.js +1 -364
- package/dist/env_services.js +2 -49
- package/dist/index.js +2 -1
- package/dist/init/auth.js +4 -4
- package/dist/psql/cli.js +1 -1
- package/dist/psql/command/cmd_copy.js +1 -1
- package/dist/psql/command/cmd_io.js +1 -1403
- package/dist/psql/command/cmd_pipeline.js +1 -595
- package/dist/psql/command/dispatch.js +1 -2
- package/dist/psql/core/common.js +1 -834
- package/dist/psql/core/mainloop.js +1 -2
- package/dist/psql/core/startup.js +1 -656
- package/dist/psql/index.js +1 -1516
- package/dist/psql/io/psqlrc.js +1 -1
- package/dist/psql/types/index.js +6 -0
- package/dist/utils/inspect_db.js +1 -1
- package/dist/utils/middlewares.js +2 -1
- package/package.json +7 -4
- package/dist/_shared/env-core/reuse-secrets.js +0 -179
|
@@ -2,8 +2,7 @@ import { COND_COMMAND_NAMES, attachCondStack, cmdElif, cmdElse, cmdEndif, cmdIf
|
|
|
2
2
|
import { scanSlashArgs } from "../scanner/slash.js";
|
|
3
3
|
import { formatDurationMs } from "../print/units.js";
|
|
4
4
|
import { appendHistory, defaultHistoryPath, loadHistory, resolveHistSize, truncateHistory } from "../io/history.js";
|
|
5
|
-
import { captureLastError,
|
|
6
|
-
import { consumeBindState, getPipelineState } from "../command/cmd_pipeline.js";
|
|
5
|
+
import { G as writeQueryError, H as renderResultSet, L as captureLastError, U as sendQuery, V as refreshErrorVars, f as consumeBindState, m as getPipelineState, z as pickOut } from "../../_chunks/cmd_pipeline-CUbBO9U_.js";
|
|
7
6
|
import { consumeNext } from "../command/inputQueue.js";
|
|
8
7
|
import { psqlCompleter } from "../complete/index.js";
|
|
9
8
|
import { LineEditor } from "../io/lineEditor/index.js";
|
|
@@ -1,657 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { helpVariables, slashUsage, usage } from "./help.js";
|
|
3
|
-
import { lookupPgPass } from "../io/pgpass.js";
|
|
4
|
-
import { envConnectionDefaults, libpqConnectionDefaults, looksLikeConnectionString, mergeConnectOptions, parseConnectionUriPartial, parseConninfo, serviceEntryToConnectOptions } from "../index.js";
|
|
5
|
-
//#region src/psql/core/startup.ts
|
|
6
|
-
/**
|
|
7
|
-
* psql startup-args parser + applier.
|
|
8
|
-
*
|
|
9
|
-
* TypeScript port of `parse_psql_options()` / the top of `main()` in
|
|
10
|
-
* `src/bin/psql/startup.c`. Two responsibilities:
|
|
11
|
-
*
|
|
12
|
-
* 1. `parseStartupArgs(argv)` — hand-written getopt_long-equivalent that
|
|
13
|
-
* walks the argv array once, decoding short (`-c`) and long (`--command`)
|
|
14
|
-
* options, and accumulates an ordered list of `-c`/`-f` actions plus a
|
|
15
|
-
* bag of settings flags. Positional arguments follow the upstream
|
|
16
|
-
* `[DBNAME [USERNAME]]` rule.
|
|
17
|
-
*
|
|
18
|
-
* We hand-roll the parser instead of pulling in `yargs` (or similar)
|
|
19
|
-
* because upstream psql has subtle precedence rules — actions are
|
|
20
|
-
* ordered, `-v NAME` without `=` deletes the variable, `-X` interacts
|
|
21
|
-
* with `.psqlrc` discovery, etc. The parser stays under ~250 LOC and is
|
|
22
|
-
* fully covered by unit tests.
|
|
23
|
-
*
|
|
24
|
-
* 2. `applyStartupArgs(args, settings, baseConnect)` — mutates `settings`
|
|
25
|
-
* (and its var store) in-place to reflect parsed flags, then returns
|
|
26
|
-
* the connect options the caller should use plus the ordered list of
|
|
27
|
-
* pre-REPL actions to execute (currently just `-c` / `-f`).
|
|
28
|
-
*
|
|
29
|
-
* Out-of-scope for WP-26 but the table mentions them so they're listed below:
|
|
30
|
-
* - `-1` / `--single-transaction` — we accept and record on the args but
|
|
31
|
-
* do not wire its semantics in the caller. Tracked for a follow-up.
|
|
32
|
-
* - `-C` — accepted as a no-op (since-PG17 connection-check skip).
|
|
33
|
-
* - `-l` / `--list` — recorded; the caller may use it later to short-circuit
|
|
34
|
-
* the REPL with a `\l` and exit. Not wired here.
|
|
35
|
-
* - `-L logfile`, `-o output` — recorded on args. Routing into the printer
|
|
36
|
-
* is owned by other WPs (logfile streaming and output redirection).
|
|
37
|
-
* - `--help[=topic]` — returns a ParseError with `kind: 'help'` and the
|
|
38
|
-
* help text already rendered as `message`. Caller writes and exits 0.
|
|
39
|
-
* - `-V` / `--version` — returns `kind: 'version'` with the version string.
|
|
40
|
-
* Caller writes and exits 0.
|
|
41
|
-
*
|
|
42
|
-
* Help/version text is rendered through `./help.ts` so the formatting stays
|
|
43
|
-
* in lock-step with `\?` output (WP-18). The version string mirrors upstream
|
|
44
|
-
* `psql (PostgreSQL) PG_VERSION` and is currently hard-coded — the embedded
|
|
45
|
-
* psql doesn't have a build-system PG_VERSION constant. A follow-up could
|
|
46
|
-
* surface the real PG version from a const, but for now we expose the
|
|
47
|
-
* embedded build's version label.
|
|
48
|
-
*/
|
|
49
|
-
/** Short options that consume the next argv slot (or attached value). */
|
|
50
|
-
const SHORT_WITH_ARG = /* @__PURE__ */ new Set([
|
|
51
|
-
"c",
|
|
52
|
-
"d",
|
|
53
|
-
"f",
|
|
54
|
-
"F",
|
|
55
|
-
"h",
|
|
56
|
-
"L",
|
|
57
|
-
"o",
|
|
58
|
-
"p",
|
|
59
|
-
"P",
|
|
60
|
-
"R",
|
|
61
|
-
"T",
|
|
62
|
-
"U",
|
|
63
|
-
"v"
|
|
64
|
-
]);
|
|
65
|
-
/** Short flags (no argument). */
|
|
66
|
-
const SHORT_NO_ARG = /* @__PURE__ */ new Set([
|
|
67
|
-
"a",
|
|
68
|
-
"A",
|
|
69
|
-
"b",
|
|
70
|
-
"C",
|
|
71
|
-
"e",
|
|
72
|
-
"E",
|
|
73
|
-
"H",
|
|
74
|
-
"l",
|
|
75
|
-
"n",
|
|
76
|
-
"q",
|
|
77
|
-
"s",
|
|
78
|
-
"S",
|
|
79
|
-
"t",
|
|
80
|
-
"V",
|
|
81
|
-
"w",
|
|
82
|
-
"W",
|
|
83
|
-
"x",
|
|
84
|
-
"X",
|
|
85
|
-
"z",
|
|
86
|
-
"0",
|
|
87
|
-
"1",
|
|
88
|
-
"?"
|
|
89
|
-
]);
|
|
90
|
-
/** Long option → canonical short equivalent (or sentinel string). */
|
|
91
|
-
const LONG_MAP = {
|
|
92
|
-
"echo-all": "a",
|
|
93
|
-
"no-align": "A",
|
|
94
|
-
command: "c",
|
|
95
|
-
dbname: "d",
|
|
96
|
-
"echo-queries": "e",
|
|
97
|
-
"echo-errors": "b",
|
|
98
|
-
"echo-hidden": "E",
|
|
99
|
-
file: "f",
|
|
100
|
-
"field-separator": "F",
|
|
101
|
-
"field-separator-zero": "z",
|
|
102
|
-
host: "h",
|
|
103
|
-
html: "H",
|
|
104
|
-
list: "l",
|
|
105
|
-
"log-file": "L",
|
|
106
|
-
"no-readline": "n",
|
|
107
|
-
"single-transaction": "1",
|
|
108
|
-
output: "o",
|
|
109
|
-
port: "p",
|
|
110
|
-
pset: "P",
|
|
111
|
-
quiet: "q",
|
|
112
|
-
"record-separator": "R",
|
|
113
|
-
"record-separator-zero": "0",
|
|
114
|
-
"single-step": "s",
|
|
115
|
-
"single-line": "S",
|
|
116
|
-
"tuples-only": "t",
|
|
117
|
-
"table-attr": "T",
|
|
118
|
-
username: "U",
|
|
119
|
-
set: "v",
|
|
120
|
-
variable: "v",
|
|
121
|
-
version: "V",
|
|
122
|
-
"no-password": "w",
|
|
123
|
-
password: "W",
|
|
124
|
-
expanded: "x",
|
|
125
|
-
"no-psqlrc": "X",
|
|
126
|
-
"no-pager": "__no_pager__",
|
|
127
|
-
"on-error-stop": "__on_error_stop__",
|
|
128
|
-
help: "__help__",
|
|
129
|
-
csv: "__csv__"
|
|
130
|
-
};
|
|
131
|
-
/** Long options that REQUIRE an attached value (or one in the next argv). */
|
|
132
|
-
const LONG_WITH_ARG = /* @__PURE__ */ new Set([
|
|
133
|
-
"command",
|
|
134
|
-
"dbname",
|
|
135
|
-
"file",
|
|
136
|
-
"field-separator",
|
|
137
|
-
"host",
|
|
138
|
-
"log-file",
|
|
139
|
-
"output",
|
|
140
|
-
"port",
|
|
141
|
-
"pset",
|
|
142
|
-
"record-separator",
|
|
143
|
-
"table-attr",
|
|
144
|
-
"username",
|
|
145
|
-
"set",
|
|
146
|
-
"variable"
|
|
147
|
-
]);
|
|
148
|
-
/** Long options whose value is optional (only attached with `=`). */
|
|
149
|
-
const LONG_OPTIONAL_ARG = /* @__PURE__ */ new Set(["help", "echo-hidden"]);
|
|
150
|
-
const blankArgs = () => ({
|
|
151
|
-
actions: [],
|
|
152
|
-
variables: [],
|
|
153
|
-
noPsqlrc: false,
|
|
154
|
-
noReadline: false,
|
|
155
|
-
echoAll: false,
|
|
156
|
-
echoHidden: "off",
|
|
157
|
-
echoErrors: false,
|
|
158
|
-
echoQueries: false,
|
|
159
|
-
quiet: false,
|
|
160
|
-
singleline: false,
|
|
161
|
-
singlestep: false,
|
|
162
|
-
noAlign: false,
|
|
163
|
-
noPager: false,
|
|
164
|
-
htmlMode: false,
|
|
165
|
-
tuplesOnly: false,
|
|
166
|
-
expanded: false,
|
|
167
|
-
csvOutput: false,
|
|
168
|
-
onErrorStop: false,
|
|
169
|
-
fieldSepZero: false,
|
|
170
|
-
recordSepZero: false,
|
|
171
|
-
pset: [],
|
|
172
|
-
list: false,
|
|
173
|
-
singleTransaction: false,
|
|
174
|
-
help: false,
|
|
175
|
-
version: false,
|
|
176
|
-
positional: []
|
|
177
|
-
});
|
|
178
|
-
const renderToString = (fn) => {
|
|
179
|
-
const chunks = [];
|
|
180
|
-
fn({ write(chunk) {
|
|
181
|
-
chunks.push(typeof chunk === "string" ? chunk : Buffer.from(chunk).toString("utf8"));
|
|
182
|
-
return true;
|
|
183
|
-
} });
|
|
184
|
-
return chunks.join("");
|
|
185
|
-
};
|
|
186
|
-
const renderHelp = (topic) => {
|
|
187
|
-
if (topic === void 0 || topic === "options") return renderToString((out) => {
|
|
188
|
-
usage(out);
|
|
189
|
-
});
|
|
190
|
-
if (topic === "commands") return renderToString((out) => {
|
|
191
|
-
slashUsage(out, false);
|
|
192
|
-
});
|
|
193
|
-
if (topic === "variables") return renderToString((out) => {
|
|
194
|
-
helpVariables(out);
|
|
195
|
-
});
|
|
196
|
-
return "";
|
|
197
|
-
};
|
|
198
|
-
/**
|
|
199
|
-
* Version label for the embedded TypeScript psql. This is the "client"
|
|
200
|
-
* identifier — the analogue of upstream psql's compiled-in `PG_VERSION`.
|
|
201
|
-
* The embedded psql is not a real PostgreSQL build, so we track our own
|
|
202
|
-
* implementation version here. It seeds the `VERSION_NAME` psql var (and,
|
|
203
|
-
* via {@link setStartupVars}, the numeric `VERSION_NUM`); keep it as a
|
|
204
|
-
* `MAJOR.MINOR.PATCH` string so the numeric mapping stays meaningful. Bump
|
|
205
|
-
* alongside meaningful behaviour changes to the embedded psql.
|
|
206
|
-
*/
|
|
207
|
-
const CLIENT_VERSION = "1.0.0";
|
|
208
|
-
const VERSION_STRING = `psql (PostgreSQL) embedded-ts (neon ${CLIENT_VERSION})`;
|
|
209
|
-
const pushAction = (acts, a) => {
|
|
210
|
-
acts.push(a);
|
|
211
|
-
};
|
|
212
|
-
const pushVariable = (vars, raw) => {
|
|
213
|
-
const eq = raw.indexOf("=");
|
|
214
|
-
if (eq < 0) {
|
|
215
|
-
vars.push({
|
|
216
|
-
name: raw,
|
|
217
|
-
value: ""
|
|
218
|
-
});
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
vars.push({
|
|
222
|
-
name: raw.slice(0, eq),
|
|
223
|
-
value: raw.slice(eq + 1)
|
|
224
|
-
});
|
|
225
|
-
};
|
|
226
|
-
/**
|
|
227
|
-
* `-d VALUE` resolution. libpq accepts three shapes for the value:
|
|
228
|
-
*
|
|
229
|
-
* 1. Bare database name (no `=`, no `postgres[ql]://` prefix) — set
|
|
230
|
-
* `args.database` directly. This is by far the common case.
|
|
231
|
-
* 2. Connection URI (`postgresql://…` / `postgres://…`) — parse it and
|
|
232
|
-
* lift the fields it specifies onto `args` (host, port, user, etc.).
|
|
233
|
-
* 3. Conninfo key=value pairs separated by whitespace — same, but parsed
|
|
234
|
-
* via `parseConninfo`.
|
|
235
|
-
*
|
|
236
|
-
* The test corpus for upstream `001_basic.pl` uses shape (3) to open a
|
|
237
|
-
* walsender connection: `-d "dbname=postgres replication=database"`. We
|
|
238
|
-
* fold any conninfo-only fields (currently only `replication`) onto a
|
|
239
|
-
* dedicated `args.replication` slot that `applyStartupArgs` threads into
|
|
240
|
-
* `ConnectOptions.replication`.
|
|
241
|
-
*/
|
|
242
|
-
const applyDashD = (args, value) => {
|
|
243
|
-
if (!looksLikeConnectionString(value)) {
|
|
244
|
-
args.database = value;
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
const parsed = value.startsWith("postgresql://") || value.startsWith("postgres://") ? parseConnectionUriPartial(value) : parseConninfo(value);
|
|
248
|
-
args.dashD = {
|
|
249
|
-
...args.dashD ?? {},
|
|
250
|
-
...parsed
|
|
251
|
-
};
|
|
252
|
-
if (parsed.host !== void 0 && args.host === void 0) args.host = parsed.host;
|
|
253
|
-
if (parsed.port !== void 0 && args.port === void 0) args.port = parsed.port;
|
|
254
|
-
if (parsed.user !== void 0 && args.user === void 0) args.user = parsed.user;
|
|
255
|
-
if (parsed.password !== void 0 && args.password === void 0) args.password = parsed.password;
|
|
256
|
-
if (parsed.database !== void 0 && args.database === void 0) args.database = parsed.database;
|
|
257
|
-
if (parsed.replication !== void 0) args.replication = parsed.replication;
|
|
258
|
-
};
|
|
259
|
-
const parseStartupArgs = (argv) => {
|
|
260
|
-
const args = blankArgs();
|
|
261
|
-
const actions = [];
|
|
262
|
-
const variables = [];
|
|
263
|
-
const pset = [];
|
|
264
|
-
let i = 0;
|
|
265
|
-
const n = argv.length;
|
|
266
|
-
const needValue = (flagDisplay) => {
|
|
267
|
-
if (i + 1 >= n) return {
|
|
268
|
-
kind: "missing-arg",
|
|
269
|
-
message: `option requires an argument -- ${flagDisplay}`
|
|
270
|
-
};
|
|
271
|
-
i += 1;
|
|
272
|
-
return argv[i];
|
|
273
|
-
};
|
|
274
|
-
const applyShort = (letter, attachedValue, flagDisplay) => {
|
|
275
|
-
const takesArg = SHORT_WITH_ARG.has(letter);
|
|
276
|
-
let value;
|
|
277
|
-
if (takesArg) if (attachedValue !== void 0) value = attachedValue;
|
|
278
|
-
else {
|
|
279
|
-
const v = needValue(flagDisplay);
|
|
280
|
-
if (typeof v !== "string") return v;
|
|
281
|
-
value = v;
|
|
282
|
-
}
|
|
283
|
-
else if (attachedValue !== void 0) return {
|
|
284
|
-
kind: "invalid-option",
|
|
285
|
-
message: `option does not take an argument -- ${letter}`
|
|
286
|
-
};
|
|
287
|
-
switch (letter) {
|
|
288
|
-
case "a":
|
|
289
|
-
args.echoAll = true;
|
|
290
|
-
return null;
|
|
291
|
-
case "A":
|
|
292
|
-
args.noAlign = true;
|
|
293
|
-
return null;
|
|
294
|
-
case "b":
|
|
295
|
-
args.echoErrors = true;
|
|
296
|
-
return null;
|
|
297
|
-
case "C": return null;
|
|
298
|
-
case "c":
|
|
299
|
-
pushAction(actions, {
|
|
300
|
-
kind: "command",
|
|
301
|
-
sql: value
|
|
302
|
-
});
|
|
303
|
-
return null;
|
|
304
|
-
case "d":
|
|
305
|
-
applyDashD(args, value);
|
|
306
|
-
return null;
|
|
307
|
-
case "e":
|
|
308
|
-
args.echoQueries = true;
|
|
309
|
-
return null;
|
|
310
|
-
case "E":
|
|
311
|
-
args.echoHidden = "on";
|
|
312
|
-
return null;
|
|
313
|
-
case "f":
|
|
314
|
-
pushAction(actions, {
|
|
315
|
-
kind: "file",
|
|
316
|
-
path: value
|
|
317
|
-
});
|
|
318
|
-
return null;
|
|
319
|
-
case "F":
|
|
320
|
-
args.fieldSep = value;
|
|
321
|
-
args.fieldSepZero = false;
|
|
322
|
-
return null;
|
|
323
|
-
case "h":
|
|
324
|
-
args.host = value;
|
|
325
|
-
return null;
|
|
326
|
-
case "H":
|
|
327
|
-
args.htmlMode = true;
|
|
328
|
-
return null;
|
|
329
|
-
case "l":
|
|
330
|
-
args.list = true;
|
|
331
|
-
return null;
|
|
332
|
-
case "L":
|
|
333
|
-
args.log = value;
|
|
334
|
-
return null;
|
|
335
|
-
case "n":
|
|
336
|
-
args.noReadline = true;
|
|
337
|
-
return null;
|
|
338
|
-
case "o":
|
|
339
|
-
args.output = value;
|
|
340
|
-
return null;
|
|
341
|
-
case "p": {
|
|
342
|
-
const p = Number.parseInt(value, 10);
|
|
343
|
-
if (!Number.isFinite(p) || p <= 0 || p > 65535) return {
|
|
344
|
-
kind: "invalid-value",
|
|
345
|
-
message: `invalid port number: "${value}"`
|
|
346
|
-
};
|
|
347
|
-
args.port = p;
|
|
348
|
-
return null;
|
|
349
|
-
}
|
|
350
|
-
case "P":
|
|
351
|
-
pset.push(value);
|
|
352
|
-
return null;
|
|
353
|
-
case "q":
|
|
354
|
-
args.quiet = true;
|
|
355
|
-
return null;
|
|
356
|
-
case "R":
|
|
357
|
-
args.recordSep = value;
|
|
358
|
-
args.recordSepZero = false;
|
|
359
|
-
return null;
|
|
360
|
-
case "s":
|
|
361
|
-
args.singlestep = true;
|
|
362
|
-
return null;
|
|
363
|
-
case "S":
|
|
364
|
-
args.singleline = true;
|
|
365
|
-
return null;
|
|
366
|
-
case "t":
|
|
367
|
-
args.tuplesOnly = true;
|
|
368
|
-
return null;
|
|
369
|
-
case "T":
|
|
370
|
-
pset.push(`tableattr=${value}`);
|
|
371
|
-
return null;
|
|
372
|
-
case "U":
|
|
373
|
-
args.user = value;
|
|
374
|
-
return null;
|
|
375
|
-
case "v":
|
|
376
|
-
pushVariable(variables, value);
|
|
377
|
-
return null;
|
|
378
|
-
case "V": return {
|
|
379
|
-
kind: "version",
|
|
380
|
-
message: VERSION_STRING
|
|
381
|
-
};
|
|
382
|
-
case "w":
|
|
383
|
-
args.promptPassword = false;
|
|
384
|
-
return null;
|
|
385
|
-
case "W":
|
|
386
|
-
args.promptPassword = true;
|
|
387
|
-
return null;
|
|
388
|
-
case "x":
|
|
389
|
-
args.expanded = true;
|
|
390
|
-
return null;
|
|
391
|
-
case "X":
|
|
392
|
-
args.noPsqlrc = true;
|
|
393
|
-
return null;
|
|
394
|
-
case "z":
|
|
395
|
-
args.fieldSepZero = true;
|
|
396
|
-
return null;
|
|
397
|
-
case "0":
|
|
398
|
-
args.recordSepZero = true;
|
|
399
|
-
return null;
|
|
400
|
-
case "1":
|
|
401
|
-
args.singleTransaction = true;
|
|
402
|
-
return null;
|
|
403
|
-
case "?": return {
|
|
404
|
-
kind: "help",
|
|
405
|
-
message: renderHelp(void 0)
|
|
406
|
-
};
|
|
407
|
-
default: return {
|
|
408
|
-
kind: "invalid-option",
|
|
409
|
-
message: `invalid option -- ${letter}`
|
|
410
|
-
};
|
|
411
|
-
}
|
|
412
|
-
};
|
|
413
|
-
while (i < n) {
|
|
414
|
-
const tok = argv[i];
|
|
415
|
-
if (tok === "--") {
|
|
416
|
-
i += 1;
|
|
417
|
-
while (i < n) {
|
|
418
|
-
args.positional.push(argv[i]);
|
|
419
|
-
i += 1;
|
|
420
|
-
}
|
|
421
|
-
break;
|
|
422
|
-
}
|
|
423
|
-
if (tok.startsWith("--")) {
|
|
424
|
-
const eq = tok.indexOf("=");
|
|
425
|
-
const name = eq < 0 ? tok.slice(2) : tok.slice(2, eq);
|
|
426
|
-
const attached = eq < 0 ? void 0 : tok.slice(eq + 1);
|
|
427
|
-
if (name === "csv") {
|
|
428
|
-
if (attached !== void 0) return {
|
|
429
|
-
kind: "invalid-option",
|
|
430
|
-
message: `option does not take an argument: --${name}`
|
|
431
|
-
};
|
|
432
|
-
args.csvOutput = true;
|
|
433
|
-
i += 1;
|
|
434
|
-
continue;
|
|
435
|
-
}
|
|
436
|
-
if (name === "no-pager") {
|
|
437
|
-
if (attached !== void 0) return {
|
|
438
|
-
kind: "invalid-option",
|
|
439
|
-
message: `option does not take an argument: --${name}`
|
|
440
|
-
};
|
|
441
|
-
args.noPager = true;
|
|
442
|
-
i += 1;
|
|
443
|
-
continue;
|
|
444
|
-
}
|
|
445
|
-
if (name === "on-error-stop") {
|
|
446
|
-
if (attached !== void 0) return {
|
|
447
|
-
kind: "invalid-option",
|
|
448
|
-
message: `option does not take an argument: --${name}`
|
|
449
|
-
};
|
|
450
|
-
args.onErrorStop = true;
|
|
451
|
-
variables.push({
|
|
452
|
-
name: "ON_ERROR_STOP",
|
|
453
|
-
value: "on"
|
|
454
|
-
});
|
|
455
|
-
i += 1;
|
|
456
|
-
continue;
|
|
457
|
-
}
|
|
458
|
-
if (name === "help") {
|
|
459
|
-
const topic = attached;
|
|
460
|
-
if (topic !== void 0 && topic !== "options" && topic !== "commands" && topic !== "variables") return {
|
|
461
|
-
kind: "invalid-option",
|
|
462
|
-
message: `unrecognized help topic: ${topic}`
|
|
463
|
-
};
|
|
464
|
-
return {
|
|
465
|
-
kind: "help",
|
|
466
|
-
message: renderHelp(topic)
|
|
467
|
-
};
|
|
468
|
-
}
|
|
469
|
-
if (name === "echo-hidden") {
|
|
470
|
-
if (attached === void 0) args.echoHidden = "on";
|
|
471
|
-
else if (attached === "noexec") args.echoHidden = "noexec";
|
|
472
|
-
else if (attached === "" || attached === "on") args.echoHidden = "on";
|
|
473
|
-
else return {
|
|
474
|
-
kind: "invalid-value",
|
|
475
|
-
message: `invalid value for --echo-hidden: "${attached}"`
|
|
476
|
-
};
|
|
477
|
-
i += 1;
|
|
478
|
-
continue;
|
|
479
|
-
}
|
|
480
|
-
const short = LONG_MAP[name];
|
|
481
|
-
if (short === void 0) return {
|
|
482
|
-
kind: "invalid-option",
|
|
483
|
-
message: `unrecognized option: --${name}`
|
|
484
|
-
};
|
|
485
|
-
const requiresArg = LONG_WITH_ARG.has(name);
|
|
486
|
-
const optionalArg = LONG_OPTIONAL_ARG.has(name);
|
|
487
|
-
let value = attached;
|
|
488
|
-
if (requiresArg && value === void 0) {
|
|
489
|
-
if (i + 1 >= n) return {
|
|
490
|
-
kind: "missing-arg",
|
|
491
|
-
message: `option requires an argument: --${name}`
|
|
492
|
-
};
|
|
493
|
-
i += 1;
|
|
494
|
-
value = argv[i];
|
|
495
|
-
} else if (!requiresArg && !optionalArg && value !== void 0) return {
|
|
496
|
-
kind: "invalid-option",
|
|
497
|
-
message: `option does not take an argument: --${name}`
|
|
498
|
-
};
|
|
499
|
-
const err = applyShort(short, value, `--${name}`);
|
|
500
|
-
if (err) return err;
|
|
501
|
-
i += 1;
|
|
502
|
-
continue;
|
|
503
|
-
}
|
|
504
|
-
if (tok.startsWith("-") && tok.length > 1) {
|
|
505
|
-
let k = 1;
|
|
506
|
-
while (k < tok.length) {
|
|
507
|
-
const letter = tok[k];
|
|
508
|
-
if (!SHORT_WITH_ARG.has(letter) && !SHORT_NO_ARG.has(letter)) return {
|
|
509
|
-
kind: "invalid-option",
|
|
510
|
-
message: `invalid option -- ${letter}`
|
|
511
|
-
};
|
|
512
|
-
if (SHORT_WITH_ARG.has(letter)) {
|
|
513
|
-
const remainder = tok.slice(k + 1);
|
|
514
|
-
const err = applyShort(letter, remainder.length > 0 ? remainder : void 0, letter);
|
|
515
|
-
if (err) return err;
|
|
516
|
-
k = tok.length;
|
|
517
|
-
break;
|
|
518
|
-
}
|
|
519
|
-
const err = applyShort(letter, void 0, letter);
|
|
520
|
-
if (err) return err;
|
|
521
|
-
k += 1;
|
|
522
|
-
}
|
|
523
|
-
i += 1;
|
|
524
|
-
continue;
|
|
525
|
-
}
|
|
526
|
-
args.positional.push(tok);
|
|
527
|
-
i += 1;
|
|
528
|
-
}
|
|
529
|
-
return {
|
|
530
|
-
...args,
|
|
531
|
-
actions,
|
|
532
|
-
variables,
|
|
533
|
-
pset
|
|
534
|
-
};
|
|
535
|
-
};
|
|
536
|
-
const applyStartupArgs = (args, settings, baseConnectOpts, resolution) => {
|
|
537
|
-
setStartupVars(settings.vars, CLIENT_VERSION);
|
|
538
|
-
for (const v of args.variables) if (v.value === "") settings.vars.unset(v.name);
|
|
539
|
-
else settings.vars.set(v.name, v.value);
|
|
540
|
-
if (args.echoAll) settings.vars.set("ECHO", "all");
|
|
541
|
-
if (args.echoErrors) settings.vars.set("ECHO", "errors");
|
|
542
|
-
if (args.echoQueries) settings.vars.set("ECHO", "queries");
|
|
543
|
-
if (args.echoHidden !== "off") {
|
|
544
|
-
settings.echoHidden = args.echoHidden;
|
|
545
|
-
settings.vars.set("ECHO_HIDDEN", args.echoHidden === "noexec" ? "noexec" : "on");
|
|
546
|
-
}
|
|
547
|
-
if (args.quiet) {
|
|
548
|
-
settings.quiet = true;
|
|
549
|
-
settings.vars.set("QUIET", "on");
|
|
550
|
-
}
|
|
551
|
-
if (args.singleline) {
|
|
552
|
-
settings.singleline = true;
|
|
553
|
-
settings.vars.set("SINGLELINE", "on");
|
|
554
|
-
}
|
|
555
|
-
if (args.singlestep) {
|
|
556
|
-
settings.singlestep = true;
|
|
557
|
-
settings.vars.set("SINGLESTEP", "on");
|
|
558
|
-
}
|
|
559
|
-
if (args.onErrorStop) {
|
|
560
|
-
settings.onErrorStop = true;
|
|
561
|
-
settings.vars.set("ON_ERROR_STOP", "on");
|
|
562
|
-
}
|
|
563
|
-
if (args.noAlign) settings.popt.topt.format = "unaligned";
|
|
564
|
-
if (args.htmlMode) settings.popt.topt.format = "html";
|
|
565
|
-
if (args.csvOutput) settings.popt.topt.format = "csv";
|
|
566
|
-
if (args.tuplesOnly) settings.popt.topt.tuplesOnly = true;
|
|
567
|
-
if (args.expanded) settings.popt.topt.expanded = "on";
|
|
568
|
-
if (args.fieldSepZero) settings.popt.topt.fieldSep = "\0";
|
|
569
|
-
else if (args.fieldSep !== void 0) settings.popt.topt.fieldSep = args.fieldSep;
|
|
570
|
-
if (args.recordSepZero) settings.popt.topt.recordSep = "\0";
|
|
571
|
-
else if (args.recordSep !== void 0) settings.popt.topt.recordSep = args.recordSep;
|
|
572
|
-
if (args.noPager) settings.popt.topt.pager = "off";
|
|
573
|
-
for (const directive of args.pset) {
|
|
574
|
-
const eq = directive.indexOf("=");
|
|
575
|
-
if (eq >= 0) {
|
|
576
|
-
const key = directive.slice(0, eq);
|
|
577
|
-
const val = directive.slice(eq + 1);
|
|
578
|
-
if (key === "tableattr" || key === "T") settings.popt.topt.tableAttr = val.length > 0 ? val : null;
|
|
579
|
-
else if (key === "pager") {
|
|
580
|
-
if (val === "on" || val === "off" || val === "always") settings.popt.topt.pager = val;
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
let dbname = args.database;
|
|
585
|
-
let username = args.user;
|
|
586
|
-
if (args.positional[0] && !dbname) dbname = args.positional[0];
|
|
587
|
-
if (args.positional[1] && !username) username = args.positional[1];
|
|
588
|
-
const argvLayer = { ...args.dashD ?? {} };
|
|
589
|
-
if (args.host !== void 0) argvLayer.host = args.host;
|
|
590
|
-
if (args.port !== void 0) argvLayer.port = args.port;
|
|
591
|
-
if (username !== void 0) argvLayer.user = username;
|
|
592
|
-
if (dbname !== void 0) argvLayer.database = dbname;
|
|
593
|
-
if (args.password !== void 0) argvLayer.password = args.password;
|
|
594
|
-
if (args.replication !== void 0) argvLayer.replication = args.replication;
|
|
595
|
-
let connect;
|
|
596
|
-
if (resolution === void 0) connect = {
|
|
597
|
-
...baseConnectOpts ?? {
|
|
598
|
-
host: "localhost",
|
|
599
|
-
port: 5432,
|
|
600
|
-
user: "",
|
|
601
|
-
database: "",
|
|
602
|
-
ssl: "prefer"
|
|
603
|
-
},
|
|
604
|
-
...argvLayer
|
|
605
|
-
};
|
|
606
|
-
else connect = resolveLayeredConnect(argvLayer, resolution, baseConnectOpts);
|
|
607
|
-
return {
|
|
608
|
-
connect,
|
|
609
|
-
preActions: args.actions
|
|
610
|
-
};
|
|
611
|
-
};
|
|
612
|
-
/**
|
|
613
|
-
* Run the layered connection-parameter merge.
|
|
614
|
-
*
|
|
615
|
-
* argv > URI partial > PG* env > .pgpass (password only) > service > libpq defaults
|
|
616
|
-
*
|
|
617
|
-
* `baseConnectOpts` (the legacy `ConnectOptions` argument) is treated as a
|
|
618
|
-
* pre-baked URI partial when the resolution path is used WITHOUT an explicit
|
|
619
|
-
* `uriPartial`. This keeps the door open for callers that still want to
|
|
620
|
-
* pass a fully-defaulted URI shape from `parseConnectionUri`.
|
|
621
|
-
*/
|
|
622
|
-
const resolveLayeredConnect = (argvLayer, resolution, legacyBase) => {
|
|
623
|
-
const env = resolution.env ?? {};
|
|
624
|
-
const uriPartial = resolution.uriPartial ?? (legacyBase !== void 0 ? legacyBase : {});
|
|
625
|
-
const serviceName = resolution.serviceName ?? env.PGSERVICE;
|
|
626
|
-
let serviceEntry;
|
|
627
|
-
if (serviceName !== void 0 && serviceName !== "") {
|
|
628
|
-
serviceEntry = resolution.services?.get(serviceName);
|
|
629
|
-
if (serviceEntry === void 0) throw new Error(`definition of service "${serviceName}" not found`);
|
|
630
|
-
}
|
|
631
|
-
const serviceLayer = serviceEntry !== void 0 ? serviceEntryToConnectOptions(serviceEntry) : {};
|
|
632
|
-
const envLayer = envConnectionDefaults(env);
|
|
633
|
-
const defaults = libpqConnectionDefaults(env);
|
|
634
|
-
const layers = [
|
|
635
|
-
argvLayer,
|
|
636
|
-
uriPartial,
|
|
637
|
-
envLayer,
|
|
638
|
-
serviceLayer
|
|
639
|
-
];
|
|
640
|
-
let merged = mergeConnectOptions(layers, defaults);
|
|
641
|
-
if (merged.password === void 0) {
|
|
642
|
-
const pgpassPwd = lookupPgPass(resolution.pgpassEntries ?? [], {
|
|
643
|
-
host: merged.host,
|
|
644
|
-
port: merged.port,
|
|
645
|
-
database: merged.database !== "" ? merged.database : merged.user,
|
|
646
|
-
user: merged.user
|
|
647
|
-
});
|
|
648
|
-
if (pgpassPwd !== void 0) {
|
|
649
|
-
const pgpassLayer = { password: pgpassPwd };
|
|
650
|
-
merged = mergeConnectOptions([...layers, pgpassLayer], defaults);
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
return merged;
|
|
654
|
-
};
|
|
655
|
-
const formatParseError = (err) => err.message;
|
|
656
|
-
//#endregion
|
|
1
|
+
import { f as CLIENT_VERSION, h as parseStartupArgs, m as formatParseError, p as applyStartupArgs } from "../../_chunks/psql-DWH-kc69.js";
|
|
657
2
|
export { CLIENT_VERSION, applyStartupArgs, formatParseError, parseStartupArgs };
|