|
| 1 | +// SPDX-License-Identifier: PMPL-1.0-or-later |
| 2 | +/** |
| 3 | + * Praxis API Routes — Central Routing Manifest |
| 4 | + * Fully ported to ReScript v12 |
| 5 | + */ |
| 6 | + |
| 7 | +open Types |
| 8 | +open AuditController |
| 9 | +open BaselineController |
| 10 | +open ExecutionController |
| 11 | +open SymbolController |
| 12 | +open WorkflowController |
| 13 | + |
| 14 | +module Elysia = { |
| 15 | + type t |
| 16 | + type context<'q, 'p, 'b> = { |
| 17 | + query: 'q, |
| 18 | + params: 'p, |
| 19 | + body: 'b, |
| 20 | + } |
| 21 | + @send external get: (t, string, context<'q, 'p, 'b> => promise<'res>) => t = "get" |
| 22 | + @send external post: (t, string, context<'q, 'p, 'b> => promise<'res>) => t = "post" |
| 23 | + @send external patch: (t, string, context<'q, 'p, 'b> => promise<'res>) => t = "patch" |
| 24 | + @send external delete: (t, string, context<'q, 'p, 'b> => promise<'res>) => t = "delete" |
| 25 | + @send external group: (t, string, t => t) => t = "group" |
| 26 | +} |
| 27 | + |
| 28 | +let setupAuditRoutes = (app: Elysia.t, controller: AuditController.t) => { |
| 29 | + app->Elysia.group("/audits", app => { |
| 30 | + app |
| 31 | + ->Elysia.get("/", async _ctx => { |
| 32 | + let workflowId = %raw(`ctx.query.workflow_id`) |
| 33 | + await AuditController.list(controller, workflowId) |
| 34 | + }) |
| 35 | + ->Elysia.get("/stats", async _ => { |
| 36 | + await AuditController.getStats(controller) |
| 37 | + }) |
| 38 | + }) |
| 39 | +} |
| 40 | + |
| 41 | +let setupBaselineRoutes = (app: Elysia.t, controller: BaselineController.t) => { |
| 42 | + app->Elysia.group("/baselines", app => { |
| 43 | + app |
| 44 | + ->Elysia.get("/", async _ctx => { |
| 45 | + let workflowId = %raw(`ctx.query.workflow_id`) |
| 46 | + await BaselineController.list(controller, workflowId) |
| 47 | + }) |
| 48 | + ->Elysia.get("/normative/:workflow_id", async _ctx => { |
| 49 | + let workflowId = %raw(`ctx.params.workflow_id`) |
| 50 | + await BaselineController.getNormative(controller, workflowId) |
| 51 | + }) |
| 52 | + }) |
| 53 | +} |
| 54 | + |
| 55 | +let setupExecutionRoutes = (app: Elysia.t, controller: ExecutionController.t) => { |
| 56 | + app->Elysia.group("/executions", app => { |
| 57 | + app |
| 58 | + ->Elysia.get("/", async _ctx => { |
| 59 | + let status = %raw(`ctx.query.status`) |
| 60 | + await ExecutionController.list(controller, status) |
| 61 | + }) |
| 62 | + ->Elysia.get("/stats", async _ => { |
| 63 | + await ExecutionController.getStats(controller) |
| 64 | + }) |
| 65 | + }) |
| 66 | +} |
| 67 | + |
| 68 | +let setupSymbolRoutes = (app: Elysia.t, controller: SymbolController.t) => { |
| 69 | + app->Elysia.group("/symbols", app => { |
| 70 | + app |
| 71 | + ->Elysia.get("/", async _ => { |
| 72 | + await SymbolController.list(controller, None) |
| 73 | + }) |
| 74 | + ->Elysia.get("/search", async _ctx => { |
| 75 | + let q = %raw(`ctx.query.q`) |
| 76 | + let type_ = %raw(`ctx.query.type`) |
| 77 | + await SymbolController.search(controller, q, type_) |
| 78 | + }) |
| 79 | + }) |
| 80 | +} |
| 81 | + |
| 82 | +let setupWorkflowRoutes = (app: Elysia.t, controller: WorkflowController.t) => { |
| 83 | + app->Elysia.group("/workflows", app => { |
| 84 | + app |
| 85 | + ->Elysia.get("/", async _ctx => { |
| 86 | + let status = %raw(`ctx.query.status`) |
| 87 | + await WorkflowController.list(controller, status) |
| 88 | + }) |
| 89 | + ->Elysia.post("/", async _ctx => { |
| 90 | + let name = %raw(`ctx.body.name`) |
| 91 | + let path = %raw(`ctx.body.manifest_path`) |
| 92 | + await WorkflowController.create(controller, name, path) |
| 93 | + }) |
| 94 | + ->Elysia.get("/:id/symbols", async _ctx => { |
| 95 | + let id = %raw(`ctx.params.id`) |
| 96 | + await WorkflowController.getSymbols(controller, id) |
| 97 | + }) |
| 98 | + }) |
| 99 | +} |
0 commit comments