Skip to content

Update indexes for v0.28.0 #315

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

Merged
merged 66 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
a37ffd3
Update task api v0.28.0
bidoubiwa Jul 7, 2022
b9ffd60
Update tests to be relevant with the structures where they are ran
bidoubiwa Jul 11, 2022
c527312
Update types in code-samples
bidoubiwa Jul 11, 2022
17d6c19
Remove clearAll task type
bidoubiwa Jul 11, 2022
ff0d350
Add index_uid as an optional in the Tasks
bidoubiwa Jul 11, 2022
9241a7b
Add comments on best builder implementation
bidoubiwa Jul 19, 2022
eb38d18
Add execute function on get_tasks
bidoubiwa Aug 2, 2022
d37be56
Update code samples
bidoubiwa Aug 3, 2022
61be5a5
Remove out of context comment
bidoubiwa Aug 3, 2022
7aa409b
Merge
bidoubiwa Aug 3, 2022
c968df3
Fix tests
bidoubiwa Aug 3, 2022
c21b18f
Fix pagination tests
bidoubiwa Aug 3, 2022
012f939
Update HTTP methods for v0.28.0
bidoubiwa Aug 3, 2022
0cb9e93
Fix clippy
bidoubiwa Aug 3, 2022
a485ba5
Merge branch 'update_task_api_for_v0.28.0' of github.com:meilisearch/…
bidoubiwa Aug 3, 2022
f86bff4
Remove comment of task tests since the tests are now sucesful
bidoubiwa Aug 3, 2022
734fd13
Fix doc tests
bidoubiwa Aug 3, 2022
e5821c4
Merge branch 'update_task_api_for_v0.28.0' of github.com:meilisearch/…
bidoubiwa Aug 3, 2022
11bfb7e
Update keys for v0.28.0
bidoubiwa Aug 4, 2022
6b70f5a
Fix get tasks inside index structure
bidoubiwa Aug 4, 2022
604e08d
Make description and name optional in keys
bidoubiwa Aug 8, 2022
67637c2
Fix none doc tests with new get_tasks api
bidoubiwa Aug 8, 2022
c2dcd92
Add from and limit in tasks params
bidoubiwa Aug 8, 2022
efff813
Add warning on failing test
bidoubiwa Aug 8, 2022
f0020b6
Merge branch 'update_task_api_for_v0.28.0' of https://github.com/meil…
bidoubiwa Aug 8, 2022
e0762b1
Merge
bidoubiwa Aug 8, 2022
c1796a3
Update keys design
bidoubiwa Aug 9, 2022
abc0f7b
Update task API
bidoubiwa Aug 9, 2022
eaef1ea
Remove useless comment
bidoubiwa Aug 9, 2022
bdf4f13
Merge branch 'update_task_api_for_v0.28.0' of https://github.com/meil…
bidoubiwa Aug 9, 2022
2441da1
Merge branch 'update_http_methods_for_v0.28.0' of https://github.com/…
bidoubiwa Aug 9, 2022
d506eae
Remove client as mandatory parameter for the keyUpdater
bidoubiwa Aug 10, 2022
c803fd5
Add doc and tests on doc
bidoubiwa Aug 10, 2022
cdc2a41
Fix docs tests on keys in client
bidoubiwa Aug 10, 2022
b2ba741
Fix docs tests
bidoubiwa Aug 10, 2022
24ff749
Remove dbg
bidoubiwa Aug 10, 2022
1b41330
Add with_uid filter
bidoubiwa Aug 10, 2022
f6f821d
Add new actions on key creation
bidoubiwa Aug 10, 2022
710b2d6
Remove new line at the start of docs
bidoubiwa Aug 10, 2022
54d29eb
Fix clippy errors
bidoubiwa Aug 10, 2022
2439778
Merge branch 'update_keys_for_v0.28.0' of https://github.com/meilisea…
bidoubiwa Aug 10, 2022
3989758
Rename type in Task structure
bidoubiwa Aug 10, 2022
668ba13
Removed useless newlines
bidoubiwa Aug 10, 2022
ac95329
Fix typo in comment
bidoubiwa Aug 10, 2022
66bd1a5
Add missing semi-column
bidoubiwa Aug 10, 2022
3adc25e
t checkout uMerge branch 'update_task_api_for_v0.28.0' of https://git…
bidoubiwa Aug 10, 2022
17f1ecf
Merge
bidoubiwa Aug 10, 2022
31b3941
Update indexes api for v0.28.0
bidoubiwa Aug 10, 2022
7865c1f
Merge
bidoubiwa Aug 22, 2022
027181b
Improve doc comments
bidoubiwa Aug 22, 2022
761a9df
Merge branch 'update_keys_for_v0.28.0' of github.com:meilisearch/meil…
bidoubiwa Aug 22, 2022
9b36f77
Change indexes methods
bidoubiwa Aug 23, 2022
335fbf1
Add index query and index updater
bidoubiwa Aug 23, 2022
7b5b5e2
Add documentation and doc tests on indexes routes
bidoubiwa Aug 24, 2022
3012f2a
Add tests on get indexes with params
bidoubiwa Aug 24, 2022
62e5f2c
Add test on index update
bidoubiwa Aug 24, 2022
555f7dd
Fix clippy
bidoubiwa Aug 24, 2022
c28c578
Improve limit to avoid flacky test
bidoubiwa Aug 24, 2022
9910283
Update src/client.rs
bidoubiwa Aug 24, 2022
0cbcaac
Update src/client.rs
bidoubiwa Aug 24, 2022
3e2e8bb
Fix merge conflicts
bidoubiwa Aug 25, 2022
f0220fe
Remove useless newlines
bidoubiwa Aug 25, 2022
f231ce4
Rollback changes on keys api
bidoubiwa Aug 25, 2022
9d37921
Fix duplicated closing bracket
bidoubiwa Aug 25, 2022
9cd259e
Fix failing tests
bidoubiwa Aug 25, 2022
f4e99a3
Remove useless comment
bidoubiwa Aug 25, 2022
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 .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
get_one_index_1: |-
let movies: Index = client.get_index("movies").await.unwrap();
list_all_indexes_1: |-
let indexes: Vec<Index> = client.list_all_indexes().await.unwrap();
let indexes: IndexesResults = client.list_all_indexes().await.unwrap();
create_an_index_1: |-
client.create_index("movies", Some("id")).await.unwrap();
update_an_index_1: |-
Expand Down
167 changes: 139 additions & 28 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,23 @@ impl Client {
}
}

