cratestack-macros 0.7.7

Rust-native schema-first framework for typed HTTP APIs, generated clients, and backend services.
Documentation
//! `GET /rpc/subscribe/{op_id}` handler tokens — SSE subscription
//! dispatch (design doc §3.4a, cratestack#390). Per-model arm bodies are
//! generated by `crate::transport::subscribe_dispatch`; this module only
//! wires them into the shared match/fallback shape, mirroring
//! `build_dispatch_block` in the parent module.

use quote::quote;

pub(super) fn build_subscribe_block(arms: &[proc_macro2::TokenStream]) -> proc_macro2::TokenStream {
    quote! {
        async fn rpc_subscribe_dispatch<R, C, Auth>(
            ::cratestack::axum::extract::State(state):
                ::cratestack::axum::extract::State<RpcRouterState<R, C, Auth>>,
            ::cratestack::axum::extract::Path(op_id):
                ::cratestack::axum::extract::Path<String>,
            headers: ::cratestack::axum::http::HeaderMap,
        ) -> ::cratestack::axum::response::Response
        where
            R: super::procedures::ProcedureRegistry,
            C: HttpTransport,
            Auth: ::cratestack::AuthProvider,
        {
            match op_id.as_str() {
                #(#arms)*
                other => {
                    ::cratestack::tracing::warn!(
                        target: "cratestack",
                        cratestack_operation = "rpc_subscribe_dispatch",
                        cratestack_op_id = other,
                        "unknown subscription op id",
                    );
                    rpc_dispatch_error(
                        &state,
                        &headers,
                        ::cratestack::CoolError::NotFound(format!(
                            "unknown subscription op `{other}`",
                        )),
                    )
                }
            }
        }
    }
}