Skip to main content

meerkat_workgraph/
rest_contract.rs

1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2pub enum WorkGraphRestRoute {
3    Items,
4    Item,
5    Ready,
6    Snapshot,
7    Events,
8}
9
10#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11pub struct WorkGraphRestOperationDescriptor {
12    pub method: &'static str,
13    pub summary: &'static str,
14    pub response_schema: &'static str,
15}
16
17#[derive(Debug, Clone, Copy, PartialEq, Eq)]
18pub struct WorkGraphRestPathDescriptor {
19    pub route: WorkGraphRestRoute,
20    pub path: &'static str,
21    pub operations: &'static [WorkGraphRestOperationDescriptor],
22}
23
24const WORKGRAPH_ITEMS_OPERATIONS: &[WorkGraphRestOperationDescriptor] =
25    &[WorkGraphRestOperationDescriptor {
26        method: "get",
27        summary: "List WorkGraph items",
28        response_schema: "WorkGraphItemsResponse",
29    }];
30
31const WORKGRAPH_ITEM_OPERATIONS: &[WorkGraphRestOperationDescriptor] =
32    &[WorkGraphRestOperationDescriptor {
33        method: "get",
34        summary: "Get WorkGraph item",
35        response_schema: "WorkItem",
36    }];
37
38const WORKGRAPH_READY_OPERATIONS: &[WorkGraphRestOperationDescriptor] =
39    &[WorkGraphRestOperationDescriptor {
40        method: "get",
41        summary: "List ready WorkGraph items",
42        response_schema: "WorkGraphItemsResponse",
43    }];
44
45const WORKGRAPH_SNAPSHOT_OPERATIONS: &[WorkGraphRestOperationDescriptor] =
46    &[WorkGraphRestOperationDescriptor {
47        method: "get",
48        summary: "Read WorkGraph snapshot",
49        response_schema: "WorkGraphSnapshot",
50    }];
51
52const WORKGRAPH_EVENTS_OPERATIONS: &[WorkGraphRestOperationDescriptor] =
53    &[WorkGraphRestOperationDescriptor {
54        method: "get",
55        summary: "List WorkGraph events",
56        response_schema: "WorkGraphEventsResponse",
57    }];
58
59pub const WORKGRAPH_REST_PATHS: &[WorkGraphRestPathDescriptor] = &[
60    WorkGraphRestPathDescriptor {
61        route: WorkGraphRestRoute::Items,
62        path: "/workgraph/items",
63        operations: WORKGRAPH_ITEMS_OPERATIONS,
64    },
65    WorkGraphRestPathDescriptor {
66        route: WorkGraphRestRoute::Item,
67        path: "/workgraph/items/{id}",
68        operations: WORKGRAPH_ITEM_OPERATIONS,
69    },
70    WorkGraphRestPathDescriptor {
71        route: WorkGraphRestRoute::Ready,
72        path: "/workgraph/ready",
73        operations: WORKGRAPH_READY_OPERATIONS,
74    },
75    WorkGraphRestPathDescriptor {
76        route: WorkGraphRestRoute::Snapshot,
77        path: "/workgraph/snapshot",
78        operations: WORKGRAPH_SNAPSHOT_OPERATIONS,
79    },
80    WorkGraphRestPathDescriptor {
81        route: WorkGraphRestRoute::Events,
82        path: "/workgraph/events",
83        operations: WORKGRAPH_EVENTS_OPERATIONS,
84    },
85];
86
87pub fn workgraph_rest_path_catalog() -> &'static [WorkGraphRestPathDescriptor] {
88    WORKGRAPH_REST_PATHS
89}
90
91pub fn workgraph_rest_response_schema(path: &str, method: &str) -> Option<&'static str> {
92    WORKGRAPH_REST_PATHS
93        .iter()
94        .find(|entry| entry.path == path)
95        .and_then(|entry| {
96            entry
97                .operations
98                .iter()
99                .find(|operation| operation.method == method)
100        })
101        .map(|operation| operation.response_schema)
102}