Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

renamed PolywrapClient to Client #234

Merged
merged 2 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ $ cargo run --package polywrap_tests_utils --bin generate
```
Now you will be able to run tests of all crates:
```shell
$ cargo test
$ cargo test --release
krisbitney marked this conversation as resolved.
Show resolved Hide resolved
```

## Feedback and discussions
Expand Down
4 changes: 2 additions & 2 deletions examples/src/ens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ fn main() {
let domain = "vitalik.eth".to_string();
let ens_uri = uri!("wrapscan.io/polywrap/[email protected]");

let mut config = PolywrapClientConfig::new();
let mut config = ClientConfig::new();
config
.add(SystemClientConfig::default().into())
.add(Web3ClientConfig::default().into());

let client = PolywrapClient::new(config.build());
let client = Client::new(config.build());

let resolver_address = client.invoke::<String>(
&ens_uri,
Expand Down
4 changes: 2 additions & 2 deletions examples/src/ethers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct ToEthArgs {
fn main() {
let ethers_core_uri = uri!("wrapscan.io/polywrap/[email protected]");
let ethers_util_uri = uri!("wrapscan.io/polywrap/[email protected]");
let mut config = PolywrapClientConfig::new();
let mut config = ClientConfig::new();
config.add(SystemClientConfig::default().into());

let mainnet_connection = Connection::new(
Expand All @@ -50,7 +50,7 @@ fn main() {

config.add_package(uri!("wrapscan.io/polywrap/[email protected]"), package);

let client = PolywrapClient::new(config.build());
let client = Client::new(config.build());

let balance = client.invoke::<String>(
&ethers_core_uri,
Expand Down
4 changes: 2 additions & 2 deletions examples/src/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ struct FileArgs {

fn main() {
let uri = uri!("wrapscan.io/polywrap/[email protected]");
let mut config = PolywrapClientConfig::new();
let mut config = ClientConfig::new();
let fs_package = PluginPackage::from(FileSystemPlugin {});

config.add_package(uri.clone(), Arc::new(fs_package));

let file_path = "./fs-example.txt".to_string();
let data = "Hello world!";

let client = PolywrapClient::new(config.build());
let client = Client::new(config.build());
let write_file_result = client.invoke::<bool>(
&uri,
"writeFile",
Expand Down
4 changes: 2 additions & 2 deletions examples/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ struct PostArgs {

fn main() {
let uri = uri!("wrapscan.io/polywrap/[email protected]");
let mut config = PolywrapClientConfig::new();
let mut config = ClientConfig::new();
let http_package = PluginPackage::from(HttpPlugin {});

config.add_package(uri.clone(), Arc::new(http_package));

let client = PolywrapClient::new(config.build());
let client = Client::new(config.build());
let get_result = client.invoke::<Response>(
&uri,
"get",
Expand Down
4 changes: 2 additions & 2 deletions examples/src/ipfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ fn main() {
let ipfs_provider = "http://localhost:5001";
let uri = uri!("wrapscan.io/polywrap/[email protected]");

let mut config = PolywrapClientConfig::new();
let mut config = ClientConfig::new();
config.add(SystemClientConfig::default().into());

let config = config.build();

let client = PolywrapClient::new(config);
let client = Client::new(config);

let file_name = "hello-world.txt";
let file_data = "Hello World!!!";
Expand Down
4 changes: 2 additions & 2 deletions examples/src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ struct LogMessageArgs {

fn main() {
let wrap_uri = uri!("wrapscan.io/polywrap/[email protected]");
let mut config = PolywrapClientConfig::new();
let mut config = ClientConfig::new();

config.add(SystemClientConfig::default().into());
let client = PolywrapClient::new(config.build());
let client = Client::new(config.build());
let result = client.invoke::<bool>(
&wrap_uri,
"info",
Expand Down
4 changes: 2 additions & 2 deletions packages/builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ pub mod polywrap_client_config;
pub mod polywrap_client_config_builder;

pub use polywrap_base_resolver::{PolywrapBaseResolver, PolywrapBaseResolverOptions};
pub use polywrap_client_config::PolywrapClientConfig;
pub use polywrap_client_config_builder::PolywrapClientConfigBuilder;
pub use polywrap_client_config::ClientConfig;
pub use polywrap_client_config_builder::ClientConfigBuilder;
22 changes: 11 additions & 11 deletions packages/builder/src/polywrap_client_config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{collections::HashMap, sync::Arc};

use polywrap_core::{
client::{ClientConfig, ClientConfigBuilder},
client::{CoreClientConfig, CoreClientConfigBuilder},
interface_implementation::InterfaceImplementations,
package::WrapPackage,
resolution::uri_resolver::UriResolver,
Expand All @@ -10,10 +10,10 @@ use polywrap_core::{
};
use polywrap_resolvers::static_resolver::{StaticResolver, StaticResolverLike};

use crate::{PolywrapBaseResolver, PolywrapBaseResolverOptions, PolywrapClientConfigBuilder};
use crate::{PolywrapBaseResolver, PolywrapBaseResolverOptions, ClientConfigBuilder};

#[derive(Default, Clone)]
pub struct PolywrapClientConfig {
pub struct ClientConfig {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i feel that this should be something like ClientBuilderConfig and the CoreClientConfig be ClientConfig - I feel that the Core prefix is non intuitive. Wdyt? Also cc to @namesty and @nerfZael to see what they think

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should make the most user-facing type the easiest to understand and read. So, that would mean that the config used by the builder is the ClientConfig, and the "fully built config" that's used by the client would be the CoreClientConfig.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should make the most user-facing type the easiest to understand and read. So, that would mean that the config used by the builder is the ClientConfig, and the "fully built config" that's used by the client would be the CoreClientConfig.

yah in my opinion that's not the easiest to understand and read but rather confusing. if I see this for the first time I would ask to myself "what's the difference between a client and a core client" and why do they have different attributes. from my perspective, this can be really simplified to say that one is the builder attributes and the other is the client attributes (but again, this is my opinion and I can be completely wrong)

Copy link
Collaborator

@cbrzn cbrzn Sep 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

anyways, I will merge this because it is a nit, and there's no need to block this

pub interfaces: Option<InterfaceImplementations>,
pub envs: Option<HashMap<Uri, Vec<u8>>>,
pub wrappers: Option<Vec<(Uri, Arc<dyn Wrapper>)>>,
Expand All @@ -22,7 +22,7 @@ pub struct PolywrapClientConfig {
pub resolvers: Option<Vec<Arc<dyn UriResolver>>>,
}

impl PolywrapClientConfig {
impl ClientConfig {
pub fn new() -> Self {
// We don't want to use the default constructor here because it may change
// and then `new` would no longer create an empty config.
Expand Down Expand Up @@ -65,8 +65,8 @@ impl PolywrapClientConfig {
}
}

impl PolywrapClientConfigBuilder for PolywrapClientConfig {
fn add(&mut self, config: PolywrapClientConfig) -> &mut Self {
impl ClientConfigBuilder for ClientConfig {
fn add(&mut self, config: ClientConfig) -> &mut Self {
if let Some(e) = config.envs {
self.add_envs(e);
};
Expand Down Expand Up @@ -323,11 +323,11 @@ impl PolywrapClientConfigBuilder for PolywrapClientConfig {
}
}

impl ClientConfigBuilder for PolywrapClientConfig {
fn build(self) -> ClientConfig {
impl CoreClientConfigBuilder for ClientConfig {
fn build(self) -> CoreClientConfig {
// We first build the resolver because it needs a reference to self
// this way we don't need to clone `envs`, and `interfaces`.
ClientConfig {
CoreClientConfig {
resolver: PolywrapBaseResolver::new(PolywrapBaseResolverOptions {
static_resolver: self.build_static_resolver(),
dynamic_resolvers: self.resolvers,
Expand All @@ -339,8 +339,8 @@ impl ClientConfigBuilder for PolywrapClientConfig {
}
}

impl Into<ClientConfig> for PolywrapClientConfig {
fn into(self) -> ClientConfig {
impl Into<CoreClientConfig> for ClientConfig {
fn into(self) -> CoreClientConfig {
self.build()
}
}
8 changes: 4 additions & 4 deletions packages/builder/src/polywrap_client_config_builder.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use std::{collections::HashMap, sync::Arc};

use polywrap_core::{
client::ClientConfigBuilder, package::WrapPackage, resolution::uri_resolver::UriResolver,
client::CoreClientConfigBuilder, package::WrapPackage, resolution::uri_resolver::UriResolver,
uri::Uri, wrapper::Wrapper,
};

use crate::PolywrapClientConfig;
use crate::ClientConfig;

pub trait PolywrapClientConfigBuilder: ClientConfigBuilder {
fn add(&mut self, config: PolywrapClientConfig) -> &mut Self;
pub trait ClientConfigBuilder: CoreClientConfigBuilder {
fn add(&mut self, config: ClientConfig) -> &mut Self;
fn add_env(&mut self, uri: Uri, env: Vec<u8>) -> &mut Self;
fn add_envs(&mut self, env: HashMap<Uri, Vec<u8>>) -> &mut Self;
fn remove_env(&mut self, uri: &Uri) -> &mut Self;
Expand Down
22 changes: 11 additions & 11 deletions packages/builder/tests/test_builder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{collections::HashMap, sync::Arc};

use polywrap_client_builder::{PolywrapClientConfig, PolywrapClientConfigBuilder};
use polywrap_client_builder::{ClientConfig, ClientConfigBuilder};
use polywrap_core::{macros::uri, package::WrapPackage, uri::Uri, wrapper::Wrapper};
use polywrap_msgpack_serde::to_vec;
use polywrap_tests_utils::mocks::{
Expand All @@ -22,7 +22,7 @@ struct EnvTwo {

#[test]
fn test_env_methods() {
let mut builder = PolywrapClientConfig::new();
let mut builder = ClientConfig::new();
let uri = uri!("wrap://mock/wrapper");

assert!(builder.envs.is_none());
Expand Down Expand Up @@ -74,7 +74,7 @@ fn test_interface_implementation_methods() {

let another_interface_uri = uri!("wrap://mock/another-interface");

let mut builder = PolywrapClientConfig::new();
let mut builder = ClientConfig::new();
assert!(builder.interfaces.is_none());
builder.add_interface_implementation(interface_uri.clone(), implementation_a_uri.clone());
builder.add_interface_implementation(another_interface_uri, implementation_b_uri.clone());
Expand All @@ -83,7 +83,7 @@ fn test_interface_implementation_methods() {
assert!(builder.interfaces.unwrap().len() == 2);

// Recreate builder again to test add interfaces implementations
let mut builder = PolywrapClientConfig::new();
let mut builder = ClientConfig::new();

assert!(builder.interfaces.is_none());

Expand Down Expand Up @@ -125,7 +125,7 @@ fn test_interface_implementation_methods() {

#[test]
fn test_redirects() {
let mut builder = PolywrapClientConfig::new();
let mut builder = ClientConfig::new();
assert!(builder.redirects.is_none());

let a_uri = uri!("mock/a");
Expand All @@ -146,7 +146,7 @@ fn test_redirects() {
let builder_redirects = builder.redirects.unwrap();
assert_eq!(builder_redirects, redirects);

let mut builder = PolywrapClientConfig::new();
let mut builder = ClientConfig::new();
assert!(builder.redirects.is_none());

builder.add_redirect(a_uri.clone(), b_uri.clone());
Expand All @@ -163,7 +163,7 @@ fn test_redirects() {

#[test]
fn test_packages() {
let mut builder = PolywrapClientConfig::new();
let mut builder = ClientConfig::new();
assert!(builder.packages.is_none());

let uri_a: Uri = String::from("wrap://package/a").try_into().unwrap();
Expand Down Expand Up @@ -192,7 +192,7 @@ fn test_packages() {

// We need to recreate the builder because when we do builder.packages.unwrap
// the ownership is given, not allowing us to call the builder again
let mut builder = PolywrapClientConfig::new();
let mut builder = ClientConfig::new();

let modified_uri_package_b = (uri_b.clone(), get_different_mock_package());

Expand All @@ -213,7 +213,7 @@ fn test_packages() {

#[test]
fn test_wrappers() {
let mut builder = PolywrapClientConfig::new();
let mut builder = ClientConfig::new();
assert!(builder.wrappers.is_none());

let uri_wrapper_a = (
Expand Down Expand Up @@ -242,7 +242,7 @@ fn test_wrappers() {

// We need to recreate the builder because when we do builder.wrappers.unwrap
// the ownership is given, not allowing us to call the builder again
let mut builder = PolywrapClientConfig::new();
let mut builder = ClientConfig::new();

let modified_uri_wrapper_b = (
String::from("wrap://wrapper/b").try_into().unwrap(),
Expand All @@ -268,7 +268,7 @@ fn test_wrappers() {

#[test]
fn test_resolvers() {
let mut builder = PolywrapClientConfig::new();
let mut builder = ClientConfig::new();
assert!(builder.resolvers.is_none());
builder.add_resolvers(vec![Arc::new(MockResolver {})]);
assert!(builder.resolvers.is_some());
Expand Down
Loading
Loading