-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Introduced project management & Offline Mode #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a3d1043
feat: implement project management handlers and refactor configuratio…
Yashh56 6407a6c
feat: add project management features including project list, detail …
Yashh56 e7ea0d4
feat: implement project retrieval by database ID and auto-sync schema…
Yashh56 34d603a
feat: enhance ER diagram with live sync and layout management
Yashh56 b6e2b9b
feat: implement schema explorer data handling with offline support an…
Yashh56 f577e14
Update bridge/src/services/projectStore.ts
Yashh56 949f785
Update bridge/src/services/projectStore.ts
Yashh56 1054fc0
Update src/pages/Projects.tsx
Yashh56 be56b92
refactor schema transformation logic in useProjectSync hook
Yashh56 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,329 @@ | ||
| import { Rpc } from "../types"; | ||
| import { Logger } from "pino"; | ||
| import { projectStoreInstance } from "../services/projectStore"; | ||
|
|
||
| /** | ||
| * RPC handlers for project CRUD and sub-resource operations. | ||
| * Mirrors the DatabaseHandlers pattern. | ||
| */ | ||
| export class ProjectHandlers { | ||
| constructor( | ||
| private rpc: Rpc, | ||
| private logger: Logger | ||
| ) { } | ||
|
|
||
|
|
||
| async handleListProjects(_params: any, id: number | string) { | ||
| try { | ||
| const projects = await projectStoreInstance.listProjects(); | ||
| this.rpc.sendResponse(id, { ok: true, data: projects }); | ||
| } catch (e: any) { | ||
| this.logger?.error({ e }, "project.list failed"); | ||
| this.rpc.sendError(id, { code: "IO_ERROR", message: String(e) }); | ||
| } | ||
| } | ||
|
|
||
| async handleGetProject(params: any, id: number | string) { | ||
| try { | ||
| const { id: projectId } = params || {}; | ||
| if (!projectId) { | ||
| return this.rpc.sendError(id, { | ||
| code: "BAD_REQUEST", | ||
| message: "Missing id", | ||
| }); | ||
| } | ||
|
|
||
| const project = await projectStoreInstance.getProject(projectId); | ||
| if (!project) { | ||
| return this.rpc.sendError(id, { | ||
| code: "NOT_FOUND", | ||
| message: "Project not found", | ||
| }); | ||
| } | ||
|
|
||
| this.rpc.sendResponse(id, { ok: true, data: project }); | ||
| } catch (e: any) { | ||
| this.logger?.error({ e }, "project.get failed"); | ||
| this.rpc.sendError(id, { code: "IO_ERROR", message: String(e) }); | ||
| } | ||
| } | ||
|
|
||
| async handleGetProjectByDatabaseId(params: any, id: number | string) { | ||
| try { | ||
| const { databaseId } = params || {}; | ||
| if (!databaseId) { | ||
| return this.rpc.sendError(id, { | ||
| code: "BAD_REQUEST", | ||
| message: "Missing databaseId", | ||
| }); | ||
| } | ||
|
|
||
| const project = await projectStoreInstance.getProjectByDatabaseId(databaseId); | ||
| // Return null (not an error) when no project is linked | ||
| this.rpc.sendResponse(id, { ok: true, data: project }); | ||
| } catch (e: any) { | ||
| this.logger?.error({ e }, "project.getByDatabaseId failed"); | ||
| this.rpc.sendError(id, { code: "IO_ERROR", message: String(e) }); | ||
| } | ||
| } | ||
|
|
||
| async handleCreateProject(params: any, id: number | string) { | ||
| try { | ||
| const { databaseId, name, description, defaultSchema } = params || {}; | ||
| if (!databaseId || !name) { | ||
| return this.rpc.sendError(id, { | ||
| code: "BAD_REQUEST", | ||
| message: "Missing databaseId or name", | ||
| }); | ||
| } | ||
|
|
||
| const project = await projectStoreInstance.createProject({ | ||
| databaseId, | ||
| name, | ||
| description, | ||
| defaultSchema, | ||
| }); | ||
|
|
||
| this.rpc.sendResponse(id, { ok: true, data: project }); | ||
| } catch (e: any) { | ||
| this.logger?.error({ e }, "project.create failed"); | ||
| this.rpc.sendError(id, { code: "IO_ERROR", message: String(e) }); | ||
| } | ||
| } | ||
|
|
||
| async handleUpdateProject(params: any, id: number | string) { | ||
| try { | ||
| const { id: projectId, ...updates } = params || {}; | ||
| if (!projectId) { | ||
| return this.rpc.sendError(id, { | ||
| code: "BAD_REQUEST", | ||
| message: "Missing id", | ||
| }); | ||
| } | ||
|
|
||
| const project = await projectStoreInstance.updateProject(projectId, updates); | ||
| if (!project) { | ||
| return this.rpc.sendError(id, { | ||
| code: "NOT_FOUND", | ||
| message: "Project not found", | ||
| }); | ||
| } | ||
|
|
||
| this.rpc.sendResponse(id, { ok: true, data: project }); | ||
| } catch (e: any) { | ||
| this.logger?.error({ e }, "project.update failed"); | ||
| this.rpc.sendError(id, { code: "IO_ERROR", message: String(e) }); | ||
| } | ||
| } | ||
|
|
||
| async handleDeleteProject(params: any, id: number | string) { | ||
| try { | ||
| const { id: projectId } = params || {}; | ||
| if (!projectId) { | ||
| return this.rpc.sendError(id, { | ||
| code: "BAD_REQUEST", | ||
| message: "Missing id", | ||
| }); | ||
| } | ||
|
|
||
| await projectStoreInstance.deleteProject(projectId); | ||
| this.rpc.sendResponse(id, { ok: true }); | ||
| } catch (e: any) { | ||
| this.logger?.error({ e }, "project.delete failed"); | ||
| this.rpc.sendError(id, { code: "IO_ERROR", message: String(e) }); | ||
| } | ||
| } | ||
|
|
||
| async handleGetSchema(params: any, id: number | string) { | ||
| try { | ||
| const { projectId } = params || {}; | ||
| if (!projectId) { | ||
| return this.rpc.sendError(id, { | ||
| code: "BAD_REQUEST", | ||
| message: "Missing projectId", | ||
| }); | ||
| } | ||
|
|
||
| const schema = await projectStoreInstance.getSchema(projectId); | ||
| this.rpc.sendResponse(id, { ok: true, data: schema }); | ||
| } catch (e: any) { | ||
| this.logger?.error({ e }, "project.getSchema failed"); | ||
| this.rpc.sendError(id, { code: "IO_ERROR", message: String(e) }); | ||
| } | ||
| } | ||
|
|
||
| async handleSaveSchema(params: any, id: number | string) { | ||
| try { | ||
| const { projectId, schemas } = params || {}; | ||
| if (!projectId || !schemas) { | ||
| return this.rpc.sendError(id, { | ||
| code: "BAD_REQUEST", | ||
| message: "Missing projectId or schemas", | ||
| }); | ||
| } | ||
|
|
||
| const result = await projectStoreInstance.saveSchema(projectId, schemas); | ||
| this.rpc.sendResponse(id, { ok: true, data: result }); | ||
| } catch (e: any) { | ||
| this.logger?.error({ e }, "project.saveSchema failed"); | ||
| this.rpc.sendError(id, { code: "IO_ERROR", message: String(e) }); | ||
| } | ||
| } | ||
|
|
||
| async handleGetERDiagram(params: any, id: number | string) { | ||
| try { | ||
| const { projectId } = params || {}; | ||
| if (!projectId) { | ||
| return this.rpc.sendError(id, { | ||
| code: "BAD_REQUEST", | ||
| message: "Missing projectId", | ||
| }); | ||
| } | ||
|
|
||
| const diagram = await projectStoreInstance.getERDiagram(projectId); | ||
| this.rpc.sendResponse(id, { ok: true, data: diagram }); | ||
| } catch (e: any) { | ||
| this.logger?.error({ e }, "project.getERDiagram failed"); | ||
| this.rpc.sendError(id, { code: "IO_ERROR", message: String(e) }); | ||
| } | ||
| } | ||
|
|
||
| async handleSaveERDiagram(params: any, id: number | string) { | ||
| try { | ||
| const { projectId, nodes, zoom, panX, panY } = params || {}; | ||
| if (!projectId || !nodes) { | ||
| return this.rpc.sendError(id, { | ||
| code: "BAD_REQUEST", | ||
| message: "Missing projectId or nodes", | ||
| }); | ||
| } | ||
|
|
||
| const result = await projectStoreInstance.saveERDiagram(projectId, { | ||
| nodes, | ||
| zoom, | ||
| panX, | ||
| panY, | ||
| }); | ||
| this.rpc.sendResponse(id, { ok: true, data: result }); | ||
| } catch (e: any) { | ||
| this.logger?.error({ e }, "project.saveERDiagram failed"); | ||
| this.rpc.sendError(id, { code: "IO_ERROR", message: String(e) }); | ||
| } | ||
| } | ||
|
|
||
| async handleGetQueries(params: any, id: number | string) { | ||
| try { | ||
| const { projectId } = params || {}; | ||
| if (!projectId) { | ||
| return this.rpc.sendError(id, { | ||
| code: "BAD_REQUEST", | ||
| message: "Missing projectId", | ||
| }); | ||
| } | ||
|
|
||
| const queries = await projectStoreInstance.getQueries(projectId); | ||
| this.rpc.sendResponse(id, { ok: true, data: queries }); | ||
| } catch (e: any) { | ||
| this.logger?.error({ e }, "project.getQueries failed"); | ||
| this.rpc.sendError(id, { code: "IO_ERROR", message: String(e) }); | ||
| } | ||
| } | ||
|
|
||
| async handleAddQuery(params: any, id: number | string) { | ||
| try { | ||
| const { projectId, name, sql, description } = params || {}; | ||
| if (!projectId || !name || !sql) { | ||
| return this.rpc.sendError(id, { | ||
| code: "BAD_REQUEST", | ||
| message: "Missing projectId, name, or sql", | ||
| }); | ||
| } | ||
|
|
||
| const query = await projectStoreInstance.addQuery(projectId, { | ||
| name, | ||
| sql, | ||
| description, | ||
| }); | ||
| this.rpc.sendResponse(id, { ok: true, data: query }); | ||
| } catch (e: any) { | ||
| this.logger?.error({ e }, "project.addQuery failed"); | ||
| this.rpc.sendError(id, { code: "IO_ERROR", message: String(e) }); | ||
| } | ||
| } | ||
|
|
||
| async handleUpdateQuery(params: any, id: number | string) { | ||
| try { | ||
| const { projectId, queryId, ...updates } = params || {}; | ||
| if (!projectId || !queryId) { | ||
| return this.rpc.sendError(id, { | ||
| code: "BAD_REQUEST", | ||
| message: "Missing projectId or queryId", | ||
| }); | ||
| } | ||
|
|
||
| const query = await projectStoreInstance.updateQuery( | ||
| projectId, | ||
| queryId, | ||
| updates | ||
| ); | ||
| if (!query) { | ||
| return this.rpc.sendError(id, { | ||
| code: "NOT_FOUND", | ||
| message: "Query not found", | ||
| }); | ||
| } | ||
|
|
||
| this.rpc.sendResponse(id, { ok: true, data: query }); | ||
| } catch (e: any) { | ||
| this.logger?.error({ e }, "project.updateQuery failed"); | ||
| this.rpc.sendError(id, { code: "IO_ERROR", message: String(e) }); | ||
| } | ||
| } | ||
|
|
||
| async handleDeleteQuery(params: any, id: number | string) { | ||
| try { | ||
| const { projectId, queryId } = params || {}; | ||
| if (!projectId || !queryId) { | ||
| return this.rpc.sendError(id, { | ||
| code: "BAD_REQUEST", | ||
| message: "Missing projectId or queryId", | ||
| }); | ||
| } | ||
|
|
||
| await projectStoreInstance.deleteQuery(projectId, queryId); | ||
| this.rpc.sendResponse(id, { ok: true }); | ||
| } catch (e: any) { | ||
| this.logger?.error({ e }, "project.deleteQuery failed"); | ||
| this.rpc.sendError(id, { code: "IO_ERROR", message: String(e) }); | ||
| } | ||
| } | ||
|
|
||
| // ========================================== | ||
| // Export (for future git-native support) | ||
| // ========================================== | ||
|
|
||
| async handleExportProject(params: any, id: number | string) { | ||
| try { | ||
| const { projectId } = params || {}; | ||
| if (!projectId) { | ||
| return this.rpc.sendError(id, { | ||
| code: "BAD_REQUEST", | ||
| message: "Missing projectId", | ||
| }); | ||
| } | ||
|
|
||
| const bundle = await projectStoreInstance.exportProject(projectId); | ||
| if (!bundle) { | ||
| return this.rpc.sendError(id, { | ||
| code: "NOT_FOUND", | ||
| message: "Project not found", | ||
| }); | ||
| } | ||
|
|
||
| this.rpc.sendResponse(id, { ok: true, data: bundle }); | ||
| } catch (e: any) { | ||
| this.logger?.error({ e }, "project.export failed"); | ||
| this.rpc.sendError(id, { code: "IO_ERROR", message: String(e) }); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.