/// List all [Index]es and returns values as instances of [Index].
fn parse_indexes_results_from_value(&self, value: Value) -> Result<IndexesResults, Error> {
let raw_indexes = value["results"].as_array().unwrap();

let indexes_results = IndexesResults {
limit: value["limit"].as_u64().unwrap() as u32,
offset: value["offset"].as_u64().unwrap() as u32,
total: value["total"].as_u64().unwrap() as u32,
results: raw_indexes
.iter()
.map(|raw_index| Index::from_value(raw_index.clone(), self.clone()))
.collect::<Result<_, _>>()?,
};

Ok(indexes_results)
}

/// List all [Index]es with query parameters and returns values as instances of [Index].
///
/// # Example
///
Expand All @@ -55,16 +71,44 @@ impl Client {
/// // create the client
/// let client = Client::new(MEILISEARCH_HOST, MEILISEARCH_API_KEY);
///
/// let indexes: Vec<Index> = client.list_all_indexes().await.unwrap();
/// let indexes: IndexesResults = client.list_all_indexes().await.unwrap();
/// println!("{:?}", indexes);
/// # });
/// ```
pub async fn list_all_indexes(&self) -> Result<Vec<Index>, Error> {
self.list_all_indexes_raw()
.await?
.into_iter()
.map(|index| Index::from_value(index, self.clone()))
.collect()
pub async fn list_all_indexes(&self) -> Result<IndexesResults, Error> {
let value = self.list_all_indexes_raw().await?;
let indexes_results = self.parse_indexes_results_from_value(value)?;
Ok(indexes_results)
}

/// List all [Index]es and returns values as instances of [Index].
///
/// # Example
///
/// ```
/// # use meilisearch_sdk::{client::*, indexes::*};
/// #
/// # let MEILISEARCH_HOST = option_env!("MEILISEARCH_HOST").unwrap_or("http://localhost:7700");
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
/// #
/// # futures::executor::block_on(async move {
/// // create the client
/// let client = Client::new(MEILISEARCH_HOST, MEILISEARCH_API_KEY);
/// let mut query = IndexesQuery::new(&client);
/// query.with_limit(1);
/// let indexes: IndexesResults = client.list_all_indexes_with(&query).await.unwrap();
///
/// assert_eq!(indexes.limit, 1);
/// # });
/// ```
pub async fn list_all_indexes_with(
&self,
indexes_query: &IndexesQuery<'_>,
) -> Result<IndexesResults, Error> {
let value = self.list_all_indexes_raw_with(indexes_query).await?;
let indexes_results = self.parse_indexes_results_from_value(value)?;

Ok(indexes_results)
}

/// List all [Index]es and returns as Json.
Expand All @@ -85,8 +129,8 @@ impl Client {
/// println!("{:?}", json_indexes);
/// # });
/// ```
pub async fn list_all_indexes_raw(&self) -> Result<Vec<Value>, Error> {
let json_indexes = request::<(), Vec<Value>>(
pub async fn list_all_indexes_raw(&self) -> Result<Value, Error> {
let json_indexes = request::<(), Value>(
&format!("{}/indexes", self.host),
&self.api_key,
Method::Get(()),
Expand All @@ -97,6 +141,42 @@ impl Client {
Ok(json_indexes)
}

/// List all [Index]es with query parameters and returns as Json.
///
/// # Example
///
/// ```
/// # use meilisearch_sdk::{client::*, indexes::*};
/// #
/// # let MEILISEARCH_HOST = option_env!("MEILISEARCH_HOST").unwrap_or("http://localhost:7700");
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
/// #
/// # futures::executor::block_on(async move {
/// // create the client
/// let client = Client::new(MEILISEARCH_HOST, MEILISEARCH_API_KEY);
///
/// let mut query = IndexesQuery::new(&client);
/// query.with_limit(1);
/// let json_indexes = client.list_all_indexes_raw_with(&query).await.unwrap();
///
/// println!("{:?}", json_indexes);
/// # });
/// ```
pub async fn list_all_indexes_raw_with(
&self,
indexes_query: &IndexesQuery<'_>,
) -> Result<Value, Error> {
let json_indexes = request::<&IndexesQuery, Value>(
&format!("{}/indexes", self.host),
&self.api_key,
Method::Get(indexes_query),
200,
)
.await?;

Ok(json_indexes)
}

/// Get an [Index], this index should already exist.
///
/// # Example
Expand Down Expand Up @@ -158,13 +238,7 @@ impl Client {

/// Create a corresponding object of an [Index] without any check or doing an HTTP call.
pub fn index(&self, uid: impl Into<String>) -> Index {
Index {
uid: Arc::new(uid.into()),
client: self.clone(),
primary_key: None,
created_at: None,
updated_at: None,
}
Index::new(uid, self.clone())
}

/// Create an [Index].
Expand Down Expand Up @@ -225,15 +299,31 @@ impl Client {
}

/// Alias for [Client::list_all_indexes].
pub async fn get_indexes(&self) -> Result<Vec<Index>, Error> {
pub async fn get_indexes(&self) -> Result<IndexesResults, Error> {
self.list_all_indexes().await
}

/// Alias for [Client::list_all_indexes_with].
pub async fn get_indexes_with(
&self,
indexes_query: &IndexesQuery<'_>,
) -> Result<IndexesResults, Error> {
self.list_all_indexes_with(indexes_query).await
}

/// Alias for [Client::list_all_indexes_raw].
pub async fn get_indexes_raw(&self) -> Result<Vec<Value>, Error> {
pub async fn get_indexes_raw(&self) -> Result<Value, Error> {
self.list_all_indexes_raw().await
}

/// Alias for [Client::list_all_indexes_raw_with].
pub async fn get_indexes_raw_with(
&self,
indexes_query: &IndexesQuery<'_>,
) -> Result<Value, Error> {
self.list_all_indexes_raw_with(indexes_query).await
}

/// Get stats of all indexes.
///
/// # Example
Expand Down Expand Up @@ -873,6 +963,7 @@ mod tests {
}

#[meilisearch_test]

async fn test_error_delete_key(mut client: Client, name: String) {
// ==> accessing a key that does not exist
let error = client.delete_key("invalid_key").await.unwrap_err();
Expand All @@ -887,9 +978,9 @@ mod tests {

// ==> executing the action without enough right
let mut key = KeyBuilder::new();

key.with_name(&name);
let key = client.create_key(key).await.unwrap();

let master_key = client.api_key.clone();
// this key has no right
client.api_key = Arc::new(key.key.clone());
Expand Down Expand Up @@ -1058,19 +1149,39 @@ mod tests {
}

#[meilisearch_test]
async fn test_list_all_indexes(client: Client, index: Index) {
async fn test_list_all_indexes(client: Client) {
let all_indexes = client.list_all_indexes().await.unwrap();
assert!(all_indexes.len() > 0);
assert!(all_indexes.iter().any(|idx| idx.uid == index.uid));

assert_eq!(all_indexes.limit, 20);
assert_eq!(all_indexes.offset, 0);
}

#[meilisearch_test]
async fn test_list_all_indexes_raw(client: Client, index: Index) {
async fn test_list_all_indexes_with_params(client: Client) {
let mut query = IndexesQuery::new(&client);
query.with_limit(1);
let all_indexes = client.list_all_indexes_with(&query).await.unwrap();

assert_eq!(all_indexes.limit, 1);
assert_eq!(all_indexes.offset, 0);
}

#[meilisearch_test]
async fn test_list_all_indexes_raw(client: Client) {
let all_indexes_raw = client.list_all_indexes_raw().await.unwrap();
assert!(all_indexes_raw.len() > 0);
assert!(all_indexes_raw
.iter()
.any(|idx| idx["uid"] == json!(index.uid.to_string())));

assert_eq!(all_indexes_raw["limit"], json!(20));
assert_eq!(all_indexes_raw["offset"], json!(0));
}

#[meilisearch_test]
async fn test_list_all_indexes_raw_with_params(client: Client) {
let mut query = IndexesQuery::new(&client);
query.with_limit(1);
let all_indexes_raw = client.list_all_indexes_raw_with(&query).await.unwrap();

assert_eq!(all_indexes_raw["limit"], json!(1));
assert_eq!(all_indexes_raw["offset"], json!(0));
}

#[meilisearch_test]
Expand Down
Loading