diff --git a/Cargo.lock b/Cargo.lock index cd9e00b..31362db 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -242,6 +242,7 @@ dependencies = [ "napi-derive", "pyo3", "pyo3-build-config 0.19.2", + "serde", "thiserror", "tokio", "tokio-stream", @@ -388,6 +389,16 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +[[package]] +name = "erased-serde" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24e2389d65ab4fab27dc2a5de7b191e1f6617d1f1c8855c0dc569c94a4cbb18d" +dependencies = [ + "serde", + "typeid", +] + [[package]] name = "errno" version = "0.3.9" @@ -862,11 +873,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a52f529509c236114a5cf5bb3c0c06ff0695ad45d718256930ec2416edf3817" dependencies = [ "bstr", + "erased-serde", "mlua-sys", "mlua_derive", "num-traits", "parking_lot", "rustc-hash", + "serde", + "serde-value", ] [[package]] @@ -1020,6 +1034,15 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" +[[package]] +name = "ordered-float" +version = "2.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68f19d67e5a2795c94e73e0bb1cc1a7edeb2e28efd39e2e1c9b7a40c1108b11c" +dependencies = [ + "num-traits", +] + [[package]] name = "overload" version = "0.1.1" @@ -1521,18 +1544,28 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.205" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e33aedb1a7135da52b7c21791455563facbbcc43d0f0f66165b42c21b3dfb150" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" dependencies = [ "serde_derive", ] [[package]] -name = "serde_derive" -version = "1.0.205" +name = "serde-value" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "692d6f5ac90220161d6774db30c662202721e64aed9058d2c394f451261420c1" +checksum = "f3a1a3341211875ef120e117ea7fd5228530ae7e7036a779fdc9117be6b3282c" +dependencies = [ + "ordered-float", + "serde", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", @@ -1939,6 +1972,12 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "typeid" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e13db2e0ccd5e14a544e8a246ba2312cd25223f616442d7f2cb0e3db614236e" + [[package]] name = "unicode-ident" version = "1.0.12" @@ -1970,6 +2009,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81dfa00651efa65069b0b6b651f4aaa31ba9e3c3ce0137aaad053604ee7e0314" dependencies = [ "getrandom", + "serde", ] [[package]] diff --git a/dist/py/src/codemp/codemp.pyi b/dist/py/src/codemp/codemp.pyi index dc9a974..6e064e8 100644 --- a/dist/py/src/codemp/codemp.pyi +++ b/dist/py/src/codemp/codemp.pyi @@ -7,10 +7,19 @@ class Driver: """ def stop(self) -> None: ... +class Config: + """ + Configuration data structure for codemp clients + """ + username: str + password: str + host: Optional[str] + port: Optional[int] + tls: Optional[bool] def init() -> Driver: ... def set_logger(logger_cb: Callable[[str], None], debug: bool) -> bool: ... -def connect(host: str, username: str, password: str) -> Promise[Client]: ... +def connect(config: Config) -> Promise[Client]: ... class Promise[T]: """ diff --git a/src/ffi/js/client.rs b/src/ffi/js/client.rs index d82e8f3..8f5efab 100644 --- a/src/ffi/js/client.rs +++ b/src/ffi/js/client.rs @@ -3,11 +3,8 @@ use crate::{Client, Workspace}; #[napi] /// connect to codemp servers and return a client session -pub async fn connect(addr: Option, username: String, password: String) -> napi::Result{ - let client = crate::Client::connect(addr.as_deref().unwrap_or("http://code.mp:50053"), username, password) - .await?; - - Ok(client) +pub async fn connect(config: crate::api::Config) -> napi::Result{ + Ok(crate::Client::connect(config).await?) } #[napi] diff --git a/src/ffi/python/client.rs b/src/ffi/python/client.rs index 93afba7..f1ca3b5 100644 --- a/src/ffi/python/client.rs +++ b/src/ffi/python/client.rs @@ -5,14 +5,14 @@ use pyo3::prelude::*; #[pymethods] impl Client { - #[new] - fn __new__( - host: String, - username: String, - password: String, - ) -> crate::errors::ConnectionResult { - super::tokio().block_on(Client::connect(host, username, password)) - } + // #[new] + // fn __new__( + // host: String, + // username: String, + // password: String, + // ) -> crate::errors::ConnectionResult { + // super::tokio().block_on(Client::connect(host, username, password)) + // } // #[pyo3(name = "join_workspace")] // async fn pyjoin_workspace(&self, workspace: String) -> JoinHandle> { diff --git a/src/ffi/python/mod.rs b/src/ffi/python/mod.rs index 8268d93..b545afd 100644 --- a/src/ffi/python/mod.rs +++ b/src/ffi/python/mod.rs @@ -150,8 +150,8 @@ fn init() -> PyResult { } #[pyfunction] -fn connect(host: String, username: String, password: String) -> PyResult { - a_sync!(Client::connect(host, username, password).await) +fn connect(config: crate::api::Config) -> PyResult { + a_sync!(Client::connect(config).await) } #[pyfunction]