- Changed all import statements across the project to include the .js extension for consistency and to comply with ES module standards. - Updated imports in various files including bootstrap.ts, shutdown.ts, config.ts, and many others. - Ensured that all related modules and types are correctly imported with the new extension.
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import type { Router } from "express";
|
|
import express from "express";
|
|
import type { SharedUIState, SharedUIStatePatch } from "../state/uiState.js";
|
|
|
|
export { SharedUIState, SharedUIStatePatch };
|
|
|
|
export interface UIStateRouteOptions {
|
|
getSharedUIState: () => SharedUIState;
|
|
patchSharedUIState: (
|
|
patch: SharedUIStatePatch,
|
|
) => Promise<SharedUIState> | SharedUIState;
|
|
}
|
|
|
|
export function createUIStateRoutes(options: UIStateRouteOptions): Router {
|
|
const router = express.Router();
|
|
const { getSharedUIState, patchSharedUIState } = options;
|
|
|
|
// GET /api/ui-state - Get current UI state
|
|
router.get("/ui-state", (_req, res, next) => {
|
|
try {
|
|
const state = getSharedUIState();
|
|
res.json(state);
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
});
|
|
|
|
// POST /api/ui-state - Update UI state
|
|
router.post("/ui-state", async (req, res, next) => {
|
|
try {
|
|
const patch = req.body as SharedUIStatePatch;
|
|
const updated = await patchSharedUIState(patch);
|
|
res.json(updated);
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
});
|
|
|
|
return router;
|
|
}
|