neonctl 2.28.0 → 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 +2 -2
- package/dist/analytics.js +35 -33
- package/dist/api.js +34 -34
- package/dist/auth.js +50 -44
- package/dist/cli.js +2 -2
- package/dist/commands/auth.js +58 -52
- package/dist/commands/bootstrap.js +115 -157
- package/dist/commands/branches.js +154 -147
- package/dist/commands/bucket.js +124 -118
- package/dist/commands/checkout.js +49 -49
- package/dist/commands/config.js +212 -88
- package/dist/commands/connection_string.js +62 -62
- package/dist/commands/data_api.js +96 -96
- package/dist/commands/databases.js +23 -23
- 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 +97 -98
- package/dist/commands/index.js +26 -26
- package/dist/commands/init.js +23 -22
- package/dist/commands/ip_allow.js +29 -29
- package/dist/commands/link.js +223 -166
- package/dist/commands/neon_auth.js +381 -363
- package/dist/commands/operations.js +11 -11
- package/dist/commands/orgs.js +8 -8
- package/dist/commands/projects.js +101 -99
- package/dist/commands/psql.js +31 -31
- package/dist/commands/roles.js +21 -21
- package/dist/commands/schema_diff.js +23 -23
- package/dist/commands/set_context.js +17 -17
- package/dist/commands/status.js +17 -17
- 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 +23 -16
- package/dist/current_branch_fast_path.js +6 -6
- 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 +19 -19
- package/dist/functions_api.js +10 -10
- package/dist/help.js +15 -15
- package/dist/index.js +94 -92
- package/dist/log.js +2 -2
- 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 +15 -15
- package/dist/test_utils/fixtures.js +34 -31
- package/dist/test_utils/oauth_server.js +5 -5
- package/dist/utils/api_enums.js +13 -13
- 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 +20 -15
- 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 +6 -7
package/dist/help.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { consumeBlockIfMatches, consumeNextMatching, drawPointer, splitColumns, } from
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import cliui from "cliui";
|
|
3
|
+
import { consumeBlockIfMatches, consumeNextMatching, drawPointer, splitColumns, } from "./utils/ui.js";
|
|
4
4
|
// target width for the leftmost column
|
|
5
5
|
const SPACE_WIDTH = 20;
|
|
6
6
|
const formatHelp = (help) => {
|
|
7
|
-
const lines = help.split(
|
|
7
|
+
const lines = help.split("\n");
|
|
8
8
|
const result = [];
|
|
9
9
|
// full command, like `neonctl projects list`
|
|
10
10
|
const topLevelCommand = consumeNextMatching(lines, /^.*/);
|
|
11
11
|
if (topLevelCommand) {
|
|
12
|
-
result.push(chalk.bold(topLevelCommand.replace(
|
|
13
|
-
result.push(
|
|
12
|
+
result.push(chalk.bold(topLevelCommand.replace("[options]", chalk.reset.green("[options]"))));
|
|
13
|
+
result.push("");
|
|
14
14
|
}
|
|
15
15
|
// commands description block
|
|
16
16
|
// example command to see: neonctl projects
|
|
@@ -24,7 +24,7 @@ const formatHelp = (help) => {
|
|
|
24
24
|
commandsBlock.forEach((line) => {
|
|
25
25
|
if (/^\s{3,}/.exec(line)) {
|
|
26
26
|
ui.div({
|
|
27
|
-
text:
|
|
27
|
+
text: "",
|
|
28
28
|
width: SPACE_WIDTH,
|
|
29
29
|
padding: [0, 0, 0, 0],
|
|
30
30
|
}, { text: line.trim(), padding: [0, 0, 0, 0] });
|
|
@@ -44,7 +44,7 @@ const formatHelp = (help) => {
|
|
|
44
44
|
}, { text: description, padding: [0, 0, 0, 2] });
|
|
45
45
|
});
|
|
46
46
|
result.push(ui.toString());
|
|
47
|
-
result.push(
|
|
47
|
+
result.push("");
|
|
48
48
|
}
|
|
49
49
|
// positional args block
|
|
50
50
|
// example command to see: neonctl branches rename
|
|
@@ -67,14 +67,14 @@ const formatHelp = (help) => {
|
|
|
67
67
|
});
|
|
68
68
|
});
|
|
69
69
|
result.push(ui.toString());
|
|
70
|
-
result.push(
|
|
70
|
+
result.push("");
|
|
71
71
|
}
|
|
72
72
|
// command description
|
|
73
73
|
// example command to see: neonctl projects list
|
|
74
74
|
const descriptionBlock = consumeBlockIfMatches(lines, /^(?!.*options:)/i);
|
|
75
75
|
if (descriptionBlock.length > 0) {
|
|
76
76
|
result.push(...descriptionBlock);
|
|
77
|
-
result.push(
|
|
77
|
+
result.push("");
|
|
78
78
|
}
|
|
79
79
|
while (true) {
|
|
80
80
|
// there are two options blocks: global and specific
|
|
@@ -89,7 +89,7 @@ const formatHelp = (help) => {
|
|
|
89
89
|
const ui = cliui({
|
|
90
90
|
width: 0,
|
|
91
91
|
});
|
|
92
|
-
if (option.startsWith(
|
|
92
|
+
if (option.startsWith("-")) {
|
|
93
93
|
ui.div({
|
|
94
94
|
text: chalk.green(option),
|
|
95
95
|
padding: [0, 0, 0, 0],
|
|
@@ -99,14 +99,14 @@ const formatHelp = (help) => {
|
|
|
99
99
|
width: SPACE_WIDTH,
|
|
100
100
|
padding: [0, 2, 0, 0],
|
|
101
101
|
}, {
|
|
102
|
-
text: chalk.rgb(210, 210, 210)(description ??
|
|
102
|
+
text: chalk.rgb(210, 210, 210)(description ?? ""),
|
|
103
103
|
padding: [0, 0, 0, 0],
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
106
|
else {
|
|
107
107
|
ui.div({
|
|
108
108
|
padding: [0, 0, 0, 0],
|
|
109
|
-
text:
|
|
109
|
+
text: "",
|
|
110
110
|
width: SPACE_WIDTH,
|
|
111
111
|
}, {
|
|
112
112
|
text: chalk.rgb(210, 210, 210)(option),
|
|
@@ -115,7 +115,7 @@ const formatHelp = (help) => {
|
|
|
115
115
|
}
|
|
116
116
|
result.push(ui.toString());
|
|
117
117
|
});
|
|
118
|
-
result.push(
|
|
118
|
+
result.push("");
|
|
119
119
|
}
|
|
120
120
|
const exampleBlock = consumeBlockIfMatches(lines, /Examples:/);
|
|
121
121
|
if (exampleBlock.length > 0) {
|
|
@@ -141,6 +141,6 @@ const formatHelp = (help) => {
|
|
|
141
141
|
export const showHelp = async (argv) => {
|
|
142
142
|
// add wrap to ensure that there are no line breaks
|
|
143
143
|
const help = await argv.getHelp();
|
|
144
|
-
process.stderr.write(formatHelp(help).join(
|
|
144
|
+
process.stderr.write(formatHelp(help).join("\n") + "\n");
|
|
145
145
|
process.exit(0);
|
|
146
146
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,111 +1,111 @@
|
|
|
1
|
-
import { basename } from
|
|
2
|
-
import yargs from
|
|
3
|
-
import { hideBin } from
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import
|
|
15
|
-
import {
|
|
1
|
+
import { basename } from "node:path";
|
|
2
|
+
import yargs from "yargs";
|
|
3
|
+
import { hideBin } from "yargs/helpers";
|
|
4
|
+
import { analyticsMiddleware, closeAnalytics, getAnalyticsEventProperties, initAnalyticsClientMiddleware, sendError, trackEvent, } from "./analytics.js";
|
|
5
|
+
import { isNeonApiError, messageFromBody } from "./api.js";
|
|
6
|
+
import { defaultClientID } from "./auth.js";
|
|
7
|
+
import { deleteCredentials, ensureAuth } from "./commands/auth.js";
|
|
8
|
+
import commands from "./commands/index.js";
|
|
9
|
+
import { defaultDir, ensureConfigDir } from "./config.js";
|
|
10
|
+
import { currentContextFile, enrichFromContext } from "./context.js";
|
|
11
|
+
import { isNetworkError, matchErrorCode, NETWORK_ERROR_MESSAGE, } from "./errors.js";
|
|
12
|
+
import { showHelp } from "./help.js";
|
|
13
|
+
import { log } from "./log.js";
|
|
14
|
+
import pkg from "./pkg.js";
|
|
15
|
+
import { fillInArgs } from "./utils/middlewares.js";
|
|
16
16
|
const NO_SUBCOMMANDS_VERBS = [
|
|
17
17
|
// aliases
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
"auth",
|
|
19
|
+
"login",
|
|
20
|
+
"me",
|
|
21
21
|
// aliases
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
22
|
+
"cs",
|
|
23
|
+
"connection-string",
|
|
24
|
+
"psql",
|
|
25
|
+
"set-context",
|
|
26
|
+
"checkout",
|
|
27
|
+
"link",
|
|
28
|
+
"init",
|
|
29
|
+
"dev",
|
|
30
|
+
"deploy",
|
|
31
|
+
"bootstrap",
|
|
32
32
|
// alias of `config status`
|
|
33
|
-
|
|
33
|
+
"status",
|
|
34
34
|
];
|
|
35
35
|
let builder = yargs(hideBin(process.argv));
|
|
36
36
|
builder = builder
|
|
37
37
|
.scriptName(pkg.name)
|
|
38
|
-
.locale(
|
|
39
|
-
.usage(
|
|
38
|
+
.locale("en")
|
|
39
|
+
.usage("$0 <command> [options]")
|
|
40
40
|
.parserConfiguration({
|
|
41
|
-
|
|
41
|
+
"populate--": true,
|
|
42
42
|
})
|
|
43
43
|
.help()
|
|
44
|
-
.option(
|
|
45
|
-
alias:
|
|
46
|
-
group:
|
|
47
|
-
describe:
|
|
48
|
-
type:
|
|
49
|
-
choices: [
|
|
50
|
-
default:
|
|
44
|
+
.option("output", {
|
|
45
|
+
alias: "o",
|
|
46
|
+
group: "Global options:",
|
|
47
|
+
describe: "Set output format",
|
|
48
|
+
type: "string",
|
|
49
|
+
choices: ["json", "yaml", "table"],
|
|
50
|
+
default: "table",
|
|
51
51
|
})
|
|
52
|
-
.option(
|
|
53
|
-
describe:
|
|
52
|
+
.option("api-host", {
|
|
53
|
+
describe: "The API host",
|
|
54
54
|
hidden: true,
|
|
55
|
-
default: process.env.NEON_API_HOST ??
|
|
55
|
+
default: process.env.NEON_API_HOST ?? "https://console.neon.tech/api/v2",
|
|
56
56
|
})
|
|
57
57
|
// Setup config directory
|
|
58
|
-
.option(
|
|
59
|
-
describe:
|
|
60
|
-
group:
|
|
61
|
-
type:
|
|
58
|
+
.option("config-dir", {
|
|
59
|
+
describe: "Path to config directory",
|
|
60
|
+
group: "Global options:",
|
|
61
|
+
type: "string",
|
|
62
62
|
default: defaultDir,
|
|
63
63
|
})
|
|
64
|
-
.option(
|
|
65
|
-
describe:
|
|
66
|
-
type:
|
|
64
|
+
.option("force-auth", {
|
|
65
|
+
describe: "Force authentication",
|
|
66
|
+
type: "boolean",
|
|
67
67
|
hidden: true,
|
|
68
68
|
default: false,
|
|
69
69
|
})
|
|
70
70
|
.middleware(ensureConfigDir)
|
|
71
71
|
.options({
|
|
72
|
-
|
|
73
|
-
description:
|
|
72
|
+
"oauth-host": {
|
|
73
|
+
description: "URL to Neon OAuth host",
|
|
74
74
|
hidden: true,
|
|
75
|
-
default: process.env.NEON_OAUTH_HOST ??
|
|
75
|
+
default: process.env.NEON_OAUTH_HOST ?? "https://oauth2.neon.tech",
|
|
76
76
|
},
|
|
77
|
-
|
|
78
|
-
description:
|
|
77
|
+
"client-id": {
|
|
78
|
+
description: "OAuth client id",
|
|
79
79
|
hidden: true,
|
|
80
|
-
type:
|
|
80
|
+
type: "string",
|
|
81
81
|
default: defaultClientID,
|
|
82
82
|
},
|
|
83
|
-
|
|
84
|
-
describe:
|
|
85
|
-
group:
|
|
86
|
-
type:
|
|
87
|
-
default: process.env.NEON_API_KEY ??
|
|
83
|
+
"api-key": {
|
|
84
|
+
describe: "API key",
|
|
85
|
+
group: "Global options:",
|
|
86
|
+
type: "string",
|
|
87
|
+
default: process.env.NEON_API_KEY ?? "",
|
|
88
88
|
},
|
|
89
89
|
apiClient: {
|
|
90
90
|
hidden: true,
|
|
91
91
|
coerce: (v) => v,
|
|
92
92
|
default: null,
|
|
93
93
|
},
|
|
94
|
-
|
|
95
|
-
describe:
|
|
96
|
-
type:
|
|
94
|
+
"context-file": {
|
|
95
|
+
describe: "Context file",
|
|
96
|
+
type: "string",
|
|
97
97
|
default: currentContextFile,
|
|
98
98
|
},
|
|
99
99
|
color: {
|
|
100
|
-
group:
|
|
101
|
-
describe:
|
|
102
|
-
type:
|
|
100
|
+
group: "Global options:",
|
|
101
|
+
describe: "Colorize the output. Example: --no-color, --color false",
|
|
102
|
+
type: "boolean",
|
|
103
103
|
default: true,
|
|
104
104
|
},
|
|
105
105
|
analytics: {
|
|
106
|
-
describe:
|
|
107
|
-
group:
|
|
108
|
-
type:
|
|
106
|
+
describe: "Manage analytics. Example: --no-analytics, --analytics false",
|
|
107
|
+
group: "Global options:",
|
|
108
|
+
type: "boolean",
|
|
109
109
|
default: true,
|
|
110
110
|
},
|
|
111
111
|
})
|
|
@@ -114,13 +114,13 @@ builder = builder
|
|
|
114
114
|
}, true)
|
|
115
115
|
.middleware(initAnalyticsClientMiddleware, true)
|
|
116
116
|
.help(false)
|
|
117
|
-
.group(
|
|
118
|
-
.option(
|
|
119
|
-
describe:
|
|
120
|
-
type:
|
|
117
|
+
.group("help", "Global options:")
|
|
118
|
+
.option("help", {
|
|
119
|
+
describe: "Show help",
|
|
120
|
+
type: "boolean",
|
|
121
121
|
default: false,
|
|
122
122
|
})
|
|
123
|
-
.alias(
|
|
123
|
+
.alias("help", "h")
|
|
124
124
|
.middleware(async (args) => {
|
|
125
125
|
if (args.help ||
|
|
126
126
|
(args._.length === 1 &&
|
|
@@ -134,21 +134,21 @@ builder = builder
|
|
|
134
134
|
.command(commands)
|
|
135
135
|
.strictCommands()
|
|
136
136
|
.version(pkg.version)
|
|
137
|
-
.group(
|
|
138
|
-
.alias(
|
|
137
|
+
.group("version", "Global options:")
|
|
138
|
+
.alias("version", "v")
|
|
139
139
|
.completion()
|
|
140
|
-
.scriptName(basename(process.argv[1]) ===
|
|
141
|
-
.epilog(
|
|
140
|
+
.scriptName(basename(process.argv[1]) === "neon" ? "neon" : "neonctl")
|
|
141
|
+
.epilog("For more information, visit https://neon.com/docs/reference/neon-cli")
|
|
142
142
|
.wrap(null)
|
|
143
143
|
.fail(false);
|
|
144
144
|
async function handleError(msg, err) {
|
|
145
|
-
if (process.argv.some((arg) => arg ===
|
|
145
|
+
if (process.argv.some((arg) => arg === "--help" || arg === "-h")) {
|
|
146
146
|
await showHelp(builder);
|
|
147
147
|
process.exit(0);
|
|
148
148
|
}
|
|
149
149
|
// Log stack trace if available
|
|
150
150
|
if (err instanceof Error && err.stack) {
|
|
151
|
-
log.debug(
|
|
151
|
+
log.debug("Stack: %s", err.stack);
|
|
152
152
|
}
|
|
153
153
|
// A connection-level failure (no response ever reached us) reads as a cryptic
|
|
154
154
|
// `fetch failed` from the @neon/sdk / global `fetch` path. Detect it first and
|
|
@@ -158,24 +158,26 @@ async function handleError(msg, err) {
|
|
|
158
158
|
if (isNetworkError(err)) {
|
|
159
159
|
log.error(NETWORK_ERROR_MESSAGE);
|
|
160
160
|
const error = err instanceof Error ? err : new Error(NETWORK_ERROR_MESSAGE);
|
|
161
|
-
sendError(error,
|
|
161
|
+
sendError(error, "NETWORK_ERROR");
|
|
162
162
|
return false;
|
|
163
163
|
}
|
|
164
164
|
if (isNeonApiError(err)) {
|
|
165
|
-
if (err.code ===
|
|
166
|
-
log.error(
|
|
167
|
-
sendError(err,
|
|
165
|
+
if (err.code === "ECONNABORTED") {
|
|
166
|
+
log.error("Request timed out");
|
|
167
|
+
sendError(err, "REQUEST_TIMEOUT");
|
|
168
168
|
return false;
|
|
169
169
|
}
|
|
170
170
|
else if (err.status === 401) {
|
|
171
|
-
sendError(err,
|
|
172
|
-
log.info(
|
|
171
|
+
sendError(err, "AUTH_FAILED");
|
|
172
|
+
log.info("Authentication failed, deleting credentials...");
|
|
173
173
|
try {
|
|
174
174
|
deleteCredentials(defaultDir);
|
|
175
175
|
return true; // Allow retry for auth failures
|
|
176
176
|
}
|
|
177
177
|
catch (deleteErr) {
|
|
178
|
-
log.debug(
|
|
178
|
+
log.debug("Failed to delete credentials: %s", deleteErr instanceof Error
|
|
179
|
+
? deleteErr.message
|
|
180
|
+
: "unknown error");
|
|
179
181
|
return false;
|
|
180
182
|
}
|
|
181
183
|
}
|
|
@@ -184,13 +186,13 @@ async function handleError(msg, err) {
|
|
|
184
186
|
if (serverMessage) {
|
|
185
187
|
log.error(serverMessage);
|
|
186
188
|
}
|
|
187
|
-
log.debug(
|
|
188
|
-
sendError(err,
|
|
189
|
+
log.debug("status: %d %s | path: %s", err.status, err.statusText, err.requestPath);
|
|
190
|
+
sendError(err, "API_ERROR");
|
|
189
191
|
return false;
|
|
190
192
|
}
|
|
191
193
|
}
|
|
192
194
|
else {
|
|
193
|
-
const error = err instanceof Error ? err : new Error(msg ||
|
|
195
|
+
const error = err instanceof Error ? err : new Error(msg || "Unknown error");
|
|
194
196
|
sendError(error, matchErrorCode(error.message));
|
|
195
197
|
log.error(error.message);
|
|
196
198
|
return false;
|
|
@@ -204,7 +206,7 @@ void (async () => {
|
|
|
204
206
|
try {
|
|
205
207
|
const args = await builder.argv;
|
|
206
208
|
// Send analytics for a successful attempt
|
|
207
|
-
trackEvent(
|
|
209
|
+
trackEvent("cli_command_success", {
|
|
208
210
|
...getAnalyticsEventProperties(args),
|
|
209
211
|
projectId: args.projectId,
|
|
210
212
|
branchId: args.branchId,
|
|
@@ -221,7 +223,7 @@ void (async () => {
|
|
|
221
223
|
}
|
|
222
224
|
catch (err) {
|
|
223
225
|
attempts++;
|
|
224
|
-
const shouldRetry = await handleError(
|
|
226
|
+
const shouldRetry = await handleError("", err);
|
|
225
227
|
if (!shouldRetry || attempts >= MAX_ATTEMPTS) {
|
|
226
228
|
await closeAnalytics();
|
|
227
229
|
process.exit(1);
|
package/dist/log.js
CHANGED
package/dist/pkg.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { readFileSync } from
|
|
2
|
-
import { dirname, join } from
|
|
3
|
-
import { fileURLToPath } from
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
4
|
/**
|
|
5
5
|
* Load the CLI's package.json for version metadata. In the built CLI it sits right next to
|
|
6
6
|
* this module (the build copies it into `dist`); when running from source (tests, `tsx`) it
|
|
@@ -11,12 +11,12 @@ const loadPkg = () => {
|
|
|
11
11
|
let dir = dirname(fileURLToPath(import.meta.url));
|
|
12
12
|
for (;;) {
|
|
13
13
|
try {
|
|
14
|
-
return JSON.parse(readFileSync(join(dir,
|
|
14
|
+
return JSON.parse(readFileSync(join(dir, "package.json"), "utf-8"));
|
|
15
15
|
}
|
|
16
16
|
catch {
|
|
17
17
|
const parent = dirname(dir);
|
|
18
18
|
if (parent === dir) {
|
|
19
|
-
throw new Error(
|
|
19
|
+
throw new Error("Could not locate package.json for version detection.");
|
|
20
20
|
}
|
|
21
21
|
dir = parent;
|
|
22
22
|
}
|
package/dist/psql/cli.js
CHANGED
|
@@ -29,14 +29,16 @@
|
|
|
29
29
|
* EXIT_SUCCESS / EXIT_FAILURE / EXIT_USER / EXIT_BADCONN values; see
|
|
30
30
|
* `core/mainloop.ts`).
|
|
31
31
|
*/
|
|
32
|
-
import {
|
|
32
|
+
import { looksLikeConnectionString, runPsql } from "./index.js";
|
|
33
33
|
const main = async () => {
|
|
34
34
|
const raw = process.argv.slice(2);
|
|
35
35
|
// Detect whether the first arg is a connection URI/conninfo string.
|
|
36
36
|
// libpq's `recognized_connection_string()` covers both `postgres[ql]://…`
|
|
37
37
|
// URIs and bare `key=value` conninfo strings — `looksLikeConnectionString`
|
|
38
38
|
// mirrors that test.
|
|
39
|
-
const argv = raw.length > 0 && looksLikeConnectionString(raw[0])
|
|
39
|
+
const argv = raw.length > 0 && looksLikeConnectionString(raw[0])
|
|
40
|
+
? raw
|
|
41
|
+
: ["", ...raw];
|
|
40
42
|
const code = await runPsql(argv, {
|
|
41
43
|
stdin: process.stdin,
|
|
42
44
|
stdout: process.stdout,
|