Skip to main content

laser_wire/
commands.rs

1// One trait pairing each managed command code with its request and reply wire
2// types. Not a multi-implementor abstraction (there is one wire contract and one established
3// band): a compile-time assertion that the code/type pairings match, giving
4// the SDK one generic send path and LaserData Cloud's dispatch table a fixture test
5// against the same pairings.
6
7use crate::agent_workflow::{AgentCancel, AgentList, AgentReply, AgentStatusReq, AgentSubmit};
8use crate::authz::{
9    AuthzReply, BindRolesReq, DefineRoleReq, DeleteRoleReq, GetBindingsReq, GetRoleReq,
10    ListRolesReq, WhoamiReq,
11};
12use crate::browse::{
13    BrowseReply, DecodeRecord, GetProjection, GetSchema, ListProjections, ListSchemas,
14    RegisterSchema,
15};
16use crate::codes::*;
17use crate::fork::{ForkCreate, ForkDelete, ForkList, ForkPromote, ForkPut, ForkReply};
18use crate::kv::{KvDelete, KvDeleteMany, KvGet, KvNamespaces, KvReply, KvScan, KvSet};
19use crate::query::{QueryEnvelope, QueryReply};
20
21/// A managed command: the request type, its wire code, and the reply type the
22/// other end answers with.
23pub trait Command {
24    /// The managed command code this request rides.
25    const CODE: u32;
26    /// The reply wire type.
27    type Reply;
28}
29
30macro_rules! command {
31    ($request:ty, $code:expr, $reply:ty) => {
32        impl Command for $request {
33            const CODE: u32 = $code;
34            type Reply = $reply;
35        }
36    };
37}
38
39command!(WhoamiReq, AGDX_AUTHZ_WHOAMI_CODE, AuthzReply);
40command!(ListRolesReq, AGDX_AUTHZ_LIST_ROLES_CODE, AuthzReply);
41command!(GetRoleReq, AGDX_AUTHZ_GET_ROLE_CODE, AuthzReply);
42command!(GetBindingsReq, AGDX_AUTHZ_GET_BINDINGS_CODE, AuthzReply);
43command!(DefineRoleReq, AGDX_AUTHZ_DEFINE_ROLE_CODE, AuthzReply);
44command!(DeleteRoleReq, AGDX_AUTHZ_DELETE_ROLE_CODE, AuthzReply);
45command!(BindRolesReq, AGDX_AUTHZ_BIND_ROLES_CODE, AuthzReply);
46command!(QueryEnvelope, AGDX_QUERY_CODE, QueryReply);
47command!(GetProjection, AGDX_GET_PROJECTION_CODE, BrowseReply);
48command!(ListProjections, AGDX_LIST_PROJECTIONS_CODE, BrowseReply);
49command!(GetSchema, AGDX_GET_SCHEMA_CODE, BrowseReply);
50command!(ListSchemas, AGDX_LIST_SCHEMAS_CODE, BrowseReply);
51command!(RegisterSchema, AGDX_REGISTER_SCHEMA_CODE, BrowseReply);
52command!(DecodeRecord, AGDX_DECODE_RECORD_CODE, BrowseReply);
53command!(KvGet, AGDX_KV_GET_CODE, KvReply);
54command!(KvSet, AGDX_KV_SET_CODE, KvReply);
55command!(KvScan, AGDX_KV_SCAN_CODE, KvReply);
56command!(KvDelete, AGDX_KV_DELETE_CODE, KvReply);
57command!(KvDeleteMany, AGDX_KV_DELETE_MANY_CODE, KvReply);
58command!(KvNamespaces, AGDX_KV_NAMESPACES_CODE, KvReply);
59command!(ForkCreate, AGDX_FORK_CREATE_CODE, ForkReply);
60command!(ForkDelete, AGDX_FORK_DELETE_CODE, ForkReply);
61command!(ForkPromote, AGDX_FORK_PROMOTE_CODE, ForkReply);
62command!(ForkList, AGDX_FORK_LIST_CODE, ForkReply);
63command!(ForkPut, AGDX_FORK_PUT_CODE, ForkReply);
64command!(AgentSubmit, AGDX_AGENT_SUBMIT_CODE, AgentReply);
65command!(AgentCancel, AGDX_AGENT_CANCEL_CODE, AgentReply);
66command!(AgentStatusReq, AGDX_AGENT_STATUS_CODE, AgentReply);
67command!(AgentList, AGDX_AGENT_LIST_CODE, AgentReply);
68
69#[cfg(test)]
70mod tests {
71    use super::*;
72
73    #[test]
74    fn given_command_impls_when_compared_then_codes_should_match_the_dictionary() {
75        assert_eq!(<WhoamiReq as Command>::CODE, 1_000_100);
76        assert_eq!(<ListRolesReq as Command>::CODE, 1_000_101);
77        assert_eq!(<GetRoleReq as Command>::CODE, 1_000_102);
78        assert_eq!(<GetBindingsReq as Command>::CODE, 1_000_103);
79        assert_eq!(<DefineRoleReq as Command>::CODE, 1_000_104);
80        assert_eq!(<DeleteRoleReq as Command>::CODE, 1_000_105);
81        assert_eq!(<BindRolesReq as Command>::CODE, 1_000_106);
82        assert_eq!(<QueryEnvelope as Command>::CODE, 1_000_200);
83        assert_eq!(<GetProjection as Command>::CODE, 1_000_210);
84        assert_eq!(<ListProjections as Command>::CODE, 1_000_211);
85        assert_eq!(<GetSchema as Command>::CODE, 1_000_220);
86        assert_eq!(<ListSchemas as Command>::CODE, 1_000_221);
87        assert_eq!(<RegisterSchema as Command>::CODE, 1_000_222);
88        assert_eq!(<DecodeRecord as Command>::CODE, 1_000_223);
89        assert_eq!(<KvGet as Command>::CODE, 1_000_300);
90        assert_eq!(<KvSet as Command>::CODE, 1_000_301);
91        assert_eq!(<KvScan as Command>::CODE, 1_000_302);
92        assert_eq!(<KvDelete as Command>::CODE, 1_000_303);
93        assert_eq!(<KvDeleteMany as Command>::CODE, 1_000_304);
94        assert_eq!(<KvNamespaces as Command>::CODE, 1_000_305);
95        assert_eq!(<ForkCreate as Command>::CODE, 1_000_400);
96        assert_eq!(<ForkDelete as Command>::CODE, 1_000_401);
97        assert_eq!(<ForkPromote as Command>::CODE, 1_000_402);
98        assert_eq!(<ForkList as Command>::CODE, 1_000_403);
99        assert_eq!(<ForkPut as Command>::CODE, 1_000_404);
100        assert_eq!(<AgentSubmit as Command>::CODE, 1_000_700);
101        assert_eq!(<AgentCancel as Command>::CODE, 1_000_701);
102        assert_eq!(<AgentStatusReq as Command>::CODE, 1_000_702);
103        assert_eq!(<AgentList as Command>::CODE, 1_000_703);
104    }
105}