Skip to content

Commit

Permalink
Merge branch 'main' into issue-503
Browse files Browse the repository at this point in the history
  • Loading branch information
curquiza authored Jun 11, 2024
2 parents a23fe34 + 9e57f3e commit 6643bc7
Show file tree
Hide file tree
Showing 19 changed files with 176 additions and 34 deletions.
7 changes: 5 additions & 2 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ update_settings_1: |-
"release_date:desc",
"rank:desc"
])
.with_distinct_attribute("movie_id")
.with_distinct_attribute(Some("movie_id"))
.with_searchable_attributes([
"title",
"overview",
Expand Down Expand Up @@ -993,7 +993,7 @@ primary_field_guide_add_document_primary_key: |-
getting_started_add_documents_md: |-
```toml
[dependencies]
meilisearch-sdk = "0.26.0"
meilisearch-sdk = "0.26.1"
# futures: because we want to block on futures
futures = "0.3"
# serde: required if you are going to use documents
Expand Down Expand Up @@ -1641,5 +1641,8 @@ facet_search_3: |-
.facet_search("genres")
.with_facet_query("c")
.execute()
create_snapshot_1: |-
client
.create_snapshot()
.await
.unwrap();
4 changes: 3 additions & 1 deletion .github/release-draft-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@ replacers:
replace: ''
- search: '/(?:and )?@bors(?:\[bot\])?,?/g'
replace: ''
- search: '/(?:and )?@meili-bot,?/g'
- search: '/(?:and )?@meili-bot(?:\[bot\])?,?/g'
replace: ''
- search: '/(?:and )?@meili-bors(?:\[bot\])?,?/g'
replace: ''
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "meilisearch-sdk"
version = "0.26.0"
version = "0.26.1"
authors = ["Mubelotix <[email protected]>"]
edition = "2018"
description = "Rust wrapper for the Meilisearch API. Meilisearch is a powerful, fast, open-source, easy to use and deploy search engine."
Expand All @@ -18,10 +18,10 @@ log = "0.4"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
time = { version = "0.3.7", features = ["serde-well-known", "formatting", "parsing"] }
yaup = "0.2.0"
yaup = "0.3.1"
either = { version = "1.8.0", features = ["serde"] }
thiserror = "1.0.37"
meilisearch-index-setting-macro = { path = "meilisearch-index-setting-macro", version = "0.26.0" }
meilisearch-index-setting-macro = { path = "meilisearch-index-setting-macro", version = "0.26.1" }
pin-project-lite = { version = "0.2.13", optional = true }
reqwest = { version = "0.12.3", optional = true, default-features = false, features = ["rustls-tls", "http2", "stream"] }
bytes = { version = "1.6", optional = true }
Expand All @@ -40,6 +40,7 @@ wasm-bindgen-futures = "0.4"
[features]
default = ["reqwest"]
reqwest = ["dep:reqwest", "pin-project-lite", "bytes"]
futures-unsend = []

[dev-dependencies]
futures-await-test = "0.3"
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ To use `meilisearch-sdk`, add this to your `Cargo.toml`:

```toml
[dependencies]
meilisearch-sdk = "0.26.0"
meilisearch-sdk = "0.26.1"
```

The following optional dependencies may also be useful:
Expand Down Expand Up @@ -244,6 +244,11 @@ Json output:
By default, the SDK uses [`reqwest`](https://docs.rs/reqwest/latest/reqwest/) to make http calls.
The SDK lets you customize the http client by implementing the `HttpClient` trait yourself and
initializing the `Client` with the `new_with_client` method.
You may be interested by the `futures-unsend` feature which lets you specify a non-Send http client.

#### Wasm support <!-- omit in TOC -->

The SDK supports wasm through reqwest. You'll need to enable the `futures-unsend` feature while importing it, though.

## 🌐 Running in the Browser with WASM <!-- omit in TOC -->

Expand Down
2 changes: 1 addition & 1 deletion README.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ To use `meilisearch-sdk`, add this to your `Cargo.toml`:

```toml
[dependencies]
meilisearch-sdk = "0.26.0"
meilisearch-sdk = "0.26.1"
```

The following optional dependencies may also be useful:
Expand Down
5 changes: 3 additions & 2 deletions examples/cli-app-with-awc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
meilisearch-sdk = { path = "../..", default-features = false }
meilisearch-sdk = { path = "../..", default-features = false, features = ["futures-unsend"] }
futures = "0.3"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
lazy_static = "1.4.0"
awc = "3.4"
async-trait = "0.1.51"
tokio = { version = "1.27.0", features = ["full"] }
yaup = "0.2.0"
yaup = "0.3.0"
tokio-util = { version = "0.7.10", features = ["full"] }
actix-rt = "2.9.0"
anyhow = "1.0.82"
8 changes: 4 additions & 4 deletions examples/cli-app-with-awc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,23 @@ impl HttpClient for AwcClient {
.content_type(content_type)
.send_stream(stream)
.await
.map_err(|err| Error::Other(Box::new(err)))?
.map_err(|err| Error::Other(anyhow::anyhow!(err.to_string()).into()))?
} else {
request
.send()
.await
.map_err(|err| Error::Other(Box::new(err)))?
.map_err(|err| Error::Other(anyhow::anyhow!(err.to_string()).into()))?
};

let status = response.status().as_u16();
let mut body = String::from_utf8(
response
.body()
.await
.map_err(|err| Error::Other(Box::new(err)))?
.map_err(|err| Error::Other(anyhow::anyhow!(err.to_string()).into()))?
.to_vec(),
)
.map_err(|err| Error::Other(Box::new(err)))?;
.map_err(|err| Error::Other(anyhow::anyhow!(err.to_string()).into()))?;

if body.is_empty() {
body = "null".to_string();
Expand Down
2 changes: 1 addition & 1 deletion examples/cli-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ futures = "0.3"
serde = { version="1.0", features = ["derive"] }
serde_json = "1.0"
lazy_static = "1.4.0"
yaup = "0.2.0"
yaup = "0.3.0"
2 changes: 1 addition & 1 deletion examples/web_app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ serde_json = "1.0"
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4.18"
yew = {version="0.21", features = ["csr"]}
meilisearch-sdk = {path="../.."}
meilisearch-sdk = { path="../..", features = ["futures-unsend"] }
lazy_static = "1.4"
serde = {version="1.0", features=["derive"]}
web-sys = "0.3"
Expand Down
2 changes: 1 addition & 1 deletion examples/web_app_graphql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ meilisearch-sdk = "0.24.3"
serde = { version = "1.0.192", features = ["derive"] }
serde_json = "1.0.108"
thiserror = "1.0.51"
validator = { version = "0.17.0", features = ["derive"] }
validator = { version = "0.18.1", features = ["derive"] }
2 changes: 1 addition & 1 deletion meilisearch-index-setting-macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "meilisearch-index-setting-macro"
version = "0.26.0"
version = "0.26.1"
description = "Helper tool to generate settings of a Meilisearch index"
edition = "2021"
license = "MIT"
Expand Down
10 changes: 6 additions & 4 deletions meilisearch-index-setting-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ fn get_index_config_implementation(
get_settings_token_for_list(&filterable_attributes, "with_filterable_attributes");
let searchable_attr_tokens =
get_settings_token_for_list(&searchable_attributes, "with_searchable_attributes");
let distinct_attr_token =
get_settings_token_for_string(&distinct_key_attribute, "with_distinct_attribute");
let distinct_attr_token = get_settings_token_for_string_for_some_string(
&distinct_key_attribute,
"with_distinct_attribute",
);

quote! {
#[::meilisearch_sdk::macro_helper::async_trait(?Send)]
Expand Down Expand Up @@ -173,7 +175,7 @@ fn get_settings_token_for_list(
}
}

fn get_settings_token_for_string(
fn get_settings_token_for_string_for_some_string(
field_name: &String,
method_name: &str,
) -> proc_macro2::TokenStream {
Expand All @@ -183,7 +185,7 @@ fn get_settings_token_for_string(
proc_macro2::TokenStream::new()
} else {
quote! {
.#method_ident(#field_name)
.#method_ident(::std::option::Option::Some(#field_name))
}
}
}
4 changes: 2 additions & 2 deletions src/dumps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//!
//! # Example
//!
//! ```no_run
//! ```
//! # use meilisearch_sdk::{client::*, errors::*, dumps::*, dumps::*, task_info::*, tasks::*};
//! # use futures_await_test::async_test;
//! # use std::{thread::sleep, time::Duration};
Expand Down Expand Up @@ -50,7 +50,7 @@ impl<Http: HttpClient> Client<Http> {
///
/// # Example
///
/// ```no_run
/// ```
/// # use meilisearch_sdk::{client::*, errors::*, dumps::*, dumps::*, task_info::*, tasks::*};
/// # use futures_await_test::async_test;
/// # use std::{thread::sleep, time::Duration};
Expand Down
4 changes: 2 additions & 2 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub enum Error {
InvalidUuid4Version,

#[error(transparent)]
Other(Box<dyn std::error::Error>),
Other(Box<dyn std::error::Error + Send + Sync + 'static>),
}

#[derive(Debug, Clone, Deserialize, Error)]
Expand Down Expand Up @@ -412,7 +412,7 @@ mod test {
"Impossible to generate the token, jsonwebtoken encountered an error: InvalidToken"
);

let error = Error::Yaup(yaup::error::Error::Custom("Test yaup error".to_string()));
let error = Error::Yaup(yaup::Error::Custom("Test yaup error".to_string()));
assert_eq!(
error.to_string(),
"Internal Error: could not parse the query parameters: Test yaup error"
Expand Down
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@
//! By default, the SDK uses [`reqwest`](https://docs.rs/reqwest/latest/reqwest/) to make http calls.
//! The SDK lets you customize the http client by implementing the `HttpClient` trait yourself and
//! initializing the `Client` with the `new_with_client` method.
//! You may be interested by the `futures-unsend` feature which lets you specify a non-Send http client.
//!
//! ### Wasm support <!-- omit in TOC -->
//!
//! The SDK supports wasm through reqwest. You'll need to enable the `futures-unsend` feature while importing it, though.
#![warn(clippy::all)]
#![allow(clippy::needless_doctest_main)]

Expand All @@ -244,6 +249,8 @@ pub mod request;
pub mod search;
/// Module containing [`Settings`].
pub mod settings;
/// Module containing the [snapshots] trait.
pub mod snapshots;
/// Module representing the [`TaskInfo`]s.
pub mod task_info;
/// Module representing the [`Task`]s.
Expand Down
6 changes: 4 additions & 2 deletions src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ impl<Q, B> Method<Q, B> {
}
}

#[async_trait(?Send)]
#[cfg_attr(feature = "futures-unsend", async_trait(?Send))]
#[cfg_attr(not(feature = "futures-unsend"), async_trait)]
pub trait HttpClient: Clone + Send + Sync {
async fn request<Query, Body, Output>(
&self,
Expand Down Expand Up @@ -143,7 +144,8 @@ pub fn parse_response<Output: DeserializeOwned>(
}
}

#[async_trait(?Send)]
#[cfg_attr(feature = "futures-unsend", async_trait(?Send))]
#[cfg_attr(not(feature = "futures-unsend"), async_trait)]
impl HttpClient for Infallible {
async fn request<Query, Body, Output>(
&self,
Expand Down
7 changes: 4 additions & 3 deletions src/reqwest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl ReqwestClient {
);
#[cfg(target_arch = "wasm32")]
headers.insert(
header::HeaderName::from_static("X-Meilisearch-Client"),
header::HeaderName::from_static("x-meilisearch-client"),
header::HeaderValue::from_str(&qualified_version()).unwrap(),
);

Expand All @@ -50,7 +50,8 @@ impl ReqwestClient {
}
}

#[async_trait(?Send)]
#[cfg_attr(feature = "futures-unsend", async_trait(?Send))]
#[cfg_attr(not(feature = "futures-unsend"), async_trait)]
impl HttpClient for ReqwestClient {
async fn stream_request<
Query: Serialize + Send + Sync,
Expand All @@ -71,7 +72,7 @@ impl HttpClient for ReqwestClient {
let url = if query.is_empty() {
url.to_string()
} else {
format!("{url}?{query}")
format!("{url}{query}")
};

let mut request = self.client.request(verb(&method), &url);
Expand Down
8 changes: 5 additions & 3 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub struct Settings {
pub sortable_attributes: Option<Vec<String>>,
/// Search returns documents with distinct (different) values of the given field.
#[serde(skip_serializing_if = "Option::is_none")]
pub distinct_attribute: Option<String>,
pub distinct_attribute: Option<Option<String>>,
/// Fields in which to search for matching query words sorted by order of importance.
#[serde(skip_serializing_if = "Option::is_none")]
pub searchable_attributes: Option<Vec<String>>,
Expand Down Expand Up @@ -217,9 +217,11 @@ impl Settings {
}

#[must_use]
pub fn with_distinct_attribute(self, distinct_attribute: impl AsRef<str>) -> Settings {
pub fn with_distinct_attribute(self, distinct_attribute: Option<impl AsRef<str>>) -> Settings {
Settings {
distinct_attribute: Some(distinct_attribute.as_ref().to_string()),
distinct_attribute: Some(
distinct_attribute.map(|distinct| distinct.as_ref().to_string()),
),
..self
}
}
Expand Down
Loading

0 comments on commit 6643bc7

Please sign in to comment.