diff --git a/dist/py/codemp.pyi b/dist/py/codemp.pyi index d5c25009..dc9a974e 100644 --- a/dist/py/codemp.pyi +++ b/dist/py/codemp.pyi @@ -79,7 +79,7 @@ class BufferController: Handle to the controller for a specific buffer, which manages the back and forth of operations to and from other peers. """ - def name(self) -> str: ... + def path(self) -> str: ... def content(self) -> Promise[str]: ... def send(self, start: int, diff --git a/src/ffi/js/buffer.rs b/src/ffi/js/buffer.rs index 2f533da3..7d19a5a9 100644 --- a/src/ffi/js/buffer.rs +++ b/src/ffi/js/buffer.rs @@ -33,9 +33,9 @@ impl BufferController { } - #[napi(js_name = "get_name")] - pub fn js_name(&self) -> napi::Result<&str> { - Ok(&self.name()) + #[napi(js_name = "get_path")] + pub fn js_path(&self) -> napi::Result<&str> { + Ok(&self.path()) } #[napi(js_name = "poll")] diff --git a/src/ffi/js/ext.rs b/src/ffi/js/ext.rs index cd905c48..56d87891 100644 --- a/src/ffi/js/ext.rs +++ b/src/ffi/js/ext.rs @@ -1,5 +1,5 @@ use napi_derive::napi; -use crate::hash; +use crate::ext::hash; #[napi(js_name = "hash")] diff --git a/src/ffi/js/mod.rs b/src/ffi/js/mod.rs index 2d066203..bdad225c 100644 --- a/src/ffi/js/mod.rs +++ b/src/ffi/js/mod.rs @@ -10,13 +10,21 @@ pub mod op_cache; pub mod ext; -impl From for napi::Error { - fn from(value: crate::Error) -> Self { - let msg = format!("{value}"); - match value { - crate::Error::Deadlocked => napi::Error::new(napi::Status::WouldDeadlock, msg), - _ => napi::Error::new(napi::Status::GenericFailure, msg), - } +impl From for napi::Error { + fn from(value: crate::errors::ConnectionError) -> Self { + napi::Error::new(napi::Status::GenericFailure, format!("{value}")) + } +} + +impl From for napi::Error { + fn from(value: crate::errors::RemoteError) -> Self { + napi::Error::new(napi::Status::GenericFailure, format!("{value}")) + } +} + +impl From for napi::Error { + fn from(value: crate::errors::ControllerError) -> Self { + napi::Error::new(napi::Status::GenericFailure, format!("{value}")) } } diff --git a/src/ffi/python/client.rs b/src/ffi/python/client.rs index 80a552c3..4bf9c9ea 100644 --- a/src/ffi/python/client.rs +++ b/src/ffi/python/client.rs @@ -4,9 +4,21 @@ use pyo3::prelude::*; #[pymethods] impl Client { - // #[new] - // fn __new__(host: String, username: String, password: String) -> crate::Result { - // tokio().block_on(Client::connect(host, username, password)) + #[new] + fn __new__(host: String, username: String, password: String) -> crate::errors::ConnectionResult { + tokio().block_on(Client::connect(host, username, password)) + } + + // #[pyo3(name = "join_workspace")] + // async fn pyjoin_workspace(&self, workspace: String) -> JoinHandle> { + // tracing::info!("attempting to join the workspace {}", workspace); + + // let this = self.clone(); + // async { + // tokio() + // .spawn(async move { this.join_workspace(workspace).await }) + // .await + // } // } #[pyo3(name = "join_workspace")] diff --git a/src/ffi/python/controllers.rs b/src/ffi/python/controllers.rs index 0d31a64e..c9cd6e18 100644 --- a/src/ffi/python/controllers.rs +++ b/src/ffi/python/controllers.rs @@ -74,9 +74,9 @@ impl CursorController { // need to do manually since Controller is a trait implementation #[pymethods] impl BufferController { - #[pyo3(name = "name")] - fn pyname(&self) -> String { - self.name().to_string() + #[pyo3(name = "path")] + fn pypath(&self) -> String { + self.path().to_string() } #[pyo3(name = "content")] diff --git a/src/ffi/python/mod.rs b/src/ffi/python/mod.rs index 92be8f41..088b5569 100644 --- a/src/ffi/python/mod.rs +++ b/src/ffi/python/mod.rs @@ -195,20 +195,21 @@ fn set_logger(logging_cb: Py, debug: bool) -> bool { log_subscribed } -impl From for PyErr { - fn from(value: crate::Error) -> Self { - match value { - crate::Error::Transport { status, message } => { - PyConnectionError::new_err(format!("Transport error: ({}) {}", status, message)) - } - crate::Error::Channel { send } => { - PyConnectionError::new_err(format!("Channel error (send:{})", send)) - } - crate::Error::InvalidState { msg } => { - PyRuntimeError::new_err(format!("Invalid state: {}", msg)) - } - crate::Error::Deadlocked => PyRuntimeError::new_err("Deadlock, retry."), - } +impl From for PyErr { + fn from(value: crate::errors::ConnectionError) -> Self { + PyConnectionError::new_err(format!("Connection error: {value}")) + } +} + +impl From for PyErr { + fn from(value: crate::errors::RemoteError) -> Self { + PyRuntimeError::new_err(format!("Remote error: {value}")) + } +} + +impl From for PyErr { + fn from(value: crate::errors::ControllerError) -> Self { + PyRuntimeError::new_err(format!("Controller error: {value}")) } } diff --git a/src/ffi/python/workspace.rs b/src/ffi/python/workspace.rs index e0b72a49..ac5371fb 100644 --- a/src/ffi/python/workspace.rs +++ b/src/ffi/python/workspace.rs @@ -24,9 +24,9 @@ impl Workspace { #[pyo3(name = "detach")] fn pydetach(&self, path: String) -> bool { match self.detach(path.as_str()) { - crate::workspace::worker::DetachResult::NotAttached => false, - crate::workspace::worker::DetachResult::Detaching => true, - crate::workspace::worker::DetachResult::AlreadyDetached => true, + crate::workspace::DetachResult::NotAttached => false, + crate::workspace::DetachResult::Detaching => true, + crate::workspace::DetachResult::AlreadyDetached => true, } }