Skip to content

refactor(cli/db): extract shared helpers and quickstart snippets#88

Merged
jamie-at-bunny merged 4 commits into
mainfrom
refactor/cli-db-dedupe-helpers
Jun 4, 2026
Merged

refactor(cli/db): extract shared helpers and quickstart snippets#88
jamie-at-bunny merged 4 commits into
mainfrom
refactor/cli-db-dedupe-helpers

Conversation

@jamie-at-bunny
Copy link
Copy Markdown
Member

No description provided.

@bogdan-at-bunny
Copy link
Copy Markdown

@codex review

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jun 4, 2026

🦋 Changeset detected

Latest commit: 5f57e62

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@bunny.net/cli Patch
@bunny.net/cli-linux-x64 Patch
@bunny.net/cli-linux-arm64 Patch
@bunny.net/cli-darwin-x64 Patch
@bunny.net/cli-darwin-arm64 Patch
@bunny.net/cli-windows-x64 Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 54eede367d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/cli/src/commands/db/link.ts Outdated
@jamie-at-bunny
Copy link
Copy Markdown
Member Author

@greptile-apps review

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Jun 4, 2026

Greptile Summary

This PR extracts duplicated database-command infrastructure into two new shared modules (api.ts for typed API wrappers and quickstart-snippets.ts for per-language connection code), moves the DB_PAGE_SIZE and TOKEN_TTL_MINUTES constants into constants.ts, and fixes cancelled interactive prompts in db link, db regions update, scripts link, and scripts env remove to throw UserError (exit 1 + proper --output json payload) instead of silently returning.

  • db/api.ts — new shared layer with fetchDatabase, fetchAllDatabases, fetchRegionConfig, fetchDatabaseWithRegions, generateToken, tokenExpiryFromNow, fetchLiveStatus, liveStatusLabel, regionNameMap, and liveMainRegion; consumed by ten command files to eliminate repeated pagination loops and error-checking boilerplate.
  • db/quickstart-snippets.ts — language snippet templates extracted from quickstart.ts; env-var names now reference the ENV_DATABASE_URL / ENV_DATABASE_AUTH_TOKEN constants rather than being inlined as strings.
  • Cancellation exit-code fix — four commands changed from logger.log + return/process.exit(1) to throw new UserError(…), ensuring a consistent non-zero exit and a machine-readable JSON error payload on prompt cancellation.

Confidence Score: 5/5

Safe to merge — all changes are mechanical extractions of existing logic into shared helpers with no functional regressions.

Every API call and error-handling path in the new shared helpers is a direct lift of existing, already-shipping code. The cancellation change consistently replaces logger+return/exit patterns with throw UserError across all affected files, and the token/region refactors preserve the same Promise.all parallelism as before. The only findings are two unused imports and a minor inaccuracy in the changeset description — none affect runtime behavior.

shell.ts and studio.ts each have an unused TOKEN_TTL_MINUTES import that can be trimmed.

Important Files Changed

Filename Overview
packages/cli/src/commands/db/api.ts New shared API helper module; clean extraction with typed wrappers, proper pagination, parallel fetching, and consistent error-throwing. No issues found.
packages/cli/src/commands/db/quickstart-snippets.ts Language snippet templates extracted from quickstart.ts; env var names now sourced from shared constants. Clean extraction.
packages/cli/src/commands/db/shell.ts Switched to shared generateToken/tokenExpiryFromNow helpers; TOKEN_TTL_MINUTES is now an unused import after the refactor.
packages/cli/src/commands/db/studio.ts Same pattern as shell.ts; TOKEN_TTL_MINUTES import is unused after delegating to tokenExpiryFromNow().
packages/cli/src/commands/db/resolve-db.ts Pagination loop replaced by fetchAllDatabases; process.exit(1) replaced by throw new UserError for proper JSON error output. Clean improvement.
packages/cli/src/commands/db/regions/update.ts Both cancellation paths (primary + replica prompts) now throw UserError; fetchDatabaseWithRegions replaces manual parallel fetch. Correct.
packages/cli/src/commands/scripts/link.ts Cancellation changed from logger.log+return (exit 0) to throw UserError (exit 1 + JSON). Correct fix; changeset description slightly misrepresents prior behavior.
packages/cli/src/commands/scripts/env/remove.ts Cancellation now throws UserError for consistent non-zero exit and JSON output.
AGENTS.md File listing updated to include api.ts, quickstart-snippets.ts, and the previously unlisted studio.ts. Aligns with CLAUDE.md documentation requirements.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    subgraph commands["Command files (consumers)"]
        C1[create.ts]
        C2[delete.ts]
        C3[link.ts]
        C4[list.ts]
        C5[show.ts]
        C6[shell.ts]
        C7[studio.ts]
        C8[quickstart.ts]
        C9[regions/add.ts]
        C10[regions/list.ts]
        C11[regions/remove.ts]
        C12[regions/update.ts]
        C13[tokens/create.ts]
        C14[tokens/invalidate.ts]
        RDB[resolve-db.ts]
    end

    subgraph shared["New shared modules"]
        API[api.ts\nfetchDatabase / fetchAllDatabases\nfetchRegionConfig / fetchDatabaseWithRegions\ngenerateToken / tokenExpiryFromNow\nfetchLiveStatus / liveStatusLabel\nliveMainRegion / regionNameMap]
        SNIP[quickstart-snippets.ts\ngetSnippet / QUICKSTART_LANGUAGES]
        CONST[constants.ts\nDB_PAGE_SIZE / TOKEN_TTL_MINUTES]
    end

    C1 & C2 & C3 & C4 & C5 & C6 & C7 --> API
    C8 --> API
    C8 --> SNIP
    C9 & C10 & C11 & C12 --> API
    C13 & C14 --> API
    RDB --> API
    API --> CONST
Loading

Fix All in Claude Code

Reviews (2): Last reviewed commit: "docs: agents" | Re-trigger Greptile

Comment thread packages/cli/src/commands/db/api.ts
@jamie-at-bunny jamie-at-bunny merged commit aa0f44d into main Jun 4, 2026
1 check passed
@jamie-at-bunny jamie-at-bunny deleted the refactor/cli-db-dedupe-helpers branch June 4, 2026 12:12
@github-actions github-actions Bot mentioned this pull request Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants