diff --git a/core/src/rpc/rpc_context.rs b/core/src/rpc/rpc_context.rs index f993ed95..435099fb 100644 --- a/core/src/rpc/rpc_context.rs +++ b/core/src/rpc/rpc_context.rs @@ -85,13 +85,30 @@ pub trait RpcContext { // ------------------------------ async fn yuse(&mut self, params: Array) -> Result, RpcError> { + // For both ns+db, string = change, null = unset, none = do nothing + // We need to be able to adjust either ns or db without affecting the other + // To be able to select a namespace, and then list resources in that namespace, as an example let (ns, db) = params.needs_two()?; - if let Value::Strand(ns) = ns { + let unset_ns = matches!(ns, Value::Null); + let unset_db = matches!(db, Value::Null); + + // If we unset the namespace, we must also unset the database + if unset_ns && !unset_db { + return Err(RpcError::InvalidParams); + } + + if unset_ns { + self.session_mut().ns = None; + } else if let Value::Strand(ns) = ns { self.session_mut().ns = Some(ns.0); } - if let Value::Strand(db) = db { + + if unset_db { + self.session_mut().db = None; + } else if let Value::Strand(db) = db { self.session_mut().db = Some(db.0); } + Ok(Value::None) }