neon 3.0.0 → 3.1.1
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 +70 -5
- package/dist/_chunks/auth_selection-DGgq6ifc.js +83 -0
- package/dist/_chunks/cmd_pipeline-CUbBO9U_.js +2818 -0
- package/dist/_chunks/credentials-MYdHdKah.js +188 -0
- package/dist/_chunks/env-NbA61JR3.js +585 -0
- package/dist/_chunks/env_services-Tz9G4JeT.js +531 -0
- package/dist/_chunks/paths-DMq0Lt7a.js +151 -0
- package/dist/_chunks/profiles-Ir29rqns.js +217 -0
- package/dist/_chunks/psql-DWH-kc69.js +2169 -0
- package/dist/_chunks/rolldown-runtime-D7D4PA-g.js +13 -0
- package/dist/_chunks/secure_file-BucZj4yQ.js +39 -0
- package/dist/analytics.js +163 -207
- package/dist/api.js +815 -758
- package/dist/auth.js +121 -141
- package/dist/auth_context.js +39 -53
- package/dist/cli.js +4 -7
- package/dist/commands/api.js +220 -250
- package/dist/commands/api_keys.js +251 -314
- package/dist/commands/auth.js +283 -328
- package/dist/commands/bootstrap.js +372 -437
- package/dist/commands/branches.js +304 -455
- package/dist/commands/bucket.js +374 -514
- package/dist/commands/checkout.js +213 -298
- package/dist/commands/config.js +573 -690
- package/dist/commands/connection_string.js +137 -165
- package/dist/commands/data_api.js +238 -260
- package/dist/commands/databases.js +67 -76
- package/dist/commands/deploy.js +31 -25
- package/dist/commands/dev.js +639 -719
- package/dist/commands/diff.js +156 -200
- package/dist/commands/env.js +255 -305
- package/dist/commands/functions.js +275 -355
- package/dist/commands/index.js +70 -65
- package/dist/commands/init.js +84 -119
- package/dist/commands/inspect.js +55 -55
- package/dist/commands/ip_allow.js +88 -120
- package/dist/commands/link.js +874 -1019
- package/dist/commands/logs.js +291 -0
- package/dist/commands/neon_auth.js +725 -933
- package/dist/commands/operations.js +34 -25
- package/dist/commands/orgs.js +28 -18
- package/dist/commands/profile.js +615 -846
- package/dist/commands/projects.js +313 -373
- package/dist/commands/psql.js +60 -58
- package/dist/commands/roles.js +55 -58
- package/dist/commands/schema_diff.js +87 -131
- package/dist/commands/set_context.js +34 -26
- package/dist/commands/snapshots.js +288 -413
- package/dist/commands/status.js +41 -37
- package/dist/commands/user.js +21 -10
- package/dist/commands/vpc_endpoints.js +85 -113
- package/dist/config.js +7 -6
- package/dist/config_format.js +50 -66
- package/dist/config_template.js +128 -157
- package/dist/context.js +183 -235
- package/dist/current_branch_fast_path.js +40 -49
- package/dist/dev/env.js +2 -446
- package/dist/dev/functions.js +54 -68
- package/dist/dev/inputs.js +46 -58
- package/dist/dev/runtime.js +135 -164
- package/dist/dev/websocket.js +766 -959
- package/dist/env.js +27 -33
- package/dist/env_file.js +118 -132
- package/dist/env_services.js +2 -51
- package/dist/errors.js +57 -68
- package/dist/functions_api.js +45 -43
- package/dist/help.js +189 -140
- package/dist/index.js +182 -257
- package/dist/init/agents.js +137 -118
- package/dist/init/auth.js +58 -68
- package/dist/init/bootstrap.js +325 -396
- package/dist/init/build_config.js +4 -2
- package/dist/init/detect_agent.js +56 -101
- package/dist/init/editors.js +35 -52
- package/dist/init/enrich_output.js +51 -66
- package/dist/init/extension.js +134 -171
- package/dist/init/inspect.js +179 -266
- package/dist/init/interactive.js +510 -622
- package/dist/init/neonctl.js +117 -168
- package/dist/init/orchestrate.js +157 -173
- package/dist/init/phases/auth.js +188 -202
- package/dist/init/phases/cleanup.js +23 -23
- package/dist/init/phases/db.js +251 -277
- package/dist/init/phases/getting_started.js +213 -223
- package/dist/init/phases/mcp.js +174 -224
- package/dist/init/phases/migrations.js +247 -248
- package/dist/init/phases/neon_auth.js +114 -133
- package/dist/init/phases/setup.js +546 -703
- package/dist/init/phases/skills.js +75 -86
- package/dist/init/phases/status.js +72 -67
- package/dist/init/resolve_context.js +102 -99
- package/dist/init/route_command.js +91 -98
- package/dist/init/skills.js +174 -218
- package/dist/init/vsix.js +77 -99
- package/dist/log.js +17 -16
- package/dist/neon_services.js +104 -129
- package/dist/parameters.gen.js +481 -471
- package/dist/pkg.js +17 -19
- package/dist/profile_keys.js +44 -47
- package/dist/psql/cli.js +44 -47
- package/dist/psql/command/cmd_cond.js +231 -406
- package/dist/psql/command/cmd_connect.js +557 -764
- package/dist/psql/command/cmd_copy.js +728 -984
- package/dist/psql/command/cmd_describe.js +1499 -1688
- package/dist/psql/command/cmd_format.js +733 -905
- package/dist/psql/command/cmd_io.js +2 -2193
- package/dist/psql/command/cmd_lo.js +297 -359
- package/dist/psql/command/cmd_meta.js +727 -878
- package/dist/psql/command/cmd_misc.js +138 -172
- package/dist/psql/command/cmd_pipeline.js +2 -1148
- package/dist/psql/command/cmd_restrict.js +119 -155
- package/dist/psql/command/cmd_show.js +529 -688
- package/dist/psql/command/dispatch.js +260 -325
- package/dist/psql/command/inputQueue.js +35 -33
- package/dist/psql/command/shared.js +49 -63
- package/dist/psql/complete/filenames.js +90 -133
- package/dist/psql/complete/index.js +59 -97
- package/dist/psql/complete/matcher.js +236 -300
- package/dist/psql/complete/psqlVars.js +218 -223
- package/dist/psql/complete/queries.js +159 -177
- package/dist/psql/complete/rules.js +1493 -2299
- package/dist/psql/core/common.js +2 -1253
- package/dist/psql/core/help.js +456 -546
- package/dist/psql/core/mainloop.js +692 -1303
- package/dist/psql/core/prompt.js +391 -408
- package/dist/psql/core/settings.js +429 -644
- package/dist/psql/core/sqlHelp.js +480 -554
- package/dist/psql/core/startup.js +2 -846
- package/dist/psql/core/syncVars.js +67 -110
- package/dist/psql/core/variables.js +156 -278
- package/dist/psql/describe/formatters.js +884 -1285
- package/dist/psql/describe/processNamePattern.js +173 -260
- package/dist/psql/describe/queries.js +1368 -2403
- package/dist/psql/describe/versionGate.js +32 -41
- package/dist/psql/index.js +2 -2030
- package/dist/psql/io/history.js +232 -271
- package/dist/psql/io/input.js +103 -108
- package/dist/psql/io/lineEditor/buffer.js +238 -319
- package/dist/psql/io/lineEditor/complete.js +135 -213
- package/dist/psql/io/lineEditor/filename.js +139 -148
- package/dist/psql/io/lineEditor/index.js +653 -870
- package/dist/psql/io/lineEditor/keymap.js +544 -702
- package/dist/psql/io/lineEditor/vt100.js +294 -341
- package/dist/psql/io/pgpass.js +158 -187
- package/dist/psql/io/pgservice.js +146 -183
- package/dist/psql/io/psqlrc.js +328 -403
- package/dist/psql/print/aligned.js +1020 -1683
- package/dist/psql/print/asciidoc.js +180 -214
- package/dist/psql/print/crosstab.js +281 -442
- package/dist/psql/print/csv.js +48 -70
- package/dist/psql/print/html.js +195 -226
- package/dist/psql/print/json.js +75 -88
- package/dist/psql/print/latex.js +291 -364
- package/dist/psql/print/pager.js +171 -242
- package/dist/psql/print/troff.js +194 -226
- package/dist/psql/print/unaligned.js +69 -95
- package/dist/psql/print/units.js +167 -169
- package/dist/psql/scanner/slash.js +428 -483
- package/dist/psql/scanner/sql.js +445 -889
- package/dist/psql/scanner/stringutils.js +309 -379
- package/dist/psql/types/index.js +8 -7
- package/dist/psql/types/scanner.js +25 -22
- package/dist/psql/wire/connection.js +2042 -2803
- package/dist/psql/wire/copy.js +84 -100
- package/dist/psql/wire/notify.js +39 -59
- package/dist/psql/wire/pipeline.js +305 -518
- package/dist/psql/wire/protocol.js +349 -417
- package/dist/psql/wire/sasl.js +180 -265
- package/dist/psql/wire/tls.js +400 -561
- package/dist/storage_api.js +115 -129
- package/dist/test_utils/fixtures.js +94 -113
- package/dist/test_utils/oauth_server.js +10 -7
- package/dist/test_utils/project_dir.js +33 -0
- package/dist/utils/ai_gateway_notice.js +131 -162
- package/dist/utils/api_enums.js +21 -28
- package/dist/utils/auth.js +10 -4
- package/dist/utils/branch_notice.js +20 -19
- package/dist/utils/branch_picker.js +83 -89
- package/dist/utils/cli_name.js +15 -12
- package/dist/utils/compute_units.js +20 -27
- package/dist/utils/config_diff.js +127 -158
- package/dist/utils/enrichers.js +95 -148
- package/dist/utils/esbuild.js +130 -189
- package/dist/utils/flags.js +35 -47
- package/dist/utils/formats.js +8 -15
- package/dist/utils/git_diff.js +69 -80
- package/dist/utils/inspect_db.js +101 -143
- package/dist/utils/inspect_queries.js +179 -142
- package/dist/utils/middlewares.js +39 -45
- package/dist/utils/openapi.js +87 -99
- package/dist/utils/package_manager.js +312 -110
- package/dist/utils/point_in_time.js +49 -53
- package/dist/utils/psql.js +89 -106
- package/dist/utils/service_picker.js +55 -58
- package/dist/utils/string.js +5 -5
- package/dist/utils/ui.js +38 -55
- package/dist/utils/write_sync.js +26 -35
- package/dist/utils/zip.js +4 -3
- package/dist/writer.js +67 -87
- package/package.json +11 -6
- package/dist/_shared/auth_selection.js +0 -86
- package/dist/_shared/credentials.js +0 -209
- package/dist/_shared/env-core/env.js +0 -558
- package/dist/_shared/env-core/reuse-secrets.js +0 -223
- package/dist/_shared/paths.js +0 -148
- package/dist/_shared/profiles.js +0 -276
- package/dist/_shared/secure_file.js +0 -43
package/dist/commands/api.js
CHANGED
|
@@ -1,278 +1,248 @@
|
|
|
1
|
+
import { t as __exportAll } from "../_chunks/rolldown-runtime-D7D4PA-g.js";
|
|
2
|
+
import { getEndpoints, loadSpec } from "../utils/openapi.js";
|
|
3
|
+
import { writer } from "../writer.js";
|
|
1
4
|
import { readFileSync } from "node:fs";
|
|
2
5
|
import { resolve } from "node:path";
|
|
3
6
|
import YAML from "yaml";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
//#region src/commands/api.ts
|
|
8
|
+
var api_exports = /* @__PURE__ */ __exportAll({
|
|
9
|
+
buildBody: () => buildBody,
|
|
10
|
+
buildQuery: () => buildQuery,
|
|
11
|
+
builder: () => builder,
|
|
12
|
+
command: () => command,
|
|
13
|
+
describe: () => describe,
|
|
14
|
+
handler: () => handler,
|
|
15
|
+
parseHeaders: () => parseHeaders,
|
|
16
|
+
parseKeyValue: () => parseKeyValue,
|
|
17
|
+
parseTypedValue: () => parseTypedValue,
|
|
18
|
+
setDeep: () => setDeep
|
|
19
|
+
});
|
|
20
|
+
const HTTP_METHODS = [
|
|
21
|
+
"GET",
|
|
22
|
+
"POST",
|
|
23
|
+
"PUT",
|
|
24
|
+
"PATCH",
|
|
25
|
+
"DELETE"
|
|
26
|
+
];
|
|
8
27
|
/**
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
try {
|
|
25
|
-
return JSON.parse(raw);
|
|
26
|
-
}
|
|
27
|
-
catch {
|
|
28
|
-
return raw;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return raw;
|
|
28
|
+
* Coerce a raw string into a typed JSON value: booleans, `null`, integers,
|
|
29
|
+
* floats, and JSON arrays/objects are parsed; everything else stays a string.
|
|
30
|
+
*/
|
|
31
|
+
function parseTypedValue(raw) {
|
|
32
|
+
if (raw === "true") return true;
|
|
33
|
+
if (raw === "false") return false;
|
|
34
|
+
if (raw === "null") return null;
|
|
35
|
+
if (/^-?\d+$/.test(raw)) return Number.parseInt(raw, 10);
|
|
36
|
+
if (/^-?\d*\.\d+$/.test(raw)) return Number.parseFloat(raw);
|
|
37
|
+
if (raw.startsWith("[") || raw.startsWith("{")) try {
|
|
38
|
+
return JSON.parse(raw);
|
|
39
|
+
} catch {
|
|
40
|
+
return raw;
|
|
41
|
+
}
|
|
42
|
+
return raw;
|
|
32
43
|
}
|
|
33
44
|
/** Split a `key=value` pair on the first `=`. */
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
45
|
+
function parseKeyValue(input) {
|
|
46
|
+
const eq = input.indexOf("=");
|
|
47
|
+
if (eq === -1) throw new Error(`Invalid "key=value" pair: "${input}".`);
|
|
48
|
+
return {
|
|
49
|
+
key: input.slice(0, eq),
|
|
50
|
+
value: input.slice(eq + 1)
|
|
51
|
+
};
|
|
40
52
|
}
|
|
41
53
|
/**
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
node[parts[parts.length - 1]] = value;
|
|
54
|
+
* Assign `value` into `target` at a dot-delimited path, creating intermediate
|
|
55
|
+
* objects as needed. Enables `-F branch.name=dev` → `{ branch: { name: "dev" } }`,
|
|
56
|
+
* matching the nested shape of Neon request bodies.
|
|
57
|
+
*/
|
|
58
|
+
function setDeep(target, dottedKey, value) {
|
|
59
|
+
const parts = dottedKey.split(".");
|
|
60
|
+
let node = target;
|
|
61
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
62
|
+
const part = parts[i];
|
|
63
|
+
const next = node[part];
|
|
64
|
+
if (typeof next !== "object" || next === null || Array.isArray(next)) node[part] = {};
|
|
65
|
+
node = node[part];
|
|
66
|
+
}
|
|
67
|
+
node[parts[parts.length - 1]] = value;
|
|
58
68
|
}
|
|
59
69
|
/** Build a JSON body object from typed `-F` and string `-f` field pairs. */
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
function buildBody(fields, rawFields) {
|
|
71
|
+
const body = {};
|
|
72
|
+
for (const field of fields) {
|
|
73
|
+
const { key, value } = parseKeyValue(field);
|
|
74
|
+
setDeep(body, key, parseTypedValue(value));
|
|
75
|
+
}
|
|
76
|
+
for (const field of rawFields) {
|
|
77
|
+
const { key, value } = parseKeyValue(field);
|
|
78
|
+
setDeep(body, key, value);
|
|
79
|
+
}
|
|
80
|
+
return body;
|
|
71
81
|
}
|
|
72
82
|
/** Build a query-string map from `-Q key=value` pairs. */
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
83
|
+
function buildQuery(pairs) {
|
|
84
|
+
const query = {};
|
|
85
|
+
for (const pair of pairs) {
|
|
86
|
+
const { key, value } = parseKeyValue(pair);
|
|
87
|
+
query[key] = value;
|
|
88
|
+
}
|
|
89
|
+
return query;
|
|
80
90
|
}
|
|
81
91
|
/** Build a header map from `-H key:value` pairs. */
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
return headers;
|
|
92
|
+
function parseHeaders(pairs) {
|
|
93
|
+
const headers = {};
|
|
94
|
+
for (const pair of pairs) {
|
|
95
|
+
const idx = pair.indexOf(":");
|
|
96
|
+
if (idx === -1) throw new Error(`Invalid header "${pair}". Expected "key:value".`);
|
|
97
|
+
headers[pair.slice(0, idx).trim()] = pair.slice(idx + 1).trim();
|
|
98
|
+
}
|
|
99
|
+
return headers;
|
|
92
100
|
}
|
|
93
101
|
function assertMethod(method) {
|
|
94
|
-
|
|
95
|
-
throw new Error(`Unsupported method "${method}". Use one of: ${HTTP_METHODS.join(", ")}.`);
|
|
96
|
-
}
|
|
102
|
+
if (!HTTP_METHODS.includes(method)) throw new Error(`Unsupported method "${method}". Use one of: ${HTTP_METHODS.join(", ")}.`);
|
|
97
103
|
}
|
|
98
|
-
// ── I/O helpers ──────────────────────────────────────────────────────────────
|
|
99
104
|
async function readStdin() {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
return Buffer.concat(chunks).toString("utf8");
|
|
105
|
+
const chunks = [];
|
|
106
|
+
for await (const chunk of process.stdin) chunks.push(Buffer.from(chunk));
|
|
107
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
105
108
|
}
|
|
106
109
|
/** Resolve `--data`: `-` reads stdin, `@file` reads a file, else the literal string. Parsed as JSON when possible. */
|
|
107
110
|
async function readData(data) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
try {
|
|
119
|
-
return JSON.parse(raw);
|
|
120
|
-
}
|
|
121
|
-
catch {
|
|
122
|
-
return raw;
|
|
123
|
-
}
|
|
111
|
+
let raw;
|
|
112
|
+
if (data === "-") raw = await readStdin();
|
|
113
|
+
else if (data.startsWith("@")) raw = readFileSync(resolve(data.slice(1)), "utf8");
|
|
114
|
+
else raw = data;
|
|
115
|
+
try {
|
|
116
|
+
return JSON.parse(raw);
|
|
117
|
+
} catch {
|
|
118
|
+
return raw;
|
|
119
|
+
}
|
|
124
120
|
}
|
|
125
121
|
const toStrings = (values) => (values ?? []).map(String);
|
|
126
122
|
async function listEndpoints(args) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
123
|
+
const spec = await loadSpec({
|
|
124
|
+
configDir: args.configDir,
|
|
125
|
+
specUrl: args.specUrl,
|
|
126
|
+
refresh: args.refresh
|
|
127
|
+
});
|
|
128
|
+
if (!spec) throw new Error(`Could not load the Neon OpenAPI spec from ${args.specUrl}. Check your network connection or pass --spec-url.`);
|
|
129
|
+
const endpoints = getEndpoints(spec).map((endpoint) => ({
|
|
130
|
+
method: endpoint.method,
|
|
131
|
+
path: endpoint.path,
|
|
132
|
+
summary: endpoint.summary ?? ""
|
|
133
|
+
}));
|
|
134
|
+
writer(args).end(endpoints, {
|
|
135
|
+
fields: [
|
|
136
|
+
"method",
|
|
137
|
+
"path",
|
|
138
|
+
"summary"
|
|
139
|
+
],
|
|
140
|
+
title: `Neon API endpoints (${endpoints.length})`,
|
|
141
|
+
emptyMessage: "No endpoints found in the spec."
|
|
142
|
+
});
|
|
146
143
|
}
|
|
147
144
|
async function runRequest(args) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
const response = await args.apiClient.request(params);
|
|
179
|
-
const out = process.stdout;
|
|
180
|
-
if (args.include) {
|
|
181
|
-
out.write(`HTTP ${response.status} ${response.statusText}\n`);
|
|
182
|
-
for (const [key, value] of Object.entries(response.headers)) {
|
|
183
|
-
out.write(`${key}: ${value}\n`);
|
|
184
|
-
}
|
|
185
|
-
out.write("\n");
|
|
186
|
-
}
|
|
187
|
-
if (response.data === undefined) {
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
if (args.output === "yaml") {
|
|
191
|
-
out.write(YAML.stringify(response.data));
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
out.write(`${JSON.stringify(response.data, null, 2)}\n`);
|
|
195
|
-
}
|
|
145
|
+
const path = args.path;
|
|
146
|
+
if (!path) throw new Error("Missing API path. Usage: neon api <path> (e.g. neon api /projects). Run `neon api --list` to see available routes.");
|
|
147
|
+
if (!path.startsWith("/")) throw new Error(`Invalid path "${path}". API paths must start with "/". Run \`neon api --list\` to see available routes.`);
|
|
148
|
+
const fields = toStrings(args.field);
|
|
149
|
+
const rawFields = toStrings(args.rawField);
|
|
150
|
+
let body;
|
|
151
|
+
if (args.data !== void 0) body = await readData(args.data);
|
|
152
|
+
else if (fields.length > 0 || rawFields.length > 0) body = buildBody(fields, rawFields);
|
|
153
|
+
const hasBody = body !== void 0;
|
|
154
|
+
const method = String(args.method ?? (hasBody ? "POST" : "GET")).toUpperCase();
|
|
155
|
+
assertMethod(method);
|
|
156
|
+
const query = buildQuery(toStrings(args.query));
|
|
157
|
+
const headers = parseHeaders(toStrings(args.header));
|
|
158
|
+
const params = {
|
|
159
|
+
path,
|
|
160
|
+
method,
|
|
161
|
+
...Object.keys(query).length > 0 ? { query } : {},
|
|
162
|
+
...hasBody ? { body } : {},
|
|
163
|
+
...Object.keys(headers).length > 0 ? { headers } : {}
|
|
164
|
+
};
|
|
165
|
+
const response = await args.apiClient.request(params);
|
|
166
|
+
const out = process.stdout;
|
|
167
|
+
if (args.include) {
|
|
168
|
+
out.write(`HTTP ${response.status} ${response.statusText}\n`);
|
|
169
|
+
for (const [key, value] of Object.entries(response.headers)) out.write(`${key}: ${value}\n`);
|
|
170
|
+
out.write("\n");
|
|
171
|
+
}
|
|
172
|
+
if (response.data === void 0) return;
|
|
173
|
+
if (args.output === "yaml") out.write(YAML.stringify(response.data));
|
|
174
|
+
else out.write(`${JSON.stringify(response.data, null, 2)}\n`);
|
|
196
175
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
})
|
|
268
|
-
.example("$0 api /projects", "List your projects")
|
|
269
|
-
.example("$0 api /projects/{id}/branches -X POST -F branch.name=dev", "Create a branch")
|
|
270
|
-
.example("$0 api --list", "List every available API route");
|
|
271
|
-
export const handler = async (args) => {
|
|
272
|
-
const apiArgs = args;
|
|
273
|
-
if (apiArgs.list || apiArgs.path === "list" || apiArgs.path === "ls") {
|
|
274
|
-
await listEndpoints(apiArgs);
|
|
275
|
-
return;
|
|
276
|
-
}
|
|
277
|
-
await runRequest(apiArgs);
|
|
176
|
+
const command = "api [path]";
|
|
177
|
+
const describe = "Call any Neon API route directly (authenticated passthrough)";
|
|
178
|
+
const builder = (argv) => argv.usage("$0 api <path> [options]").positional("path", {
|
|
179
|
+
type: "string",
|
|
180
|
+
describe: "API path beginning with \"/\" (e.g. /projects or /projects/{project_id}/branches). Use `list` to list endpoints."
|
|
181
|
+
}).options({
|
|
182
|
+
method: {
|
|
183
|
+
alias: "X",
|
|
184
|
+
type: "string",
|
|
185
|
+
describe: "HTTP method (GET, POST, PUT, PATCH, DELETE). Defaults to GET, or POST when a body is provided."
|
|
186
|
+
},
|
|
187
|
+
field: {
|
|
188
|
+
alias: "F",
|
|
189
|
+
type: "array",
|
|
190
|
+
string: true,
|
|
191
|
+
describe: "Body field key=value (repeatable). Dot-notation nests objects (e.g. -F branch.name=dev); values are typed (numbers, booleans, null, JSON)."
|
|
192
|
+
},
|
|
193
|
+
"raw-field": {
|
|
194
|
+
alias: "f",
|
|
195
|
+
type: "array",
|
|
196
|
+
string: true,
|
|
197
|
+
describe: "Body field key=value with the value kept as a raw string."
|
|
198
|
+
},
|
|
199
|
+
data: {
|
|
200
|
+
alias: "d",
|
|
201
|
+
type: "string",
|
|
202
|
+
describe: "Raw request body: a JSON string, @file, or - for stdin. Overrides --field."
|
|
203
|
+
},
|
|
204
|
+
query: {
|
|
205
|
+
alias: "Q",
|
|
206
|
+
type: "array",
|
|
207
|
+
string: true,
|
|
208
|
+
describe: "Query parameter key=value (repeatable)."
|
|
209
|
+
},
|
|
210
|
+
header: {
|
|
211
|
+
alias: "H",
|
|
212
|
+
type: "array",
|
|
213
|
+
string: true,
|
|
214
|
+
describe: "Extra request header key:value (repeatable)."
|
|
215
|
+
},
|
|
216
|
+
include: {
|
|
217
|
+
alias: "i",
|
|
218
|
+
type: "boolean",
|
|
219
|
+
default: false,
|
|
220
|
+
describe: "Print the response status and headers before the body."
|
|
221
|
+
},
|
|
222
|
+
list: {
|
|
223
|
+
type: "boolean",
|
|
224
|
+
default: false,
|
|
225
|
+
describe: "List available API endpoints from the OpenAPI spec."
|
|
226
|
+
},
|
|
227
|
+
refresh: {
|
|
228
|
+
type: "boolean",
|
|
229
|
+
default: false,
|
|
230
|
+
describe: "Refresh the cached OpenAPI spec (used with --list)."
|
|
231
|
+
},
|
|
232
|
+
"spec-url": {
|
|
233
|
+
type: "string",
|
|
234
|
+
default: process.env.NEON_API_SPEC_URL ?? "https://neon.com/api_spec/release/v2.json",
|
|
235
|
+
hidden: true,
|
|
236
|
+
describe: "OpenAPI spec URL used by --list."
|
|
237
|
+
}
|
|
238
|
+
}).example("$0 api /projects", "List your projects").example("$0 api /projects/{id}/branches -X POST -F branch.name=dev", "Create a branch").example("$0 api --list", "List every available API route");
|
|
239
|
+
const handler = async (args) => {
|
|
240
|
+
const apiArgs = args;
|
|
241
|
+
if (apiArgs.list || apiArgs.path === "list" || apiArgs.path === "ls") {
|
|
242
|
+
await listEndpoints(apiArgs);
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
await runRequest(apiArgs);
|
|
278
246
|
};
|
|
247
|
+
//#endregion
|
|
248
|
+
export { buildBody, buildQuery, builder, command, describe, handler, parseHeaders, parseKeyValue, parseTypedValue, setDeep, api_exports as t };
|