( app: WorkspaceRouteHost, ix: IInstantiationService, )
| 52 | } |
| 53 | |
| 54 | export function registerWorkspacesRoutes( |
| 55 | app: WorkspaceRouteHost, |
| 56 | ix: IInstantiationService, |
| 57 | ): void { |
| 58 | |
| 59 | const listRoute = defineRoute( |
| 60 | { |
| 61 | method: 'GET', |
| 62 | path: '/workspaces', |
| 63 | success: { data: listWorkspacesResponseSchema }, |
| 64 | description: 'List registered workspaces', |
| 65 | tags: ['workspaces'], |
| 66 | }, |
| 67 | async (req, reply) => { |
| 68 | try { |
| 69 | const items = await ix.invokeFunction((a) => a.get(IWorkspaceRegistry).list()); |
| 70 | reply.send(okEnvelope({ items }, req.id)); |
| 71 | } catch (err) { |
| 72 | sendMappedError(reply, req.id, err); |
| 73 | } |
| 74 | }, |
| 75 | ); |
| 76 | |
| 77 | app.get( |
| 78 | listRoute.path, |
| 79 | listRoute.options, |
| 80 | listRoute.handler as Parameters<WorkspaceRouteHost['get']>[2], |
| 81 | ); |
| 82 | |
| 83 | const createRoute = defineRoute( |
| 84 | { |
| 85 | method: 'POST', |
| 86 | path: '/workspaces', |
| 87 | body: createWorkspaceRequestSchema, |
| 88 | success: { data: createWorkspaceResponseSchema }, |
| 89 | description: 'Register a workspace (idempotent on root)', |
| 90 | tags: ['workspaces'], |
| 91 | }, |
| 92 | async (req, reply) => { |
| 93 | try { |
| 94 | const ws = await ix.invokeFunction((a) => |
| 95 | a.get(IWorkspaceRegistry).createOrTouch(req.body.root, req.body.name), |
| 96 | ); |
| 97 | reply.send(okEnvelope(ws, req.id)); |
| 98 | } catch (err) { |
| 99 | sendMappedError(reply, req.id, err); |
| 100 | } |
| 101 | }, |
| 102 | ); |
| 103 | |
| 104 | app.post( |
| 105 | createRoute.path, |
| 106 | createRoute.options, |
| 107 | createRoute.handler as Parameters<WorkspaceRouteHost['post']>[2], |
| 108 | ); |
| 109 | |
| 110 | const updateRoute = defineRoute( |
| 111 | { |
no test coverage detected