Skip to content

Commit da88e4e

Browse files
tianzhouclaude
andauthored
feat: add REST API endpoints for data sources (#125)
* feat: add REST API endpoints for data sources Add RESTful API with GET endpoints for querying database data sources: - GET /api/sources - List all configured data sources - GET /api/sources/{source-id} - Get specific data source details Implementation details: - OpenAPI 3.0 spec-first approach with openapi-typescript for type generation - Exposes source configuration (type, host, port, database, user, readonly, max_rows) - Includes SSH tunnel configuration (host, port, user) without credentials - Properly excludes sensitive fields (passwords, SSH keys) - Returns 404 for non-existent sources - Indicates default source with is_default flag Technical changes: - Added OpenAPI spec at src/api/openapi.yaml - Implemented route handlers in src/api/sources.ts - Extended ConnectorManager to store and expose SourceConfig objects - Integrated routes into existing Express HTTP server - Added generate:api-types script to build process 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * test: add integration tests for REST API endpoints Add comprehensive integration tests for data sources API endpoints: - GET /api/sources - list all sources - GET /api/sources/{source-id} - get specific source Test coverage: - Validates response format matches OpenAPI schema - Tests multiple data sources with different configurations - Verifies is_default flag for first source - Confirms readonly and max_rows settings are exposed - Tests 404 error handling for non-existent sources - Validates sensitive fields (passwords, SSH credentials) are excluded - Tests URL-encoded source IDs and special characters Technical details: - Sets up Express server on test port (13579) - Uses three in-memory SQLite databases for testing - 14 tests passing, 1 skipped (SSH tunnel test) - Clean setup and teardown of server and database connections 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * refactor: address code review feedback for REST API Fix 5 issues identified in PR review: 1. Path parameter naming consistency - Changed OpenAPI spec from {source-id} to {sourceId} - Now matches Express route parameter naming convention 2. Remove unused variable - Removed unused sourceIds in listSources function - Cleaner code with no dead variables 3. Simplify redundant null checks - Removed double validation in getSource handler - Single check for sourceConfig is sufficient - Improves code clarity and reduces duplication 4. Fix inconsistent null safety - Removed .filter(Boolean) from getAllSourceConfigs - Non-null assertion is safe due to synchronized Maps - sourceIds and sourceConfigs are always in sync 5. Add type field validation - Replace implicit type assumption with explicit check - Throws clear error if type is missing - Added comment explaining why type is guaranteed All integration tests passing (14 tests). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * test: fix issues in integration tests Address followup code review feedback: 1. Fix grammar error - Changed "should include all database type" to "should include database type" - Grammatically correct test description 2. Remove incomplete SSH test section - Removed unused variables: managerWithSSH, appWithSSH, serverWithSSH - Removed sourcesWithSSH constant - Eliminated always-false conditions in cleanup code - Removed non-functional beforeAll/afterAll hooks - Removed skipped SSH tunnel test The SSH test section had setup/teardown code but no actual implementation, causing undefined variable warnings. Removed entirely until proper SSH test infrastructure is available. Test results: 14 tests passing (previously 14 passing + 1 skipped) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
1 parent b1cda56 commit da88e4e

File tree

8 files changed

+963
-10
lines changed

8 files changed

+963
-10
lines changed

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
"README.md"
1818
],
1919
"scripts": {
20-
"build": "tsup && cd frontend && pnpm run build",
21-
"build:backend": "tsup",
20+
"build": "pnpm run generate:api-types && tsup && cd frontend && pnpm run build",
21+
"build:backend": "pnpm run generate:api-types && tsup",
2222
"build:frontend": "cd frontend && pnpm run build",
2323
"start": "node dist/index.js",
2424
"dev": "concurrently --kill-others \"pnpm run dev:backend\" \"pnpm run dev:frontend\"",
2525
"dev:backend": "NODE_ENV=development tsx src/index.ts --demo --transport=http",
2626
"dev:frontend": "cd frontend && pnpm run dev",
2727
"crossdev": "cross-env NODE_ENV=development tsx src/index.ts",
28+
"generate:api-types": "openapi-typescript src/api/openapi.yaml -o src/api/openapi.d.ts",
2829
"test": "vitest run",
2930
"test:unit": "vitest run --project unit",
3031
"test:watch": "vitest",
@@ -61,6 +62,7 @@
6162
"@types/ssh2": "^1.15.5",
6263
"concurrently": "^9.2.1",
6364
"cross-env": "^7.0.3",
65+
"openapi-typescript": "^7.10.1",
6466
"prettier": "^3.5.3",
6567
"testcontainers": "^11.0.3",
6668
"ts-node": "^10.9.2",

0 commit comments

Comments
 (0)