( app: GuiStoreRouteHost, ix: IInstantiationService, )
| 34 | } |
| 35 | |
| 36 | export function registerGuiStoreRoutes( |
| 37 | app: GuiStoreRouteHost, |
| 38 | ix: IInstantiationService, |
| 39 | ): void { |
| 40 | const getItemRoute = defineRoute( |
| 41 | { |
| 42 | method: 'GET', |
| 43 | path: '/gui/store/getItem', |
| 44 | querystring: guiStoreGetItemQuerySchema, |
| 45 | success: { data: guiStoreGetItemResponseSchema }, |
| 46 | errors: { [ErrorCode.VALIDATION_FAILED]: {} }, |
| 47 | description: 'Read a value by key (mirrors localStorage.getItem).', |
| 48 | tags: ['gui-store'], |
| 49 | }, |
| 50 | async (req, reply) => { |
| 51 | const value = await ix.invokeFunction((a) => |
| 52 | a.get(IGuiStoreService).getItem(req.query.key), |
| 53 | ); |
| 54 | reply.send(okEnvelope({ value }, req.id)); |
| 55 | }, |
| 56 | ); |
| 57 | app.get( |
| 58 | getItemRoute.path, |
| 59 | getItemRoute.options, |
| 60 | getItemRoute.handler as Parameters<GuiStoreRouteHost['get']>[2], |
| 61 | ); |
| 62 | |
| 63 | const setItemRoute = defineRoute( |
| 64 | { |
| 65 | method: 'POST', |
| 66 | path: '/gui/store/setItem', |
| 67 | body: guiStoreSetItemBodySchema, |
| 68 | success: { data: z.null() }, |
| 69 | errors: { [ErrorCode.VALIDATION_FAILED]: {} }, |
| 70 | description: 'Write a value by key (mirrors localStorage.setItem).', |
| 71 | tags: ['gui-store'], |
| 72 | }, |
| 73 | async (req, reply) => { |
| 74 | await ix.invokeFunction((a) => |
| 75 | a.get(IGuiStoreService).setItem(req.body.key, req.body.value), |
| 76 | ); |
| 77 | reply.send(okEnvelope(null, req.id)); |
| 78 | }, |
| 79 | ); |
| 80 | app.post( |
| 81 | setItemRoute.path, |
| 82 | setItemRoute.options, |
| 83 | setItemRoute.handler as Parameters<GuiStoreRouteHost['post']>[2], |
| 84 | ); |
| 85 | |
| 86 | const removeItemRoute = defineRoute( |
| 87 | { |
| 88 | method: 'POST', |
| 89 | path: '/gui/store/removeItem', |
| 90 | body: guiStoreRemoveItemBodySchema, |
| 91 | success: { data: z.null() }, |
| 92 | errors: { [ErrorCode.VALIDATION_FAILED]: {} }, |
| 93 | description: 'Delete a value by key (mirrors localStorage.removeItem).', |
no test coverage detected