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.
Files changed (207) hide show
  1. package/README.md +70 -5
  2. package/dist/_chunks/auth_selection-DGgq6ifc.js +83 -0
  3. package/dist/_chunks/cmd_pipeline-CUbBO9U_.js +2818 -0
  4. package/dist/_chunks/credentials-MYdHdKah.js +188 -0
  5. package/dist/_chunks/env-NbA61JR3.js +585 -0
  6. package/dist/_chunks/env_services-Tz9G4JeT.js +531 -0
  7. package/dist/_chunks/paths-DMq0Lt7a.js +151 -0
  8. package/dist/_chunks/profiles-Ir29rqns.js +217 -0
  9. package/dist/_chunks/psql-DWH-kc69.js +2169 -0
  10. package/dist/_chunks/rolldown-runtime-D7D4PA-g.js +13 -0
  11. package/dist/_chunks/secure_file-BucZj4yQ.js +39 -0
  12. package/dist/analytics.js +163 -207
  13. package/dist/api.js +815 -758
  14. package/dist/auth.js +121 -141
  15. package/dist/auth_context.js +39 -53
  16. package/dist/cli.js +4 -7
  17. package/dist/commands/api.js +220 -250
  18. package/dist/commands/api_keys.js +251 -314
  19. package/dist/commands/auth.js +283 -328
  20. package/dist/commands/bootstrap.js +372 -437
  21. package/dist/commands/branches.js +304 -455
  22. package/dist/commands/bucket.js +374 -514
  23. package/dist/commands/checkout.js +213 -298
  24. package/dist/commands/config.js +573 -690
  25. package/dist/commands/connection_string.js +137 -165
  26. package/dist/commands/data_api.js +238 -260
  27. package/dist/commands/databases.js +67 -76
  28. package/dist/commands/deploy.js +31 -25
  29. package/dist/commands/dev.js +639 -719
  30. package/dist/commands/diff.js +156 -200
  31. package/dist/commands/env.js +255 -305
  32. package/dist/commands/functions.js +275 -355
  33. package/dist/commands/index.js +70 -65
  34. package/dist/commands/init.js +84 -119
  35. package/dist/commands/inspect.js +55 -55
  36. package/dist/commands/ip_allow.js +88 -120
  37. package/dist/commands/link.js +874 -1019
  38. package/dist/commands/logs.js +291 -0
  39. package/dist/commands/neon_auth.js +725 -933
  40. package/dist/commands/operations.js +34 -25
  41. package/dist/commands/orgs.js +28 -18
  42. package/dist/commands/profile.js +615 -846
  43. package/dist/commands/projects.js +313 -373
  44. package/dist/commands/psql.js +60 -58
  45. package/dist/commands/roles.js +55 -58
  46. package/dist/commands/schema_diff.js +87 -131
  47. package/dist/commands/set_context.js +34 -26
  48. package/dist/commands/snapshots.js +288 -413
  49. package/dist/commands/status.js +41 -37
  50. package/dist/commands/user.js +21 -10
  51. package/dist/commands/vpc_endpoints.js +85 -113
  52. package/dist/config.js +7 -6
  53. package/dist/config_format.js +50 -66
  54. package/dist/config_template.js +128 -157
  55. package/dist/context.js +183 -235
  56. package/dist/current_branch_fast_path.js +40 -49
  57. package/dist/dev/env.js +2 -446
  58. package/dist/dev/functions.js +54 -68
  59. package/dist/dev/inputs.js +46 -58
  60. package/dist/dev/runtime.js +135 -164
  61. package/dist/dev/websocket.js +766 -959
  62. package/dist/env.js +27 -33
  63. package/dist/env_file.js +118 -132
  64. package/dist/env_services.js +2 -51
  65. package/dist/errors.js +57 -68
  66. package/dist/functions_api.js +45 -43
  67. package/dist/help.js +189 -140
  68. package/dist/index.js +182 -257
  69. package/dist/init/agents.js +137 -118
  70. package/dist/init/auth.js +58 -68
  71. package/dist/init/bootstrap.js +325 -396
  72. package/dist/init/build_config.js +4 -2
  73. package/dist/init/detect_agent.js +56 -101
  74. package/dist/init/editors.js +35 -52
  75. package/dist/init/enrich_output.js +51 -66
  76. package/dist/init/extension.js +134 -171
  77. package/dist/init/inspect.js +179 -266
  78. package/dist/init/interactive.js +510 -622
  79. package/dist/init/neonctl.js +117 -168
  80. package/dist/init/orchestrate.js +157 -173
  81. package/dist/init/phases/auth.js +188 -202
  82. package/dist/init/phases/cleanup.js +23 -23
  83. package/dist/init/phases/db.js +251 -277
  84. package/dist/init/phases/getting_started.js +213 -223
  85. package/dist/init/phases/mcp.js +174 -224
  86. package/dist/init/phases/migrations.js +247 -248
  87. package/dist/init/phases/neon_auth.js +114 -133
  88. package/dist/init/phases/setup.js +546 -703
  89. package/dist/init/phases/skills.js +75 -86
  90. package/dist/init/phases/status.js +72 -67
  91. package/dist/init/resolve_context.js +102 -99
  92. package/dist/init/route_command.js +91 -98
  93. package/dist/init/skills.js +174 -218
  94. package/dist/init/vsix.js +77 -99
  95. package/dist/log.js +17 -16
  96. package/dist/neon_services.js +104 -129
  97. package/dist/parameters.gen.js +481 -471
  98. package/dist/pkg.js +17 -19
  99. package/dist/profile_keys.js +44 -47
  100. package/dist/psql/cli.js +44 -47
  101. package/dist/psql/command/cmd_cond.js +231 -406
  102. package/dist/psql/command/cmd_connect.js +557 -764
  103. package/dist/psql/command/cmd_copy.js +728 -984
  104. package/dist/psql/command/cmd_describe.js +1499 -1688
  105. package/dist/psql/command/cmd_format.js +733 -905
  106. package/dist/psql/command/cmd_io.js +2 -2193
  107. package/dist/psql/command/cmd_lo.js +297 -359
  108. package/dist/psql/command/cmd_meta.js +727 -878
  109. package/dist/psql/command/cmd_misc.js +138 -172
  110. package/dist/psql/command/cmd_pipeline.js +2 -1148
  111. package/dist/psql/command/cmd_restrict.js +119 -155
  112. package/dist/psql/command/cmd_show.js +529 -688
  113. package/dist/psql/command/dispatch.js +260 -325
  114. package/dist/psql/command/inputQueue.js +35 -33
  115. package/dist/psql/command/shared.js +49 -63
  116. package/dist/psql/complete/filenames.js +90 -133
  117. package/dist/psql/complete/index.js +59 -97
  118. package/dist/psql/complete/matcher.js +236 -300
  119. package/dist/psql/complete/psqlVars.js +218 -223
  120. package/dist/psql/complete/queries.js +159 -177
  121. package/dist/psql/complete/rules.js +1493 -2299
  122. package/dist/psql/core/common.js +2 -1253
  123. package/dist/psql/core/help.js +456 -546
  124. package/dist/psql/core/mainloop.js +692 -1303
  125. package/dist/psql/core/prompt.js +391 -408
  126. package/dist/psql/core/settings.js +429 -644
  127. package/dist/psql/core/sqlHelp.js +480 -554
  128. package/dist/psql/core/startup.js +2 -846
  129. package/dist/psql/core/syncVars.js +67 -110
  130. package/dist/psql/core/variables.js +156 -278
  131. package/dist/psql/describe/formatters.js +884 -1285
  132. package/dist/psql/describe/processNamePattern.js +173 -260
  133. package/dist/psql/describe/queries.js +1368 -2403
  134. package/dist/psql/describe/versionGate.js +32 -41
  135. package/dist/psql/index.js +2 -2030
  136. package/dist/psql/io/history.js +232 -271
  137. package/dist/psql/io/input.js +103 -108
  138. package/dist/psql/io/lineEditor/buffer.js +238 -319
  139. package/dist/psql/io/lineEditor/complete.js +135 -213
  140. package/dist/psql/io/lineEditor/filename.js +139 -148
  141. package/dist/psql/io/lineEditor/index.js +653 -870
  142. package/dist/psql/io/lineEditor/keymap.js +544 -702
  143. package/dist/psql/io/lineEditor/vt100.js +294 -341
  144. package/dist/psql/io/pgpass.js +158 -187
  145. package/dist/psql/io/pgservice.js +146 -183
  146. package/dist/psql/io/psqlrc.js +328 -403
  147. package/dist/psql/print/aligned.js +1020 -1683
  148. package/dist/psql/print/asciidoc.js +180 -214
  149. package/dist/psql/print/crosstab.js +281 -442
  150. package/dist/psql/print/csv.js +48 -70
  151. package/dist/psql/print/html.js +195 -226
  152. package/dist/psql/print/json.js +75 -88
  153. package/dist/psql/print/latex.js +291 -364
  154. package/dist/psql/print/pager.js +171 -242
  155. package/dist/psql/print/troff.js +194 -226
  156. package/dist/psql/print/unaligned.js +69 -95
  157. package/dist/psql/print/units.js +167 -169
  158. package/dist/psql/scanner/slash.js +428 -483
  159. package/dist/psql/scanner/sql.js +445 -889
  160. package/dist/psql/scanner/stringutils.js +309 -379
  161. package/dist/psql/types/index.js +8 -7
  162. package/dist/psql/types/scanner.js +25 -22
  163. package/dist/psql/wire/connection.js +2042 -2803
  164. package/dist/psql/wire/copy.js +84 -100
  165. package/dist/psql/wire/notify.js +39 -59
  166. package/dist/psql/wire/pipeline.js +305 -518
  167. package/dist/psql/wire/protocol.js +349 -417
  168. package/dist/psql/wire/sasl.js +180 -265
  169. package/dist/psql/wire/tls.js +400 -561
  170. package/dist/storage_api.js +115 -129
  171. package/dist/test_utils/fixtures.js +94 -113
  172. package/dist/test_utils/oauth_server.js +10 -7
  173. package/dist/test_utils/project_dir.js +33 -0
  174. package/dist/utils/ai_gateway_notice.js +131 -162
  175. package/dist/utils/api_enums.js +21 -28
  176. package/dist/utils/auth.js +10 -4
  177. package/dist/utils/branch_notice.js +20 -19
  178. package/dist/utils/branch_picker.js +83 -89
  179. package/dist/utils/cli_name.js +15 -12
  180. package/dist/utils/compute_units.js +20 -27
  181. package/dist/utils/config_diff.js +127 -158
  182. package/dist/utils/enrichers.js +95 -148
  183. package/dist/utils/esbuild.js +130 -189
  184. package/dist/utils/flags.js +35 -47
  185. package/dist/utils/formats.js +8 -15
  186. package/dist/utils/git_diff.js +69 -80
  187. package/dist/utils/inspect_db.js +101 -143
  188. package/dist/utils/inspect_queries.js +179 -142
  189. package/dist/utils/middlewares.js +39 -45
  190. package/dist/utils/openapi.js +87 -99
  191. package/dist/utils/package_manager.js +312 -110
  192. package/dist/utils/point_in_time.js +49 -53
  193. package/dist/utils/psql.js +89 -106
  194. package/dist/utils/service_picker.js +55 -58
  195. package/dist/utils/string.js +5 -5
  196. package/dist/utils/ui.js +38 -55
  197. package/dist/utils/write_sync.js +26 -35
  198. package/dist/utils/zip.js +4 -3
  199. package/dist/writer.js +67 -87
  200. package/package.json +11 -6
  201. package/dist/_shared/auth_selection.js +0 -86
  202. package/dist/_shared/credentials.js +0 -209
  203. package/dist/_shared/env-core/env.js +0 -558
  204. package/dist/_shared/env-core/reuse-secrets.js +0 -223
  205. package/dist/_shared/paths.js +0 -148
  206. package/dist/_shared/profiles.js +0 -276
  207. package/dist/_shared/secure_file.js +0 -43
@@ -1,52 +1,40 @@
1
+ //#region src/utils/flags.ts
1
2
  /**
2
- * Strict readers for flags whose value decides how much a credential can reach.
3
- *
4
- * These live apart from any one command because both `api-keys` and `profile create` mint
5
- * keys, and a lenient reading of a scope flag has the same consequence in either: the flag
6
- * reads as falsy, the scope check falls through, and an **account** key is minted instead of
7
- * the narrow one that was asked for. Two copies of that check is one copy too many.
8
- */
3
+ * Strict readers for flags whose value decides how much a credential can reach.
4
+ *
5
+ * These live apart from any one command because both `api-keys` and `profile create` mint
6
+ * keys, and a lenient reading of a scope flag has the same consequence in either: the flag
7
+ * reads as falsy, the scope check falls through, and an **account** key is minted instead of
8
+ * the narrow one that was asked for. Two copies of that check is one copy too many.
9
+ */
9
10
  /**
10
- * A flag is either absent, or exactly one non-empty string. Anything else is an error.
11
- *
12
- * - `--org-id ""` — an unset shell variable; empty string, which is falsy.
13
- * - `--no-org-id` — yargs boolean negation; `false`, which is falsy.
14
- * - `--org-id a --org-id b` — an array, which would reach the API as `a,b`.
15
- *
16
- * A misspelled flag never binds and cannot be seen here; `.strict()` rejects it. Anything
17
- * after a `--` terminator is handled by {@link noPassthrough}.
18
- */
19
- export const single = (name, { required = false } = {}) => (value) => {
20
- if (value === undefined)
21
- return undefined;
22
- if (Array.isArray(value)) {
23
- throw new Error(`--${name} was given more than once. Pass it at most once.`);
24
- }
25
- // `--no-x` is the negation form and yields `false`, so name it rather than telling
26
- // the user their value was empty when they never gave one.
27
- if (value === false) {
28
- throw new Error(required
29
- ? `--no-${name} is not valid: --${name} is required.`
30
- : `--no-${name} is not a valid way to skip --${name}. Omit the flag entirely.`);
31
- }
32
- if (typeof value !== "string" || value.trim() === "") {
33
- throw new Error(required
34
- ? `--${name} needs a value.`
35
- : `--${name} needs a value. Pass one, or omit the flag entirely.`);
36
- }
37
- return value;
11
+ * A flag is either absent, or exactly one non-empty string. Anything else is an error.
12
+ *
13
+ * - `--org-id ""` — an unset shell variable; empty string, which is falsy.
14
+ * - `--no-org-id` — yargs boolean negation; `false`, which is falsy.
15
+ * - `--org-id a --org-id b` — an array, which would reach the API as `a,b`.
16
+ *
17
+ * A misspelled flag never binds and cannot be seen here; `.strict()` rejects it. Anything
18
+ * after a `--` terminator is handled by {@link noPassthrough}.
19
+ */
20
+ const single = (name, { required = false } = {}) => (value) => {
21
+ if (value === void 0) return void 0;
22
+ if (Array.isArray(value)) throw new Error(`--${name} was given more than once. Pass it at most once.`);
23
+ if (value === false) throw new Error(required ? `--no-${name} is not valid: --${name} is required.` : `--no-${name} is not a valid way to skip --${name}. Omit the flag entirely.`);
24
+ if (typeof value !== "string" || value.trim() === "") throw new Error(required ? `--${name} needs a value.` : `--${name} needs a value. Pass one, or omit the flag entirely.`);
25
+ return value;
38
26
  };
39
27
  /**
40
- * Refuse arguments after a `--` terminator.
41
- *
42
- * The CLI sets `populate--`, so everything past `--` lands in `argv["--"]` where `.strict()`
43
- * never looks — `create --name x -- --project-id p` would parse cleanly and mint an account
44
- * key from a line that names the scope flag.
45
- */
46
- export const noPassthrough = (command) => (argv) => {
47
- const rest = argv["--"];
48
- if (Array.isArray(rest) && rest.length > 0) {
49
- throw new Error(`${command} takes no arguments after \`--\`, and options placed there are ignored rather than applied. Remove the \`--\`.`);
50
- }
51
- return true;
28
+ * Refuse arguments after a `--` terminator.
29
+ *
30
+ * The CLI sets `populate--`, so everything past `--` lands in `argv["--"]` where `.strict()`
31
+ * never looks — `create --name x -- --project-id p` would parse cleanly and mint an account
32
+ * key from a line that names the scope flag.
33
+ */
34
+ const noPassthrough = (command) => (argv) => {
35
+ const rest = argv["--"];
36
+ if (Array.isArray(rest) && rest.length > 0) throw new Error(`${command} takes no arguments after \`--\`, and options placed there are ignored rather than applied. Remove the \`--\`.`);
37
+ return true;
52
38
  };
39
+ //#endregion
40
+ export { noPassthrough, single };
@@ -1,18 +1,11 @@
1
+ //#region src/utils/formats.ts
1
2
  const HAIKU_REGEX = /^[a-z0-9]+-[a-z0-9]+-[a-z0-9]+$/;
2
- export const looksLikeBranchId = (branch) => branch.startsWith("br-") && HAIKU_REGEX.test(branch.substring(3));
3
+ const looksLikeBranchId = (branch) => branch.startsWith("br-") && HAIKU_REGEX.test(branch.substring(3));
3
4
  const LSN_REGEX = /^[a-fA-F0-9]{1,8}\/[a-fA-F0-9]{1,8}$/;
4
- export const looksLikeLSN = (lsn) => LSN_REGEX.test(lsn);
5
- export const looksLikeTimestamp = (timestamp) => {
6
- if (isNaN(Date.parse(timestamp)))
7
- return false;
8
- /**
9
- * @info
10
- * Check for ISO 8601/RFC 3339 format patterns
11
- * Must contain 'T' separator and end with 'Z' or timezone offset
12
- *
13
- * `Date.parse` aggressive parsing will attempt a date out of any string.
14
- * so if a branch name has a number, `Date.parse` will return a valid timestamp.
15
- */
16
- const iso8601Regex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?([+-]\d{2}:\d{2}|Z)$/;
17
- return iso8601Regex.test(timestamp);
5
+ const looksLikeLSN = (lsn) => LSN_REGEX.test(lsn);
6
+ const looksLikeTimestamp = (timestamp) => {
7
+ if (isNaN(Date.parse(timestamp))) return false;
8
+ return /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?([+-]\d{2}:\d{2}|Z)$/.test(timestamp);
18
9
  };
10
+ //#endregion
11
+ export { looksLikeBranchId, looksLikeLSN, looksLikeTimestamp };
@@ -1,90 +1,79 @@
1
1
  import chalk from "chalk";
2
2
  import { structuredPatch } from "diff";
3
+ //#region src/utils/git_diff.ts
3
4
  /**
4
- * Color palette for the rendered diff. When `color` is false every entry is the
5
- * identity function, so the exact same layout is emitted without ANSI codes
6
- * (for `--no-color`, non-TTY pipes, and stable test snapshots).
7
- */
5
+ * Color palette for the rendered diff. When `color` is false every entry is the
6
+ * identity function, so the exact same layout is emitted without ANSI codes
7
+ * (for `--no-color`, non-TTY pipes, and stable test snapshots).
8
+ */
8
9
  const palette = (color) => {
9
- const id = (s) => s;
10
- if (!color) {
11
- return {
12
- header: id,
13
- removedFile: id,
14
- addedFile: id,
15
- hunk: id,
16
- added: id,
17
- removed: id,
18
- noNewline: id,
19
- };
20
- }
21
- return {
22
- header: (s) => chalk.bold(s),
23
- removedFile: (s) => chalk.bold.red(s),
24
- addedFile: (s) => chalk.bold.green(s),
25
- hunk: (s) => chalk.cyan(s),
26
- added: (s) => chalk.green(s),
27
- removed: (s) => chalk.red(s),
28
- noNewline: (s) => chalk.dim(s),
29
- };
10
+ const id = (s) => s;
11
+ if (!color) return {
12
+ header: id,
13
+ removedFile: id,
14
+ addedFile: id,
15
+ hunk: id,
16
+ added: id,
17
+ removed: id,
18
+ noNewline: id
19
+ };
20
+ return {
21
+ header: (s) => chalk.bold(s),
22
+ removedFile: (s) => chalk.bold.red(s),
23
+ addedFile: (s) => chalk.bold.green(s),
24
+ hunk: (s) => chalk.cyan(s),
25
+ added: (s) => chalk.green(s),
26
+ removed: (s) => chalk.red(s),
27
+ noNewline: (s) => chalk.dim(s)
28
+ };
30
29
  };
31
30
  const branchLabel = (schema) => `${schema.branchName} (${schema.branchId})`;
32
31
  /**
33
- * Render a single database's schema comparison as a git-style unified diff.
34
- *
35
- * Pure: given the two schemas it computes hunks with `diff`'s `structuredPatch`
36
- * and lays them out like `git diff` — a bold header, red `---` / green `+++`
37
- * branch lines, cyan `@@` hunk headers, and green/red line bodies. Returns
38
- * `hasChanges: false` with empty text when the two schemas are identical.
39
- */
40
- export const renderDatabaseSchemaDiff = (diff, opts) => {
41
- const patch = structuredPatch(diff.database, diff.database, diff.before.sql, diff.after.sql, "", "", { context: 3 });
42
- if (patch.hunks.length === 0) {
43
- return { database: diff.database, hasChanges: false, text: "" };
44
- }
45
- const paint = palette(opts.color);
46
- const lines = [
47
- paint.header(`diff --neon database ${diff.database}`),
48
- paint.removedFile(`--- ${branchLabel(diff.before)}`),
49
- paint.addedFile(`+++ ${branchLabel(diff.after)}`),
50
- ];
51
- for (const hunk of patch.hunks) {
52
- lines.push(paint.hunk(`@@ -${hunk.oldStart},${hunk.oldLines} +${hunk.newStart},${hunk.newLines} @@`));
53
- for (const line of hunk.lines) {
54
- // `structuredPatch` prefixes every line: '+' added, '-' removed,
55
- // ' ' unchanged context, and '\' for the "No newline at end of file"
56
- // marker. Color the first three; dim the marker; leave context plain.
57
- if (line.startsWith("+")) {
58
- lines.push(paint.added(line));
59
- }
60
- else if (line.startsWith("-")) {
61
- lines.push(paint.removed(line));
62
- }
63
- else if (line.startsWith("\\")) {
64
- lines.push(paint.noNewline(line));
65
- }
66
- else {
67
- lines.push(line);
68
- }
69
- }
70
- }
71
- return {
72
- database: diff.database,
73
- hasChanges: true,
74
- text: lines.join("\n"),
75
- };
32
+ * Render a single database's schema comparison as a git-style unified diff.
33
+ *
34
+ * Pure: given the two schemas it computes hunks with `diff`'s `structuredPatch`
35
+ * and lays them out like `git diff` — a bold header, red `---` / green `+++`
36
+ * branch lines, cyan `@@` hunk headers, and green/red line bodies. Returns
37
+ * `hasChanges: false` with empty text when the two schemas are identical.
38
+ */
39
+ const renderDatabaseSchemaDiff = (diff, opts) => {
40
+ const patch = structuredPatch(diff.database, diff.database, diff.before.sql, diff.after.sql, "", "", { context: 3 });
41
+ if (patch.hunks.length === 0) return {
42
+ database: diff.database,
43
+ hasChanges: false,
44
+ text: ""
45
+ };
46
+ const paint = palette(opts.color);
47
+ const lines = [
48
+ paint.header(`diff --neon database ${diff.database}`),
49
+ paint.removedFile(`--- ${branchLabel(diff.before)}`),
50
+ paint.addedFile(`+++ ${branchLabel(diff.after)}`)
51
+ ];
52
+ for (const hunk of patch.hunks) {
53
+ lines.push(paint.hunk(`@@ -${hunk.oldStart},${hunk.oldLines} +${hunk.newStart},${hunk.newLines} @@`));
54
+ for (const line of hunk.lines) if (line.startsWith("+")) lines.push(paint.added(line));
55
+ else if (line.startsWith("-")) lines.push(paint.removed(line));
56
+ else if (line.startsWith("\\")) lines.push(paint.noNewline(line));
57
+ else lines.push(line);
58
+ }
59
+ return {
60
+ database: diff.database,
61
+ hasChanges: true,
62
+ text: lines.join("\n")
63
+ };
76
64
  };
77
65
  /**
78
- * Render every database's diff into one report, keeping only databases whose
79
- * schema actually changed. `hasChanges` is false when nothing changed across
80
- * all databases, letting the caller print a single "no differences" note.
81
- */
82
- export const renderSchemaDiffReport = (diffs, opts) => {
83
- const rendered = diffs.map((diff) => renderDatabaseSchemaDiff(diff, opts));
84
- const changed = rendered.filter((r) => r.hasChanges);
85
- return {
86
- hasChanges: changed.length > 0,
87
- text: changed.map((r) => r.text).join("\n\n"),
88
- changedDatabases: changed.map((r) => r.database),
89
- };
66
+ * Render every database's diff into one report, keeping only databases whose
67
+ * schema actually changed. `hasChanges` is false when nothing changed across
68
+ * all databases, letting the caller print a single "no differences" note.
69
+ */
70
+ const renderSchemaDiffReport = (diffs, opts) => {
71
+ const changed = diffs.map((diff) => renderDatabaseSchemaDiff(diff, opts)).filter((r) => r.hasChanges);
72
+ return {
73
+ hasChanges: changed.length > 0,
74
+ text: changed.map((r) => r.text).join("\n\n"),
75
+ changedDatabases: changed.map((r) => r.database)
76
+ };
90
77
  };
78
+ //#endregion
79
+ export { renderDatabaseSchemaDiff, renderSchemaDiffReport };
@@ -1,153 +1,111 @@
1
- import { parseConnectionUri } from "../psql/index.js";
2
- import { PgConnection } from "../psql/wire/connection.js";
3
1
  import { EndpointType } from "./api_enums.js";
4
2
  import { branchIdFromProps } from "./enrichers.js";
5
3
  import { parsePITBranch } from "./point_in_time.js";
6
- export const SSL_MODES = [
7
- "require",
8
- "verify-ca",
9
- "verify-full",
10
- "omit",
4
+ import { PgConnection } from "../psql/wire/connection.js";
5
+ import { o as parseConnectionUri } from "../_chunks/psql-DWH-kc69.js";
6
+ //#region src/utils/inspect_db.ts
7
+ const SSL_MODES = [
8
+ "require",
9
+ "verify-ca",
10
+ "verify-full",
11
+ "omit"
11
12
  ];
12
13
  /**
13
- * Resolve a branch's live Postgres connection details via the Neon API
14
- * (endpoint → role → password → database → URL, honoring point-in-time,
15
- * pooling, prisma tuning, and SSL mode). Mirrors how `connection-string`
16
- * resolves a branch so `inspect db` connects the same way.
17
- */
18
- export const resolveConnectionUri = async (props) => {
19
- const projectId = props.projectId;
20
- const parsedPIT = props.branch
21
- ? parsePITBranch(props.branch)
22
- : { tag: "head", branch: "" };
23
- if (props.branch) {
24
- props.branch = parsedPIT.branch;
25
- }
26
- const branchId = await branchIdFromProps(props);
27
- const { data: { endpoints }, } = await props.apiClient.listProjectBranchEndpoints(projectId, branchId);
28
- const matchEndpointType = props.endpointType ?? EndpointType.ReadWrite;
29
- let endpoint = endpoints.find((e) => e.type === matchEndpointType);
30
- if (!endpoint && props.endpointType == null) {
31
- endpoint = endpoints[0];
32
- }
33
- if (!endpoint) {
34
- throw new Error(`No ${props.endpointType ?? ""} endpoint found for the branch: ${branchId}`);
35
- }
36
- const role = props.roleName ||
37
- (await props.apiClient
38
- .listProjectBranchRoles(projectId, branchId)
39
- .then(({ data }) => {
40
- if (data.roles.length === 0) {
41
- throw new Error(`No roles found for the branch: ${branchId}`);
42
- }
43
- if (data.roles.length === 1) {
44
- return data.roles[0].name;
45
- }
46
- throw new Error(`Multiple roles found for the branch, please provide one with the --role-name option: ${data.roles
47
- .map((r) => r.name)
48
- .join(", ")}`);
49
- }));
50
- const { data: { databases: branchDatabases }, } = await props.apiClient.listProjectBranchDatabases(projectId, branchId);
51
- const database = props.databaseName ||
52
- (() => {
53
- if (branchDatabases.length === 0) {
54
- throw new Error(`No databases found for the branch: ${branchId}`);
55
- }
56
- if (branchDatabases.length === 1) {
57
- return branchDatabases[0].name;
58
- }
59
- throw new Error(`Multiple databases found for the branch, please provide one with the --database-name option: ${branchDatabases
60
- .map((d) => d.name)
61
- .join(", ")}`);
62
- })();
63
- if (!branchDatabases.find((d) => d.name === database)) {
64
- throw new Error(`Database not found: ${database}`);
65
- }
66
- const { data: { password }, } = await props.apiClient.getProjectBranchRolePassword(props.projectId, endpoint.branch_id, role);
67
- let host = props.pooled
68
- ? endpoint.host.replace(endpoint.id, `${endpoint.id}-pooler`)
69
- : endpoint.host;
70
- if (parsedPIT.tag !== "head") {
71
- host = endpoint.host.replace(endpoint.id, endpoint.branch_id);
72
- }
73
- const connectionString = new URL(`postgresql://${host}`);
74
- connectionString.pathname = database;
75
- connectionString.username = role;
76
- connectionString.password = password;
77
- if (props.prisma) {
78
- connectionString.searchParams.set("connect_timeout", "30");
79
- if (props.pooled) {
80
- connectionString.searchParams.set("pool_timeout", "30");
81
- connectionString.searchParams.set("pgbouncer", "true");
82
- }
83
- }
84
- const ssl = props.ssl ?? "require";
85
- if (ssl !== "omit") {
86
- connectionString.searchParams.set("sslmode", ssl);
87
- connectionString.searchParams.set("channel_binding", "require");
88
- }
89
- if (parsedPIT.tag === "lsn") {
90
- connectionString.searchParams.set("options", `neon_lsn:${parsedPIT.lsn}`);
91
- }
92
- else if (parsedPIT.tag === "timestamp") {
93
- connectionString.searchParams.set("options", `neon_timestamp:${parsedPIT.timestamp}`);
94
- }
95
- return {
96
- connectionUri: connectionString.toString(),
97
- host,
98
- role,
99
- password,
100
- database,
101
- options: connectionString.searchParams.toString(),
102
- };
14
+ * Resolve a branch's live Postgres connection details via the Neon API
15
+ * (endpoint → role → password → database → URL, honoring point-in-time,
16
+ * pooling, prisma tuning, and SSL mode). Mirrors how `connection-string`
17
+ * resolves a branch so `inspect db` connects the same way.
18
+ */
19
+ const resolveConnectionUri = async (props) => {
20
+ const projectId = props.projectId;
21
+ const parsedPIT = props.branch ? parsePITBranch(props.branch) : {
22
+ tag: "head",
23
+ branch: ""
24
+ };
25
+ if (props.branch) props.branch = parsedPIT.branch;
26
+ const branchId = await branchIdFromProps(props);
27
+ const { data: { endpoints } } = await props.apiClient.listProjectBranchEndpoints(projectId, branchId);
28
+ const matchEndpointType = props.endpointType ?? EndpointType.ReadWrite;
29
+ let endpoint = endpoints.find((e) => e.type === matchEndpointType);
30
+ if (!endpoint && props.endpointType == null) endpoint = endpoints[0];
31
+ if (!endpoint) throw new Error(`No ${props.endpointType ?? ""} endpoint found for the branch: ${branchId}`);
32
+ const role = props.roleName || await props.apiClient.listProjectBranchRoles(projectId, branchId).then(({ data }) => {
33
+ if (data.roles.length === 0) throw new Error(`No roles found for the branch: ${branchId}`);
34
+ if (data.roles.length === 1) return data.roles[0].name;
35
+ throw new Error(`Multiple roles found for the branch, please provide one with the --role-name option: ${data.roles.map((r) => r.name).join(", ")}`);
36
+ });
37
+ const { data: { databases: branchDatabases } } = await props.apiClient.listProjectBranchDatabases(projectId, branchId);
38
+ const database = props.databaseName || (() => {
39
+ if (branchDatabases.length === 0) throw new Error(`No databases found for the branch: ${branchId}`);
40
+ if (branchDatabases.length === 1) return branchDatabases[0].name;
41
+ throw new Error(`Multiple databases found for the branch, please provide one with the --database-name option: ${branchDatabases.map((d) => d.name).join(", ")}`);
42
+ })();
43
+ if (!branchDatabases.find((d) => d.name === database)) throw new Error(`Database not found: ${database}`);
44
+ const { data: { password } } = await props.apiClient.getProjectBranchRolePassword(props.projectId, endpoint.branch_id, role);
45
+ let host = props.pooled ? endpoint.host.replace(endpoint.id, `${endpoint.id}-pooler`) : endpoint.host;
46
+ if (parsedPIT.tag !== "head") host = endpoint.host.replace(endpoint.id, endpoint.branch_id);
47
+ const connectionString = new URL(`postgresql://${host}`);
48
+ connectionString.pathname = database;
49
+ connectionString.username = role;
50
+ connectionString.password = password;
51
+ if (props.prisma) {
52
+ connectionString.searchParams.set("connect_timeout", "30");
53
+ if (props.pooled) {
54
+ connectionString.searchParams.set("pool_timeout", "30");
55
+ connectionString.searchParams.set("pgbouncer", "true");
56
+ }
57
+ }
58
+ const ssl = props.ssl ?? "require";
59
+ if (ssl !== "omit") {
60
+ connectionString.searchParams.set("sslmode", ssl);
61
+ connectionString.searchParams.set("channel_binding", "require");
62
+ }
63
+ if (parsedPIT.tag === "lsn") connectionString.searchParams.set("options", `neon_lsn:${parsedPIT.lsn}`);
64
+ else if (parsedPIT.tag === "timestamp") connectionString.searchParams.set("options", `neon_timestamp:${parsedPIT.timestamp}`);
65
+ return {
66
+ connectionUri: connectionString.toString(),
67
+ host,
68
+ role,
69
+ password,
70
+ database,
71
+ options: connectionString.searchParams.toString()
72
+ };
103
73
  };
104
74
  const rowsFrom = (result) => {
105
- const names = result.fields.map((f) => f.name);
106
- return result.rows.map((row) => {
107
- const obj = {};
108
- names.forEach((name, i) => {
109
- obj[name] = row[i];
110
- });
111
- return obj;
112
- });
75
+ const names = result.fields.map((f) => f.name);
76
+ return result.rows.map((row) => {
77
+ const obj = {};
78
+ names.forEach((name, i) => {
79
+ obj[name] = row[i];
80
+ });
81
+ return obj;
82
+ });
113
83
  };
114
84
  /**
115
- * Connect to `connectionUri` with the embedded wire client, run a single
116
- * read-only `sql`, and return the rows as objects keyed by column name (so the
117
- * shared `writer` can render them by field). The connection is always closed,
118
- * even on error.
119
- */
120
- export const runInspectQuery = async (connectionUri, sql, options = {}) => {
121
- const opts = parseConnectionUri(connectionUri);
122
- let connection;
123
- try {
124
- connection = await PgConnection.connect(opts);
125
- }
126
- catch (err) {
127
- // Give the failure a Postgres-specific message. The raw socket error
128
- // (e.g. ECONNREFUSED) would otherwise be mislabeled by the top-level
129
- // `isNetworkError` handler as a "Could not reach the Neon API" hint —
130
- // misleading for `inspect db`, which talks to Postgres, not the API.
131
- // We intentionally do not chain `cause` so that classifier can't match
132
- // the socket `code`; the underlying reason is preserved in the message.
133
- const reason = err instanceof Error ? err.message : String(err);
134
- throw new Error(`Could not connect to Postgres at ${opts.host}:${opts.port}: ${reason}`);
135
- }
136
- try {
137
- const ext = options.requiresExtension;
138
- if (ext) {
139
- // `ext` is an internal constant from INSPECT_QUERIES, never user input,
140
- // so interpolating it into the literal is safe.
141
- const check = await connection.query(`SELECT 1 FROM pg_extension WHERE extname = '${ext}';`);
142
- if (check.rows.length === 0) {
143
- throw new Error(`This query needs the "${ext}" extension, which is not installed. ` +
144
- `Enable it with: CREATE EXTENSION ${ext};`);
145
- }
146
- }
147
- const result = await connection.query(sql);
148
- return rowsFrom(result);
149
- }
150
- finally {
151
- await connection.close();
152
- }
85
+ * Connect to `connectionUri` with the embedded wire client, run a single
86
+ * read-only `sql`, and return the rows as objects keyed by column name (so the
87
+ * shared `writer` can render them by field). The connection is always closed,
88
+ * even on error.
89
+ */
90
+ const runInspectQuery = async (connectionUri, sql, options = {}) => {
91
+ const opts = parseConnectionUri(connectionUri);
92
+ let connection;
93
+ try {
94
+ connection = await PgConnection.connect(opts);
95
+ } catch (err) {
96
+ const reason = err instanceof Error ? err.message : String(err);
97
+ throw new Error(`Could not connect to Postgres at ${opts.host}:${opts.port}: ${reason}`);
98
+ }
99
+ try {
100
+ const ext = options.requiresExtension;
101
+ if (ext) {
102
+ if ((await connection.query(`SELECT 1 FROM pg_extension WHERE extname = '${ext}';`)).rows.length === 0) throw new Error(`This query needs the "${ext}" extension, which is not installed. Enable it with: CREATE EXTENSION ${ext};`);
103
+ }
104
+ const result = await connection.query(sql);
105
+ return rowsFrom(result);
106
+ } finally {
107
+ await connection.close();
108
+ }
153
109
  };
110
+ //#endregion
111
+ export { SSL_MODES, resolveConnectionUri, runInspectQuery };