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