mirror of
https://github.com/Start9Labs/rpc-toolkit.git
synced 2026-03-26 02:11:56 +00:00
thread through inherited params
This commit is contained in:
@@ -3,7 +3,7 @@ use std::collections::VecDeque;
|
||||
use std::ffi::OsString;
|
||||
|
||||
use clap::{CommandFactory, FromArgMatches};
|
||||
use imbl_value::Value;
|
||||
use imbl_value::{InOMap, Value};
|
||||
use reqwest::header::{ACCEPT, CONTENT_LENGTH, CONTENT_TYPE};
|
||||
use reqwest::{Client, Method};
|
||||
use serde::de::DeserializeOwned;
|
||||
@@ -67,6 +67,7 @@ impl<Context: crate::Context + Clone, Config: CommandFactory + FromArgMatches>
|
||||
parent_method: VecDeque::new(),
|
||||
method: method.clone(),
|
||||
params: params.clone(),
|
||||
inherited: Value::Object(InOMap::new()),
|
||||
})?;
|
||||
root_handler.cli_display(
|
||||
HandleAnyArgs {
|
||||
@@ -74,6 +75,7 @@ impl<Context: crate::Context + Clone, Config: CommandFactory + FromArgMatches>
|
||||
parent_method: VecDeque::new(),
|
||||
method,
|
||||
params,
|
||||
inherited: Value::Object(InOMap::new()),
|
||||
},
|
||||
res,
|
||||
)?;
|
||||
|
||||
@@ -26,6 +26,7 @@ pub(crate) struct HandleAnyArgs {
|
||||
pub(crate) parent_method: VecDeque<&'static str>,
|
||||
pub(crate) method: VecDeque<&'static str>,
|
||||
pub(crate) params: Value,
|
||||
pub(crate) inherited: Value,
|
||||
}
|
||||
impl HandleAnyArgs {
|
||||
fn downcast<Context: IntoContext, H>(
|
||||
@@ -41,6 +42,7 @@ impl HandleAnyArgs {
|
||||
parent_method,
|
||||
method,
|
||||
params,
|
||||
inherited,
|
||||
} = self;
|
||||
Ok(HandlerArgs {
|
||||
context: Context::downcast(context).map_err(|_| imbl_value::Error {
|
||||
@@ -50,7 +52,7 @@ impl HandleAnyArgs {
|
||||
parent_method,
|
||||
method,
|
||||
params: imbl_value::from_value(params.clone())?,
|
||||
inherited_params: imbl_value::from_value(params.clone())?,
|
||||
inherited_params: imbl_value::from_value(inherited.clone())?,
|
||||
raw_params: params,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use std::sync::Arc;
|
||||
|
||||
use clap::{ArgMatches, Command, CommandFactory, FromArgMatches};
|
||||
use imbl_value::imbl::{OrdMap, OrdSet};
|
||||
use imbl_value::Value;
|
||||
use imbl_value::{to_value, Value};
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::Serialize;
|
||||
use yajrc::RpcError;
|
||||
@@ -172,7 +172,7 @@ where
|
||||
#[async_trait::async_trait]
|
||||
impl<Params, InheritedParams> Handler for ParentHandler<Params, InheritedParams>
|
||||
where
|
||||
Params: Serialize + Send + Sync + 'static,
|
||||
Params: Send + Sync + 'static,
|
||||
InheritedParams: Serialize + Send + Sync + 'static,
|
||||
{
|
||||
type Context = AnyContext;
|
||||
@@ -182,6 +182,7 @@ where
|
||||
context,
|
||||
mut parent_method,
|
||||
mut method,
|
||||
inherited_params,
|
||||
raw_params,
|
||||
..
|
||||
}: HandlerArgsFor<AnyContext, Self>,
|
||||
@@ -196,6 +197,7 @@ where
|
||||
parent_method,
|
||||
method,
|
||||
params: raw_params,
|
||||
inherited: to_value(&inherited_params)?,
|
||||
})
|
||||
} else {
|
||||
Err(yajrc::METHOD_NOT_FOUND_ERROR)
|
||||
@@ -207,6 +209,7 @@ where
|
||||
context,
|
||||
mut parent_method,
|
||||
mut method,
|
||||
inherited_params,
|
||||
raw_params,
|
||||
..
|
||||
}: HandlerArgsFor<AnyContext, Self>,
|
||||
@@ -222,6 +225,7 @@ where
|
||||
parent_method,
|
||||
method,
|
||||
params: raw_params,
|
||||
inherited: to_value(&inherited_params)?,
|
||||
})
|
||||
.await
|
||||
} else {
|
||||
@@ -326,6 +330,7 @@ where
|
||||
context,
|
||||
mut parent_method,
|
||||
mut method,
|
||||
inherited_params,
|
||||
raw_params,
|
||||
..
|
||||
}: HandlerArgsFor<AnyContext, Self>,
|
||||
@@ -344,6 +349,7 @@ where
|
||||
parent_method,
|
||||
method,
|
||||
params: raw_params,
|
||||
inherited: to_value(&inherited_params)?,
|
||||
},
|
||||
result,
|
||||
)
|
||||
|
||||
@@ -4,7 +4,7 @@ use std::sync::Arc;
|
||||
|
||||
use futures::future::{join_all, BoxFuture};
|
||||
use futures::{Future, FutureExt, Stream, StreamExt};
|
||||
use imbl_value::Value;
|
||||
use imbl_value::{InOMap, Value};
|
||||
use yajrc::{RpcError, RpcMethod};
|
||||
|
||||
use crate::util::{invalid_request, JobRunner};
|
||||
@@ -66,6 +66,7 @@ impl<Context: crate::Context> Server<Context> {
|
||||
parent_method: VecDeque::new(),
|
||||
method: method.ok_or_else(|| yajrc::METHOD_NOT_FOUND_ERROR)?,
|
||||
params,
|
||||
inherited: Value::Object(InOMap::new()),
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user