don't
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor: remove xrpc proc macro

Signed-off-by: tjh <x@tjh.dev>

tjh ea80e65e 8823a0e2

+8 -135
-9
Cargo.lock
··· 2765 2765 "tracing", 2766 2766 "tracing-subscriber", 2767 2767 "url", 2768 - "xrpc", 2769 2768 ] 2770 2769 2771 2770 [[package]] ··· 5265 5266 version = "0.6.2" 5266 5267 source = "registry+https://github.com/rust-lang/crates.io-index" 5267 5268 checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9" 5268 - 5269 - [[package]] 5270 - name = "xrpc" 5271 - version = "0.0.0" 5272 - dependencies = [ 5273 - "quote", 5274 - "syn 2.0.111", 5275 - ] 5276 5269 5277 5270 [[package]] 5278 5271 name = "yoke"
-2
Cargo.toml
··· 9 9 "crates/knot", 10 10 "crates/lexicon", 11 11 "crates/git-service", 12 - "crates/xrpc" 13 12 ] 14 13 default-members = ["crates/knot"] 15 14 ··· 27 28 jetstream = { path = "crates/jetstream" } 28 29 lexicon = { path = "crates/lexicon" } 29 30 git-service = { path = "crates/git-service"} 30 - xrpc = { path = "crates/xrpc" } 31 31 32 32 anyhow = "1.0.100" 33 33 axum = "0.8.4"
-1
crates/knot/Cargo.toml
··· 15 15 jetstream.workspace = true 16 16 lexicon.workspace = true 17 17 git-service.workspace = true 18 - xrpc.workspace = true 19 18 20 19 anyhow.workspace = true 21 20 gix.workspace = true
+6 -3
crates/knot/src/public/xrpc.rs
··· 1 - use crate::model::{Knot, errors}; 1 + use crate::{ 2 + model::{Knot, errors}, 3 + public::xrpc::sh::tangled::{self, knot}, 4 + }; 2 5 use axum::{ 3 6 Json, Router, 4 7 extract::{FromRef, FromRequestParts}, ··· 24 21 25 22 Router::<S>::new() 26 23 .without_v07_checks() 27 - .merge(sh::tangled::owner()) 28 - .merge(sh::tangled::knot::version()) 24 + .route("/sh.tangled.owner", get(tangled::handle_owner)) 25 + .route("/sh.tangled.knot.version", get(knot::handle_version)) 29 26 .route("/sh.tangled.repo.blob", get(repo::handle_blob)) 30 27 .route("/sh.tangled.repo.branches", get(repo::handle_branches)) 31 28 .route("/sh.tangled.repo.create", post(repo::handle_create))
+1 -2
crates/knot/src/public/xrpc/sh/tangled.rs
··· 9 9 pub mod knot; 10 10 pub mod repo; 11 11 12 - #[xrpc::query("sh.tangled.owner")] 13 - pub async fn owner(State(knot): State<Knot>) -> Json<owner::Output<'static>> 12 + pub async fn handle_owner<S>(State(knot): State<Knot>) -> Json<owner::Output<'static>> 14 13 where 15 14 Knot: FromRef<S>, 16 15 {
+1 -2
crates/knot/src/public/xrpc/sh/tangled/knot.rs
··· 1 1 use axum::Json; 2 2 use lexicon::sh::tangled::knot::version; 3 3 4 - #[xrpc::query("sh.tangled.knot.version")] 5 - pub async fn version() -> Json<version::Output> { 4 + pub async fn handle_version() -> Json<version::Output> { 6 5 Json(version::Output { 7 6 version: concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")).into(), 8 7 })
-15
crates/xrpc/Cargo.toml
··· 1 - [package] 2 - name = "xrpc" 3 - version.workspace = true 4 - authors.workspace = true 5 - repository.workspace = true 6 - license.workspace = true 7 - edition.workspace = true 8 - publish.workspace = true 9 - 10 - [lib] 11 - proc-macro = true 12 - 13 - [dependencies] 14 - syn = "2.0" 15 - quote = "1.0"
-3
crates/xrpc/readme.md
··· 1 - # xrpc 2 - 3 - Helpers for raw-dogging XRPC APIs in axum.
-98
crates/xrpc/src/lib.rs
··· 1 - use proc_macro::TokenStream; 2 - use quote::quote; 3 - use syn::{Generics, ItemFn, LitStr, Signature, parse::Parse}; 4 - 5 - #[proc_macro_attribute] 6 - pub fn query(attr: TokenStream, item: TokenStream) -> TokenStream { 7 - let attr = syn::parse_macro_input!(attr as AttributeInput); 8 - let AttributeInput { nsid } = attr; 9 - 10 - let input = syn::parse_macro_input!(item as ItemFn); 11 - 12 - let ItemFn { 13 - attrs, 14 - vis, 15 - sig, 16 - block, 17 - } = input; 18 - 19 - let statements = block.stmts; 20 - 21 - let Signature { 22 - ident, 23 - inputs, 24 - output, 25 - generics, 26 - asyncness, 27 - .. 28 - } = sig; 29 - 30 - let Generics { where_clause, .. } = generics; 31 - 32 - quote!( 33 - #vis fn #ident<S: Clone + Send + Sync + 'static>() -> axum::Router<S> #where_clause { 34 - const NSID: &str = #nsid; 35 - 36 - #(#attrs)* 37 - #vis #asyncness fn #ident(#inputs) #output { 38 - #(#statements)* 39 - } 40 - 41 - axum::Router::<S>::new().route(concat!("/", #nsid), axum::routing::get(#ident)) 42 - } 43 - ) 44 - .into() 45 - } 46 - 47 - #[proc_macro_attribute] 48 - pub fn method(attr: TokenStream, item: TokenStream) -> TokenStream { 49 - let attr = syn::parse_macro_input!(attr as AttributeInput); 50 - let AttributeInput { nsid } = attr; 51 - 52 - let input = syn::parse_macro_input!(item as ItemFn); 53 - 54 - let ItemFn { 55 - attrs, 56 - vis, 57 - sig, 58 - block, 59 - } = input; 60 - 61 - let statements = block.stmts; 62 - 63 - let Signature { 64 - ident, 65 - inputs, 66 - output, 67 - generics, 68 - .. 69 - } = sig; 70 - 71 - let Generics { where_clause, .. } = generics; 72 - 73 - quote!( 74 - #vis fn #ident<S: Clone + Send + Sync + 'static>() -> axum::Router<S> #where_clause { 75 - const NSID: &str = #nsid; 76 - 77 - #(#attrs)* 78 - #vis async fn #ident(#inputs) #output { 79 - #(#statements)* 80 - } 81 - 82 - axum::Router::<S>::new().route(concat!("/", #nsid), axum::routing::post(#ident)) 83 - } 84 - ) 85 - .into() 86 - } 87 - 88 - struct AttributeInput { 89 - nsid: LitStr, 90 - } 91 - 92 - impl Parse for AttributeInput { 93 - fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> { 94 - Ok(Self { 95 - nsid: input.parse()?, 96 - }) 97 - } 98 - }