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