Skip to content

refactor: introduce Client type, remove TUI from library, eliminate init() side effects#361

Open
zeroshade wants to merge 43 commits intomainfrom
feat/library-api-refactor
Open

refactor: introduce Client type, remove TUI from library, eliminate init() side effects#361
zeroshade wants to merge 43 commits intomainfrom
feat/library-api-refactor

Conversation

@zeroshade
Copy link
Copy Markdown
Member

Summary

This branch refactors the dbc package from a package-global, init()-heavy design to a clean library API:

  • New Client type with functional options (WithHTTPClient, WithRegistries, WithBaseURL, WithUserAgent, WithCredential, WithAuthFromFilesystem) replacing package-level singletons
  • TUI dependencies removed from root dbc and config packages — import "github.com/columnar-tech/dbc" now pulls zero bubbletea/lipgloss/bubbles transitive deps; widgets moved to cmd/dbc
  • init() side effects eliminated — no disk writes, no http.DefaultClient mutation at import time; lazy sync.Once-based setup only triggered on first network call
  • Old APIs deprecated (GetDriverList, DefaultClient) with forwarding shims for backward compatibility; CLI migrated to use Client internally
  • 27 iterative fix commits addressing resource leaks, nil panics, race conditions, double-closes, and request-reuse violations surfaced by automated branch review

New Client API

c, err := dbc.NewClient(
    dbc.WithBaseURL("https://my-registry.example.com"),
    dbc.WithHTTPClient(myHTTPClient),
)
drivers, err := c.Search("adbc-driver-")
manifest, err := c.Install(cfg, "adbc-driver-postgresql")

Testing

All tests pass (go test ./...). Branch reviewed and passed by automated code review (27 commits, roborev job 1027).

Break config->dbc import cycle by moving ToPackageInfo() helper to cmd/dbc,
allowing the dbc package to import config without circular dependency.
Add thin Client wrappers for GetConfig, ListInstalled, GetDriver, CreateManifest.
- Delete delegates.go (moved to cmd/dbc in T3)
- Delete file_progress_model.go (moved to cmd/dbc in T3)
- Dependency tree now CLEAN: zero charm.land packages in library
- Library consumers no longer pull bubbletea/lipgloss/bubbles
- All tests pass (6 packages)
- Build succeeds with no errors

Fixes: Library API refactor goal of clean dependency tree for consumers
- Fix infinite recursion in tui_driver_list.go String() method by converting to underlying semver.Version type
- Remove dead code from drivers.go: package-level registries variable, getDriverListFromIndex function, and getDrivers sync.OnceValues
- Remove DBC_BASE_URL override block from ensureSetup() since registries is now dead
- Update GetDriverList() to respect DBC_BASE_URL environment variable by passing WithBaseURL option to NewClient
- Remove unused registryErrors fields from docs.go and info.go structs
- Add doc comments to all exported Client API functions and methods
- Remove unused yaml import from drivers.go
… overwrite in test, add sync.Once to getDriverRegistry lazy init
… client init with sync.Once in initDBCClient
…equest in uaRoundTripper before mutating headers
@zeroshade zeroshade force-pushed the feat/library-api-refactor branch from cde3419 to fcb2c19 Compare April 17, 2026 17:56
…eturns VersionInfo, deduplicate test boilerplate
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.

1 participant