Repository navigation
Add --json flag to db connect - #68
Merged
Merged
Conversation
- Add --json option to output connectionString, branch, pooled, host, port as JSON - Fix Zod schema: parent_lsn/parent_timestamp on branches were required but the Neon API omits them (not null) for branches with no parent, causing validation to fail on every branch list/inspect call - Fix Zod schema: endpoint.port was required but the Neon API doesn't always return it; default to 5432 (standard Postgres port) when absent Fixes IN3PIRE#60
TrivCodez
approved these changes
Jul 22, 2026
TrivCodez
left a comment
Contributor
There was a problem hiding this comment.
Clean implementation. Zod schema fixes (optional parent_lsn/parent_timestamp, optional port) are necessary and correct. Suggestion: port in JSON output emits null when absent — consider defaulting to 5432 for consistency with the existing pooled fallback in getConnectionString(). Not a blocker. Good to merge.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
--jsonflag todb connect, following the same pattern already used indb branch inspect --json.Fixes #60
Changes
src/commands/connect.ts.option("--json", "Output as JSON"){ connectionString, branch, pooled, host, port }instead of the plain-text/spinner outputhost/portare derived by parsing the connection string withnew URL(), sincegetConnectionString()only returns a single stringsrc/lib/neon-api.ts(pre-existing bug fixes, found while testing)parent_lsn/parent_timestampon branches were typed as required-or-null in the Zod schema, but the real API omits these fields entirely for branches with no parent (e.g. the root/default branch) rather than sendingnull. This brokelistBranches— and by extensionbranch list,branch inspect, andconnect— for any project whose default branch has no parent. Made both fields.optional().endpoint.portwas required as anumber, but the real API doesn't always return it. Made it optional and defaulted to5432(standard Postgres port) ingetConnectionString, matching the existing fallback already used for pooled connections.src/commands/endpoint.tsendpoint listtable rendering to handle the now-optionalportfield (defaults to5432for display).Why the schema fixes are included here
Both were blocking issues discovered while testing
connect --jsonagainst a real project —listBranches/getConnectionStringwould throw a Zod validation error before the--jsoncode path ever ran. They're narrow, single-purpose fixes (no new API calls, no behavior change beyond accepting valid API responses that were previously rejected), so I kept them in this PR rather than opening a separate one. Happy to split them out if preferred.Testing
Tested against a live Neon project:
Both produce valid JSON with correct
branchandpooledvalues, and pooled/non-pooled requests return distinct hosts as expected.npm run buildpasses with no errors.Not in scope (follow-up needed)
While testing, I also found that connection strings generated by
getConnectionString()(used byconnect,shell,query,seed,ci,reset,export, andbranch diff/merge) embed a literalundefinedpassword, becauselistRoles()doesn't return role passwords — Neon's API requires a separatereveal_passwordcall per role. This is a larger, higher-severity issue affecting many commands, so I'm opening it separately rather than folding it into this PR.