neon 3.0.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 +354 -517
  5. package/dist/_shared/env-core/reuse-secrets.js +159 -203
  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 +573 -690
  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 +639 -719
  28. package/dist/commands/diff.js +156 -200
  29. package/dist/commands/env.js +243 -303
  30. package/dist/commands/functions.js +275 -355
  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 -68
  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 +130 -189
  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 +7 -5
@@ -1,66 +1,71 @@
1
- import * as api from "./api.js";
2
- import * as apiKeys from "./api_keys.js";
3
- import * as auth from "./auth.js";
4
- import * as bootstrap from "./bootstrap.js";
5
- import * as branches from "./branches.js";
6
- import * as bucket from "./bucket.js";
7
- import * as checkout from "./checkout.js";
8
- import * as config from "./config.js";
9
- import * as cs from "./connection_string.js";
10
- import * as dataApi from "./data_api.js";
11
- import * as databases from "./databases.js";
12
- import * as deploy from "./deploy.js";
13
- import * as dev from "./dev.js";
14
- import * as diff from "./diff.js";
15
- import * as env from "./env.js";
16
- import * as functions from "./functions.js";
17
- import * as init from "./init.js";
18
- import * as inspect from "./inspect.js";
19
- import * as ipAllow from "./ip_allow.js";
20
- import * as link from "./link.js";
21
- import * as neonAuth from "./neon_auth.js";
22
- import * as operations from "./operations.js";
23
- import * as orgs from "./orgs.js";
24
- import * as profile from "./profile.js";
25
- import * as projects from "./projects.js";
26
- import * as psql from "./psql.js";
27
- import * as roles from "./roles.js";
28
- import * as setContext from "./set_context.js";
29
- import * as snapshots from "./snapshots.js";
30
- import * as status from "./status.js";
31
- import * as users from "./user.js";
32
- import * as vpcEndpoints from "./vpc_endpoints.js";
33
- export default [
34
- auth,
35
- profile,
36
- apiKeys,
37
- api,
38
- users,
39
- orgs,
40
- projects,
41
- ipAllow,
42
- vpcEndpoints,
43
- neonAuth,
44
- branches,
45
- databases,
46
- roles,
47
- operations,
48
- snapshots,
49
- inspect,
50
- cs,
51
- psql,
52
- setContext,
53
- checkout,
54
- link,
55
- init,
56
- dataApi,
57
- functions,
58
- dev,
59
- diff,
60
- config,
61
- status,
62
- deploy,
63
- env,
64
- bucket,
65
- bootstrap,
1
+ import { auth_exports } from "./auth.js";
2
+ import { api_exports } from "./api.js";
3
+ import { api_keys_exports } from "./api_keys.js";
4
+ import { bootstrap_exports } from "./bootstrap.js";
5
+ import { branches_exports } from "./branches.js";
6
+ import { bucket_exports } from "./bucket.js";
7
+ import { env_exports } from "./env.js";
8
+ import { config_exports } from "./config.js";
9
+ import { projects_exports } from "./projects.js";
10
+ import { link_exports } from "./link.js";
11
+ import { checkout_exports } from "./checkout.js";
12
+ import { connection_string_exports } from "./connection_string.js";
13
+ import { data_api_exports } from "./data_api.js";
14
+ import { databases_exports } from "./databases.js";
15
+ import { deploy_exports } from "./deploy.js";
16
+ import { dev_exports } from "./dev.js";
17
+ import { diff_exports } from "./diff.js";
18
+ import { functions_exports } from "./functions.js";
19
+ import { init_exports } from "./init.js";
20
+ import { inspect_exports } from "./inspect.js";
21
+ import { ip_allow_exports } from "./ip_allow.js";
22
+ import { logs_exports } from "./logs.js";
23
+ import { neon_auth_exports } from "./neon_auth.js";
24
+ import { operations_exports } from "./operations.js";
25
+ import { orgs_exports } from "./orgs.js";
26
+ import { profile_exports } from "./profile.js";
27
+ import { psql_exports } from "./psql.js";
28
+ import { roles_exports } from "./roles.js";
29
+ import { set_context_exports } from "./set_context.js";
30
+ import { snapshots_exports } from "./snapshots.js";
31
+ import { status_exports } from "./status.js";
32
+ import { user_exports } from "./user.js";
33
+ import { vpc_endpoints_exports } from "./vpc_endpoints.js";
34
+ //#region src/commands/index.ts
35
+ var commands_default = [
36
+ auth_exports,
37
+ profile_exports,
38
+ api_keys_exports,
39
+ api_exports,
40
+ user_exports,
41
+ orgs_exports,
42
+ projects_exports,
43
+ ip_allow_exports,
44
+ vpc_endpoints_exports,
45
+ neon_auth_exports,
46
+ branches_exports,
47
+ databases_exports,
48
+ roles_exports,
49
+ operations_exports,
50
+ logs_exports,
51
+ snapshots_exports,
52
+ inspect_exports,
53
+ connection_string_exports,
54
+ psql_exports,
55
+ set_context_exports,
56
+ checkout_exports,
57
+ link_exports,
58
+ init_exports,
59
+ data_api_exports,
60
+ functions_exports,
61
+ dev_exports,
62
+ diff_exports,
63
+ config_exports,
64
+ status_exports,
65
+ deploy_exports,
66
+ env_exports,
67
+ bucket_exports,
68
+ bootstrap_exports
66
69
  ];
70
+ //#endregion
71
+ export { commands_default as default };
@@ -1,135 +1,100 @@
1
- import { credentialInputs } from "../_shared/auth_selection.js";
1
+ import { __exportAll } from "../_virtual/_rolldown/runtime.js";
2
2
  import { closeAnalytics, sendError } from "../analytics.js";
3
+ import { credentialInputs } from "../_shared/auth_selection.js";
3
4
  import { detectAgent } from "../init/detect_agent.js";
4
5
  import { enrichResponse } from "../init/enrich_output.js";
5
6
  import { interactiveInit } from "../init/interactive.js";
6
7
  import { orchestrate } from "../init/orchestrate.js";
7
8
  import { routeDataStep } from "../init/route_command.js";
8
- import { STDOUT_FD, writeAllSync } from "../utils/write_sync.js";
9
- export const command = "init";
10
- export const describe = "Initialize a project with Neon using your AI coding assistant";
11
- export const builder = (yargs) => yargs
12
- .option("context-file", {
13
- hidden: true,
14
- })
15
- .option("agent", {
16
- alias: "a",
17
- type: "boolean",
18
- default: false,
19
- describe: "Enable agent/JSON mode (agent type is auto-detected).",
20
- })
21
- .option("data", {
22
- type: "string",
23
- describe: 'JSON object with a "step" field to route to a specific phase and phase-specific options.',
24
- })
25
- .option("skip-migrations", {
26
- type: "boolean",
27
- default: false,
28
- describe: "Skip the migrations phase.",
29
- })
30
- .option("preview", {
31
- type: "boolean",
32
- default: false,
33
- describe: "Enable preview features (e.g. project bootstrapping from templates).",
34
- })
35
- .strict(false);
9
+ import { writeAllSync } from "../utils/write_sync.js";
10
+ //#region src/commands/init.ts
11
+ var init_exports = /* @__PURE__ */ __exportAll({
12
+ builder: () => builder,
13
+ command: () => command,
14
+ describe: () => describe,
15
+ handler: () => handler
16
+ });
17
+ const command = "init";
18
+ const describe = "Initialize a project with Neon using your AI coding assistant";
19
+ const builder = (yargs) => yargs.option("context-file", { hidden: true }).option("agent", {
20
+ alias: "a",
21
+ type: "boolean",
22
+ default: false,
23
+ describe: "Enable agent/JSON mode (agent type is auto-detected)."
24
+ }).option("data", {
25
+ type: "string",
26
+ describe: "JSON object with a \"step\" field to route to a specific phase and phase-specific options."
27
+ }).option("skip-migrations", {
28
+ type: "boolean",
29
+ default: false,
30
+ describe: "Skip the migrations phase."
31
+ }).option("preview", {
32
+ type: "boolean",
33
+ default: false,
34
+ describe: "Enable preview features (e.g. project bootstrapping from templates)."
35
+ }).strict(false);
36
36
  /**
37
- * The agent-facing half of `neon init` speaks JSON, and it speaks it on **stdout**:
38
- * one object, no prefix, nothing else. `log.info` would prefix every line with
39
- * `INFO: ` and send it to stderr, which is right for a diagnostic and wrong for the
40
- * payload an agent is expected to parse.
41
- */
37
+ * The agent-facing half of `neon init` speaks JSON, and it speaks it on **stdout**:
38
+ * one object, no prefix, nothing else. `log.info` would prefix every line with
39
+ * `INFO: ` and send it to stderr, which is right for a diagnostic and wrong for the
40
+ * payload an agent is expected to parse.
41
+ */
42
42
  const writeAgentResponse = (result) => {
43
- writeAllSync(STDOUT_FD, `${JSON.stringify(enrichResponse(result), null, 2)}\n`);
43
+ writeAllSync(1, `${JSON.stringify(enrichResponse(result), null, 2)}\n`);
44
44
  };
45
45
  /**
46
- * A failure has to arrive in the shape the caller asked for. An agent parses stdout and
47
- * has no branch for "empty stdout, exit 1" — it cannot tell a broken credentials file
48
- * from a phase that legitimately produced nothing — so the error goes out as JSON too.
49
- */
46
+ * A failure has to arrive in the shape the caller asked for. An agent parses stdout and
47
+ * has no branch for "empty stdout, exit 1" — it cannot tell a broken credentials file
48
+ * from a phase that legitimately produced nothing — so the error goes out as JSON too.
49
+ */
50
50
  const writeAgentFailure = (error) => {
51
- writeAllSync(STDOUT_FD, `${JSON.stringify({ success: false, error: error.message }, null, 2)}\n`);
51
+ writeAllSync(1, `${JSON.stringify({
52
+ success: false,
53
+ error: error.message
54
+ }, null, 2)}\n`);
52
55
  };
53
56
  /** ` at position 12`, or nothing when the parser did not report one. */
54
57
  const parsePosition = (parseError) => {
55
- const message = parseError instanceof Error ? parseError.message : "";
56
- const at = message.match(/at position (\d+)/);
57
- return at === null ? "" : ` at position ${at[1]}`;
58
+ const at = (parseError instanceof Error ? parseError.message : "").match(/at position (\d+)/);
59
+ return at === null ? "" : ` at position ${at[1]}`;
58
60
  };
59
- export const handler = async (argv) => {
60
- // Auto-detect agent from environment. When --agent is explicitly passed,
61
- // always detect (the user asked for agent mode). Otherwise, require
62
- // non-TTY stdin to distinguish agent from human in terminal.
63
- //
64
- // Resolved before anything can fail, so that every failure this handler sees —
65
- // including the profile refusal — is reported in the shape the caller can read.
66
- // Failures raised by `ensureAuth` are not among them: it resolves credentials
67
- // above its own `init` skip, so an unknown profile, a contradictory
68
- // `--api-key`/`--profile` pair, and a damaged credentials file all report on
69
- // stderr before this runs.
70
- const agent = (argv.agent || !process.stdin.isTTY ? detectAgent() : null) ||
71
- undefined;
72
- const isAgentMode = argv.agent || agent !== undefined;
73
- try {
74
- // The init flow reads the default credentials directly and re-invokes the CLI as a
75
- // subprocess. It has no way to be told which profile to use, so honouring a selection
76
- // here is not possible yet — and silently running as the default account would be
77
- // worse than refusing, because naming an account is the entire job of the thing being
78
- // ignored.
79
- //
80
- // `NEON_PROFILE` counts just as much as the flag. Checking only the flag left the case
81
- // that is easier to hit by accident: a profile exported once into a shell then
82
- // silently disregarded by every `neon init` run in it.
83
- const selectedProfile = argv.profile?.trim() || credentialInputs().profileEnv.trim();
84
- if (selectedProfile) {
85
- const how = argv.profile?.trim()
86
- ? "--profile was passed, so"
87
- : "NEON_PROFILE is set, so";
88
- throw new Error(`${how} \`neon init\` would run as the default account instead of "${selectedProfile}", and it does not support profile selection yet. Run it without one, or set the project up with \`neon --profile ${selectedProfile} link\`.`);
89
- }
90
- // --data with a "step" field routes to the appropriate phase
91
- if (argv.data && isAgentMode) {
92
- let data;
93
- try {
94
- data = JSON.parse(argv.data);
95
- }
96
- catch (parseError) {
97
- // Neither the payload nor the parser's message may appear here. `--data`
98
- // carries whatever the caller put in it — a connection string, an API key —
99
- // and V8 quotes a window of the input around the syntax error, so both would
100
- // travel into the error message, onto stdout, and into `sendError`'s
101
- // analytics payload. `shared/cli-core/src/credentials.ts` discards the same
102
- // message for the same reason. The position is a number and says enough.
103
- throw new Error(`Invalid JSON in --data flag${parsePosition(parseError)}. Expected a JSON object.`);
104
- }
105
- if (typeof data.step === "string") {
106
- writeAgentResponse(await routeDataStep(data, agent));
107
- return;
108
- }
109
- }
110
- if (isAgentMode) {
111
- writeAgentResponse(await orchestrate({
112
- agent,
113
- skipMigrations: argv.skipMigrations,
114
- preview: argv.preview,
115
- }));
116
- }
117
- else {
118
- await interactiveInit({ preview: argv.preview });
119
- }
120
- }
121
- catch (error) {
122
- const cause = error instanceof Error ? error : new Error(String(error));
123
- if (isAgentMode) {
124
- // Agent mode answers and exits here, so nothing else will report this. Attribute
125
- // it to init and flush before exiting — `process.exit` drops in-flight events.
126
- sendError(cause, "NEON_INIT_FAILED");
127
- writeAgentFailure(cause);
128
- await closeAnalytics();
129
- process.exit(1);
130
- }
131
- // A human gets the top-level handler's single `ERROR: <message>` line on stderr, and
132
- // its `sendError`. Reporting here as well would file one failure as two events.
133
- throw cause;
134
- }
61
+ const handler = async (argv) => {
62
+ const agent = (argv.agent || !process.stdin.isTTY ? detectAgent() : null) || void 0;
63
+ const isAgentMode = argv.agent || agent !== void 0;
64
+ try {
65
+ const selectedProfile = argv.profile?.trim() || credentialInputs().profileEnv.trim();
66
+ if (selectedProfile) {
67
+ const how = argv.profile?.trim() ? "--profile was passed, so" : "NEON_PROFILE is set, so";
68
+ throw new Error(`${how} \`neon init\` would run as the default account instead of "${selectedProfile}", and it does not support profile selection yet. Run it without one, or set the project up with \`neon --profile ${selectedProfile} link\`.`);
69
+ }
70
+ if (argv.data && isAgentMode) {
71
+ let data;
72
+ try {
73
+ data = JSON.parse(argv.data);
74
+ } catch (parseError) {
75
+ throw new Error(`Invalid JSON in --data flag${parsePosition(parseError)}. Expected a JSON object.`);
76
+ }
77
+ if (typeof data.step === "string") {
78
+ writeAgentResponse(await routeDataStep(data, agent));
79
+ return;
80
+ }
81
+ }
82
+ if (isAgentMode) writeAgentResponse(await orchestrate({
83
+ agent,
84
+ skipMigrations: argv.skipMigrations,
85
+ preview: argv.preview
86
+ }));
87
+ else await interactiveInit({ preview: argv.preview });
88
+ } catch (error) {
89
+ const cause = error instanceof Error ? error : new Error(String(error));
90
+ if (isAgentMode) {
91
+ sendError(cause, "NEON_INIT_FAILED");
92
+ writeAgentFailure(cause);
93
+ await closeAnalytics();
94
+ process.exit(1);
95
+ }
96
+ throw cause;
97
+ }
135
98
  };
99
+ //#endregion
100
+ export { builder, command, describe, handler, init_exports };
@@ -1,65 +1,65 @@
1
+ import { __exportAll } from "../_virtual/_rolldown/runtime.js";
2
+ import { writer } from "../writer.js";
1
3
  import { fillSingleProject } from "../utils/enrichers.js";
2
4
  import { resolveConnectionUri, runInspectQuery } from "../utils/inspect_db.js";
3
- import { INSPECT_QUERIES, } from "../utils/inspect_queries.js";
4
- import { writer } from "../writer.js";
5
- export const command = "inspect";
6
- export const describe = "Inspect a database's health and configuration";
7
- export const aliases = ["inspection"];
5
+ import { INSPECT_QUERIES } from "../utils/inspect_queries.js";
6
+ //#region src/commands/inspect.ts
7
+ var inspect_exports = /* @__PURE__ */ __exportAll({
8
+ aliases: () => aliases,
9
+ builder: () => builder,
10
+ command: () => command,
11
+ describe: () => describe,
12
+ handler: () => handler
13
+ });
14
+ const command = "inspect";
15
+ const describe = "Inspect a database's health and configuration";
16
+ const aliases = ["inspection"];
8
17
  /**
9
- * `fillSingleProject` hits the API to auto-resolve a project. When the user
10
- * passes `--db-url` we bypass the Neon API entirely, so skip it.
11
- */
18
+ * `fillSingleProject` hits the API to auto-resolve a project. When the user
19
+ * passes `--db-url` we bypass the Neon API entirely, so skip it.
20
+ */
12
21
  const fillSingleProjectUnlessDbUrl = async (props) => {
13
- if (props.dbUrl) {
14
- return props;
15
- }
16
- return fillSingleProject(props);
22
+ if (props.dbUrl) return props;
23
+ return fillSingleProject(props);
17
24
  };
18
25
  const runSubcommand = async (name, props) => {
19
- const query = INSPECT_QUERIES[name];
20
- const connectionUri = props.dbUrl ?? (await resolveConnectionUri(props)).connectionUri;
21
- const rows = await runInspectQuery(connectionUri, query.sql, {
22
- requiresExtension: query.requiresExtension,
23
- });
24
- writer(props).end(rows, {
25
- fields: query.fields,
26
- emptyMessage: query.emptyMessage,
27
- });
26
+ const query = INSPECT_QUERIES[name];
27
+ const connectionUri = props.dbUrl ?? (await resolveConnectionUri(props)).connectionUri;
28
+ const rows = await runInspectQuery(connectionUri, query.sql, { requiresExtension: query.requiresExtension });
29
+ writer(props).end(rows, {
30
+ fields: query.fields,
31
+ emptyMessage: query.emptyMessage
32
+ });
28
33
  };
29
34
  const dbBuilder = (argv) => {
30
- let builder = argv
31
- .usage("$0 inspect db <sub-command> [options]")
32
- .options({
33
- "project-id": {
34
- describe: "Project ID",
35
- type: "string",
36
- },
37
- branch: {
38
- describe: "Branch ID or name",
39
- type: "string",
40
- },
41
- "database-name": {
42
- describe: "Database name",
43
- type: "string",
44
- },
45
- "role-name": {
46
- describe: "Role name",
47
- type: "string",
48
- },
49
- "db-url": {
50
- describe: "Inspect any Postgres via a connection string, bypassing the Neon API (project/branch resolution is skipped)",
51
- type: "string",
52
- },
53
- })
54
- .middleware(fillSingleProjectUnlessDbUrl);
55
- for (const name of Object.keys(INSPECT_QUERIES)) {
56
- builder = builder.command(name, INSPECT_QUERIES[name].describe, (yargs) => yargs, (args) => runSubcommand(name, args));
57
- }
58
- return builder;
35
+ let builder = argv.usage("$0 inspect db <sub-command> [options]").options({
36
+ "project-id": {
37
+ describe: "Project ID",
38
+ type: "string"
39
+ },
40
+ branch: {
41
+ describe: "Branch ID or name",
42
+ type: "string"
43
+ },
44
+ "database-name": {
45
+ describe: "Database name",
46
+ type: "string"
47
+ },
48
+ "role-name": {
49
+ describe: "Role name",
50
+ type: "string"
51
+ },
52
+ "db-url": {
53
+ describe: "Inspect any Postgres via a connection string, bypassing the Neon API (project/branch resolution is skipped)",
54
+ type: "string"
55
+ }
56
+ }).middleware(fillSingleProjectUnlessDbUrl);
57
+ for (const name of Object.keys(INSPECT_QUERIES)) builder = builder.command(name, INSPECT_QUERIES[name].describe, (yargs) => yargs, (args) => runSubcommand(name, args));
58
+ return builder;
59
59
  };
60
- export const builder = (argv) => argv
61
- .usage("$0 inspect <sub-command> [options]")
62
- .command("db", "Run a diagnostic query against a branch's Postgres", dbBuilder);
63
- export const handler = (args) => {
64
- return args;
60
+ const builder = (argv) => argv.usage("$0 inspect <sub-command> [options]").command("db", "Run a diagnostic query against a branch's Postgres", dbBuilder);
61
+ const handler = (args) => {
62
+ return args;
65
63
  };
64
+ //#endregion
65
+ export { aliases, builder, command, describe, handler, inspect_exports };