neonctl 2.27.1 → 2.29.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 +35 -3
- package/dist/analytics.js +52 -34
- package/dist/api.js +643 -13
- package/dist/auth.js +50 -44
- package/dist/cli.js +8 -1
- package/dist/commands/auth.js +64 -51
- package/dist/commands/bootstrap.js +115 -157
- package/dist/commands/branches.js +160 -150
- package/dist/commands/bucket.js +183 -146
- package/dist/commands/checkout.js +51 -51
- package/dist/commands/config.js +228 -82
- package/dist/commands/connection_string.js +62 -62
- package/dist/commands/data_api.js +100 -101
- package/dist/commands/databases.js +29 -26
- package/dist/commands/deploy.js +12 -12
- package/dist/commands/dev.js +114 -114
- package/dist/commands/env.js +43 -43
- package/dist/commands/functions.js +101 -104
- package/dist/commands/index.js +27 -25
- package/dist/commands/init.js +23 -22
- package/dist/commands/ip_allow.js +29 -29
- package/dist/commands/link.js +232 -182
- package/dist/commands/neon_auth.js +385 -370
- package/dist/commands/operations.js +11 -11
- package/dist/commands/orgs.js +8 -8
- package/dist/commands/projects.js +103 -101
- package/dist/commands/psql.js +31 -31
- package/dist/commands/roles.js +27 -24
- package/dist/commands/schema_diff.js +25 -26
- package/dist/commands/set_context.js +17 -17
- package/dist/commands/status.js +40 -0
- package/dist/commands/user.js +5 -5
- package/dist/commands/vpc_endpoints.js +50 -50
- package/dist/config.js +7 -7
- package/dist/config_format.js +5 -5
- package/dist/context.js +37 -14
- package/dist/current_branch_fast_path.js +55 -0
- package/dist/dev/env.js +33 -33
- package/dist/dev/functions.js +4 -4
- package/dist/dev/inputs.js +6 -6
- package/dist/dev/runtime.js +25 -25
- package/dist/env.js +14 -14
- package/dist/env_file.js +13 -13
- package/dist/errors.js +68 -5
- package/dist/functions_api.js +10 -10
- package/dist/help.js +15 -15
- package/dist/index.js +110 -107
- package/dist/log.js +2 -2
- package/dist/parameters.gen.js +14 -14
- package/dist/pkg.js +5 -5
- package/dist/psql/cli.js +4 -2
- package/dist/psql/command/cmd_cond.js +61 -61
- package/dist/psql/command/cmd_connect.js +159 -154
- package/dist/psql/command/cmd_copy.js +107 -97
- package/dist/psql/command/cmd_describe.js +368 -363
- package/dist/psql/command/cmd_format.js +276 -263
- package/dist/psql/command/cmd_io.js +269 -263
- package/dist/psql/command/cmd_lo.js +74 -66
- package/dist/psql/command/cmd_meta.js +148 -148
- package/dist/psql/command/cmd_misc.js +17 -17
- package/dist/psql/command/cmd_pipeline.js +142 -135
- package/dist/psql/command/cmd_restrict.js +25 -25
- package/dist/psql/command/cmd_show.js +183 -168
- package/dist/psql/command/dispatch.js +26 -26
- package/dist/psql/command/shared.js +14 -14
- package/dist/psql/complete/filenames.js +16 -16
- package/dist/psql/complete/index.js +4 -4
- package/dist/psql/complete/matcher.js +33 -32
- package/dist/psql/complete/psqlVars.js +173 -173
- package/dist/psql/complete/queries.js +5 -3
- package/dist/psql/complete/rules.js +900 -863
- package/dist/psql/core/common.js +136 -133
- package/dist/psql/core/help.js +343 -343
- package/dist/psql/core/mainloop.js +160 -153
- package/dist/psql/core/prompt.js +126 -123
- package/dist/psql/core/settings.js +111 -111
- package/dist/psql/core/sqlHelp.js +150 -150
- package/dist/psql/core/startup.js +211 -205
- package/dist/psql/core/syncVars.js +14 -14
- package/dist/psql/core/variables.js +24 -24
- package/dist/psql/describe/formatters.js +302 -289
- package/dist/psql/describe/processNamePattern.js +28 -28
- package/dist/psql/describe/queries.js +656 -651
- package/dist/psql/index.js +436 -411
- package/dist/psql/io/history.js +36 -36
- package/dist/psql/io/input.js +15 -15
- package/dist/psql/io/lineEditor/buffer.js +27 -25
- package/dist/psql/io/lineEditor/complete.js +15 -15
- package/dist/psql/io/lineEditor/filename.js +22 -22
- package/dist/psql/io/lineEditor/index.js +65 -62
- package/dist/psql/io/lineEditor/keymap.js +325 -318
- package/dist/psql/io/lineEditor/vt100.js +60 -60
- package/dist/psql/io/pgpass.js +18 -18
- package/dist/psql/io/pgservice.js +14 -14
- package/dist/psql/io/psqlrc.js +46 -46
- package/dist/psql/print/aligned.js +175 -166
- package/dist/psql/print/asciidoc.js +51 -51
- package/dist/psql/print/crosstab.js +34 -31
- package/dist/psql/print/csv.js +25 -22
- package/dist/psql/print/html.js +54 -54
- package/dist/psql/print/json.js +12 -12
- package/dist/psql/print/latex.js +118 -118
- package/dist/psql/print/pager.js +28 -26
- package/dist/psql/print/troff.js +48 -48
- package/dist/psql/print/unaligned.js +15 -14
- package/dist/psql/print/units.js +17 -17
- package/dist/psql/scanner/slash.js +48 -46
- package/dist/psql/scanner/sql.js +88 -84
- package/dist/psql/scanner/stringutils.js +21 -17
- package/dist/psql/types/index.js +7 -7
- package/dist/psql/types/scanner.js +8 -8
- package/dist/psql/wire/connection.js +341 -327
- package/dist/psql/wire/copy.js +7 -7
- package/dist/psql/wire/pipeline.js +26 -24
- package/dist/psql/wire/protocol.js +102 -102
- package/dist/psql/wire/sasl.js +62 -62
- package/dist/psql/wire/tls.js +79 -73
- package/dist/storage_api.js +22 -23
- package/dist/test_utils/fixtures.js +74 -41
- package/dist/test_utils/oauth_server.js +5 -5
- package/dist/utils/api_enums.js +33 -0
- package/dist/utils/branch_notice.js +5 -5
- package/dist/utils/branch_picker.js +26 -26
- package/dist/utils/compute_units.js +4 -4
- package/dist/utils/enrichers.js +28 -16
- package/dist/utils/esbuild.js +28 -28
- package/dist/utils/formats.js +1 -1
- package/dist/utils/middlewares.js +3 -3
- package/dist/utils/package_manager.js +68 -0
- package/dist/utils/point_in_time.js +12 -12
- package/dist/utils/psql.js +30 -30
- package/dist/utils/string.js +2 -2
- package/dist/utils/ui.js +9 -9
- package/dist/utils/zip.js +1 -1
- package/dist/writer.js +17 -17
- package/package.json +10 -12
package/dist/psql/io/psqlrc.js
CHANGED
|
@@ -29,19 +29,19 @@
|
|
|
29
29
|
* primitive and delete this duplication. Tracked TODO at the bottom of this
|
|
30
30
|
* file.
|
|
31
31
|
*/
|
|
32
|
-
import { promises as fs } from
|
|
33
|
-
import * as path from
|
|
34
|
-
import {
|
|
35
|
-
import {
|
|
36
|
-
import {
|
|
37
|
-
import {
|
|
38
|
-
import {
|
|
39
|
-
import {
|
|
32
|
+
import { promises as fs } from "node:fs";
|
|
33
|
+
import * as path from "node:path";
|
|
34
|
+
import { attachCondStack, COND_COMMAND_NAMES } from "../command/cmd_cond.js";
|
|
35
|
+
import { dispatchBackslash } from "../command/dispatch.js";
|
|
36
|
+
import { sendQuery } from "../core/common.js";
|
|
37
|
+
import { scanSlashArgs } from "../scanner/slash.js";
|
|
38
|
+
import { scanSql } from "../scanner/sql.js";
|
|
39
|
+
import { initialScanState } from "../types/scanner.js";
|
|
40
40
|
// ---------------------------------------------------------------------------
|
|
41
41
|
// Path discovery.
|
|
42
42
|
// ---------------------------------------------------------------------------
|
|
43
|
-
const isWindows = process.platform ===
|
|
44
|
-
const baseRcName = isWindows ?
|
|
43
|
+
const isWindows = process.platform === "win32";
|
|
44
|
+
const baseRcName = isWindows ? "psqlrc.conf" : ".psqlrc";
|
|
45
45
|
/**
|
|
46
46
|
* Return the default user-level psqlrc path. The path is *not* verified to
|
|
47
47
|
* exist — callers stat it lazily. The Windows layout follows upstream:
|
|
@@ -51,11 +51,11 @@ export const defaultPsqlrcPath = (env = process.env) => {
|
|
|
51
51
|
if (isWindows) {
|
|
52
52
|
const appData = env.APPDATA;
|
|
53
53
|
if (appData && appData.length > 0) {
|
|
54
|
-
return path.join(appData,
|
|
54
|
+
return path.join(appData, "postgresql", baseRcName);
|
|
55
55
|
}
|
|
56
|
-
return path.join(env.USERPROFILE ??
|
|
56
|
+
return path.join(env.USERPROFILE ?? "", "postgresql", baseRcName);
|
|
57
57
|
}
|
|
58
|
-
const home = env.HOME ??
|
|
58
|
+
const home = env.HOME ?? "";
|
|
59
59
|
return path.join(home, baseRcName);
|
|
60
60
|
};
|
|
61
61
|
const versionSuffix = (serverVersion) => {
|
|
@@ -73,61 +73,61 @@ export const psqlrcCandidates = (env, serverVersion) => {
|
|
|
73
73
|
// System-wide.
|
|
74
74
|
const sysDir = env.PGSYSCONFDIR;
|
|
75
75
|
if (sysDir && sysDir.length > 0) {
|
|
76
|
-
const sysBase = isWindows ?
|
|
76
|
+
const sysBase = isWindows ? "psqlrc.conf" : "psqlrc";
|
|
77
77
|
if (suffix) {
|
|
78
78
|
out.push({
|
|
79
79
|
path: path.join(sysDir, `${sysBase}-${suffix}`),
|
|
80
|
-
description:
|
|
80
|
+
description: "system psqlrc (versioned)",
|
|
81
81
|
});
|
|
82
82
|
}
|
|
83
83
|
out.push({
|
|
84
84
|
path: path.join(sysDir, sysBase),
|
|
85
|
-
description:
|
|
85
|
+
description: "system psqlrc",
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
88
|
// PSQLRC override suppresses HOME-based discovery (matches upstream).
|
|
89
89
|
const envRc = env.PSQLRC;
|
|
90
|
-
if (envRc !== undefined && envRc !==
|
|
91
|
-
out.push({ path: expandTilde(envRc, env), description:
|
|
90
|
+
if (envRc !== undefined && envRc !== "") {
|
|
91
|
+
out.push({ path: expandTilde(envRc, env), description: "$PSQLRC" });
|
|
92
92
|
return out;
|
|
93
93
|
}
|
|
94
94
|
// HOME-based.
|
|
95
|
-
const home = env.HOME ??
|
|
95
|
+
const home = env.HOME ?? "";
|
|
96
96
|
if (isWindows) {
|
|
97
97
|
const appData = env.APPDATA;
|
|
98
98
|
const dir = appData && appData.length > 0
|
|
99
|
-
? path.join(appData,
|
|
100
|
-
: path.join(env.USERPROFILE ??
|
|
99
|
+
? path.join(appData, "postgresql")
|
|
100
|
+
: path.join(env.USERPROFILE ?? "", "postgresql");
|
|
101
101
|
if (suffix) {
|
|
102
102
|
out.push({
|
|
103
103
|
path: path.join(dir, `${baseRcName}-${suffix}`),
|
|
104
|
-
description:
|
|
104
|
+
description: "user psqlrc (versioned)",
|
|
105
105
|
});
|
|
106
106
|
}
|
|
107
107
|
out.push({
|
|
108
108
|
path: path.join(dir, baseRcName),
|
|
109
|
-
description:
|
|
109
|
+
description: "user psqlrc",
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
112
|
else if (home.length > 0) {
|
|
113
113
|
if (suffix) {
|
|
114
114
|
out.push({
|
|
115
115
|
path: path.join(home, `${baseRcName}-${suffix}`),
|
|
116
|
-
description:
|
|
116
|
+
description: "user psqlrc (versioned)",
|
|
117
117
|
});
|
|
118
118
|
}
|
|
119
119
|
out.push({
|
|
120
120
|
path: path.join(home, baseRcName),
|
|
121
|
-
description:
|
|
121
|
+
description: "user psqlrc",
|
|
122
122
|
});
|
|
123
123
|
}
|
|
124
124
|
return out;
|
|
125
125
|
};
|
|
126
126
|
const expandTilde = (p, env) => {
|
|
127
|
-
if (p.startsWith(
|
|
127
|
+
if (p.startsWith("~/") && env.HOME) {
|
|
128
128
|
return path.join(env.HOME, p.slice(2));
|
|
129
129
|
}
|
|
130
|
-
if (p ===
|
|
130
|
+
if (p === "~" && env.HOME) {
|
|
131
131
|
return env.HOME;
|
|
132
132
|
}
|
|
133
133
|
return p;
|
|
@@ -137,11 +137,11 @@ const expandTilde = (p, env) => {
|
|
|
137
137
|
// ---------------------------------------------------------------------------
|
|
138
138
|
const readIfExists = async (file) => {
|
|
139
139
|
try {
|
|
140
|
-
return await fs.readFile(file,
|
|
140
|
+
return await fs.readFile(file, "utf8");
|
|
141
141
|
}
|
|
142
142
|
catch (err) {
|
|
143
143
|
const code = err.code;
|
|
144
|
-
if (code ===
|
|
144
|
+
if (code === "ENOENT" || code === "ENOTDIR")
|
|
145
145
|
return null;
|
|
146
146
|
// Permission / I/O errors propagate — they're worth surfacing because
|
|
147
147
|
// they signal a likely misconfiguration. Mirror upstream which prints
|
|
@@ -166,7 +166,7 @@ const makeBackslashContext = (ctx, cmdName, rawArgs, queryBuf) => {
|
|
|
166
166
|
cmdName,
|
|
167
167
|
queryBuf,
|
|
168
168
|
rawArgs,
|
|
169
|
-
nextArg(mode =
|
|
169
|
+
nextArg(mode = "normal") {
|
|
170
170
|
const av = argsFor(mode);
|
|
171
171
|
const idx = cursors.get(mode) ?? 0;
|
|
172
172
|
if (idx >= av.length)
|
|
@@ -195,7 +195,7 @@ const makeBackslashContext = (ctx, cmdName, rawArgs, queryBuf) => {
|
|
|
195
195
|
*/
|
|
196
196
|
export const executeInputString = async (input, ctx, opts = {}) => {
|
|
197
197
|
let working = input;
|
|
198
|
-
let queryBuf =
|
|
198
|
+
let queryBuf = "";
|
|
199
199
|
let scanState = initialScanState();
|
|
200
200
|
let hadError = false;
|
|
201
201
|
let stoppedOnError = false;
|
|
@@ -203,7 +203,7 @@ export const executeInputString = async (input, ctx, opts = {}) => {
|
|
|
203
203
|
const print = opts.print ?? false;
|
|
204
204
|
const noteConnectionLost = () => {
|
|
205
205
|
if (ctx.settings.db?.isClosed()) {
|
|
206
|
-
ctx.stderr.write(
|
|
206
|
+
ctx.stderr.write("psql: error: connection to server was lost\n");
|
|
207
207
|
connectionLost = true;
|
|
208
208
|
return true;
|
|
209
209
|
}
|
|
@@ -217,11 +217,11 @@ export const executeInputString = async (input, ctx, opts = {}) => {
|
|
|
217
217
|
while (working.length > 0) {
|
|
218
218
|
const r = scanSql(working, scanState, sqlVarLookup);
|
|
219
219
|
scanState = r.nextState;
|
|
220
|
-
if (r.kind ===
|
|
220
|
+
if (r.kind === "semicolon") {
|
|
221
221
|
// Use the substituted text rather than the raw slice so `:NAME`
|
|
222
222
|
// expansions land in the executed SQL.
|
|
223
223
|
const sqlText = queryBuf + r.sql;
|
|
224
|
-
queryBuf =
|
|
224
|
+
queryBuf = "";
|
|
225
225
|
working = working.slice(r.consumed);
|
|
226
226
|
scanState = initialScanState();
|
|
227
227
|
if (!ctx.cond.isActive())
|
|
@@ -269,7 +269,7 @@ export const executeInputString = async (input, ctx, opts = {}) => {
|
|
|
269
269
|
}
|
|
270
270
|
continue;
|
|
271
271
|
}
|
|
272
|
-
if (r.kind ===
|
|
272
|
+
if (r.kind === "backslash") {
|
|
273
273
|
// Use `r.sql` — the scanner's substituted/processed text that
|
|
274
274
|
// *preceded* the backslash boundary. The raw consumed slice would
|
|
275
275
|
// also include the backslash command itself and any separators
|
|
@@ -301,26 +301,26 @@ export const executeInputString = async (input, ctx, opts = {}) => {
|
|
|
301
301
|
}
|
|
302
302
|
continue;
|
|
303
303
|
}
|
|
304
|
-
if (res.status ===
|
|
304
|
+
if (res.status === "exit")
|
|
305
305
|
return { hadError, stoppedOnError, connectionLost };
|
|
306
|
-
if (res.status ===
|
|
307
|
-
queryBuf = res.newBuf ??
|
|
306
|
+
if (res.status === "reset-buf") {
|
|
307
|
+
queryBuf = res.newBuf ?? "";
|
|
308
308
|
scanState = initialScanState();
|
|
309
309
|
}
|
|
310
310
|
// Mirror upstream `mainloop.c`: a backslash command that errored
|
|
311
311
|
// drops the query buffer and resets the scanner. Without this the
|
|
312
312
|
// residue would re-execute via the tail-dispatch at EOF (or get
|
|
313
313
|
// glued onto the next dispatched statement), masking the failure.
|
|
314
|
-
if (res.status ===
|
|
315
|
-
queryBuf =
|
|
314
|
+
if (res.status === "error") {
|
|
315
|
+
queryBuf = "";
|
|
316
316
|
scanState = initialScanState();
|
|
317
317
|
}
|
|
318
|
-
if (res.status ===
|
|
318
|
+
if (res.status === "error")
|
|
319
319
|
hadError = true; // latch
|
|
320
320
|
if (noteConnectionLost()) {
|
|
321
321
|
return { hadError, stoppedOnError, connectionLost };
|
|
322
322
|
}
|
|
323
|
-
if (res.status ===
|
|
323
|
+
if (res.status === "error" && ctx.settings.onErrorStop) {
|
|
324
324
|
stoppedOnError = true;
|
|
325
325
|
return { hadError, stoppedOnError, connectionLost };
|
|
326
326
|
}
|
|
@@ -331,7 +331,7 @@ export const executeInputString = async (input, ctx, opts = {}) => {
|
|
|
331
331
|
// substituted form. (Same caveat as the mainloop: cross-chunk colon
|
|
332
332
|
// references fall back to the literal.)
|
|
333
333
|
queryBuf += r.sql;
|
|
334
|
-
working =
|
|
334
|
+
working = "";
|
|
335
335
|
}
|
|
336
336
|
// Tail dispatch: if the file ended mid-statement (no trailing `;`), run
|
|
337
337
|
// the residue. This matches `process_file` behaviour in upstream.
|
|
@@ -376,7 +376,7 @@ export const loadPsqlrc = async (ctx, opts = {}) => {
|
|
|
376
376
|
if (content === null)
|
|
377
377
|
return;
|
|
378
378
|
const prevSource = ctx.settings.curCmdSource;
|
|
379
|
-
ctx.settings.curCmdSource =
|
|
379
|
+
ctx.settings.curCmdSource = "rcfile";
|
|
380
380
|
try {
|
|
381
381
|
await executeInputString(content, ctx);
|
|
382
382
|
}
|
|
@@ -394,14 +394,14 @@ export const loadPsqlrc = async (ctx, opts = {}) => {
|
|
|
394
394
|
// clobber the versioned one.
|
|
395
395
|
let systemDone = false;
|
|
396
396
|
for (const c of candidates) {
|
|
397
|
-
const isSystem = c.description.startsWith(
|
|
397
|
+
const isSystem = c.description.startsWith("system");
|
|
398
398
|
if (isSystem && systemDone)
|
|
399
399
|
continue; // first system file already ran
|
|
400
400
|
const content = await readIfExists(c.path);
|
|
401
401
|
if (content === null)
|
|
402
402
|
continue;
|
|
403
403
|
const prevSource = ctx.settings.curCmdSource;
|
|
404
|
-
ctx.settings.curCmdSource =
|
|
404
|
+
ctx.settings.curCmdSource = "rcfile";
|
|
405
405
|
try {
|
|
406
406
|
await executeInputString(content, ctx);
|
|
407
407
|
}
|