diff --git a/openapi.yml b/openapi.yml index b9d510c..3db4b12 100644 --- a/openapi.yml +++ b/openapi.yml @@ -495,7 +495,7 @@ paths: content: application/json: schema: - $ref: "#/components/schemas/SynonymSetRetrieveSchema" + $ref: "#/components/schemas/SynonymSetSchema" "404": description: Synonym set not found content: @@ -735,7 +735,7 @@ paths: content: application/json: schema: - $ref: "#/components/schemas/CurationSetRetrieveSchema" + $ref: "#/components/schemas/CurationSetSchema" "404": description: Curation set not found content: @@ -4432,8 +4432,6 @@ components: items: $ref: "#/components/schemas/SynonymSetSchema" - SynonymSetRetrieveSchema: - $ref: "#/components/schemas/SynonymSetCreateSchema" SynonymSetDeleteSchema: type: object @@ -4595,9 +4593,6 @@ components: type: string description: document id that should be excluded from the search results. - CurationSetRetrieveSchema: - $ref: '#/components/schemas/CurationSetCreateSchema' - CurationSetDeleteSchema: type: object required: diff --git a/preprocessed_openapi.yml b/preprocessed_openapi.yml index 48702e1..229d79c 100644 --- a/preprocessed_openapi.yml +++ b/preprocessed_openapi.yml @@ -883,7 +883,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/SynonymSetRetrieveSchema' + $ref: '#/components/schemas/SynonymSetSchema' '404': description: Synonym set not found content: @@ -1118,7 +1118,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/CurationSetRetrieveSchema' + $ref: '#/components/schemas/CurationSetSchema' '404': description: Curation set not found content: @@ -4924,8 +4924,6 @@ components: description: Array of synonym sets items: $ref: '#/components/schemas/SynonymSetSchema' - SynonymSetRetrieveSchema: - $ref: '#/components/schemas/SynonymSetCreateSchema' SynonymSetDeleteSchema: type: object required: @@ -5074,8 +5072,6 @@ components: id: type: string description: document id that should be excluded from the search results. - CurationSetRetrieveSchema: - $ref: '#/components/schemas/CurationSetCreateSchema' CurationSetDeleteSchema: type: object required: diff --git a/typesense/src/client/curation_set/item.rs b/typesense/src/client/curation_set/item.rs new file mode 100644 index 0000000..fca8cfc --- /dev/null +++ b/typesense/src/client/curation_set/item.rs @@ -0,0 +1,57 @@ +//! Provides access to the API endpoints for managing a curation set item. +//! +//! Curation sets allow you to include or exclude specific documents for a given query. +//! +//! A `CurationSetItem` instance is created via the main `client.curation_set("curation_set_name").item("item_id")` method. +use crate::{Client, Error, execute_wrapper}; +use typesense_codegen::{ + apis::curation_sets_api::{self, RetrieveCurationSetItemParams}, + models, +}; + +/// Provides methods for managing a curation set item. +/// +/// This struct is created by calling `client.curation_set("curation_set_name").item("item_id")`. +pub struct CurationSetItem<'a> { + pub(super) client: &'a Client, + pub(super) curation_set_name: &'a str, + pub(super) item_id: &'a str, +} + +impl<'a> CurationSetItem<'a> { + /// Creates a new `CurationSetItem` instance. + #[inline] + pub(super) fn new(client: &'a Client, curation_set_name: &'a str, item_id: &'a str) -> Self { + Self { + client, + curation_set_name, + item_id, + } + } + + /// Retrieve this curation set item. + pub async fn retrieve( + &self, + ) -> Result> + { + let params = RetrieveCurationSetItemParams { + curation_set_name: self.curation_set_name.into(), + item_id: self.item_id.into(), + }; + execute_wrapper!(self, curation_sets_api::retrieve_curation_set_item, params) + } + + /// Delete this curation set item. + pub async fn delete( + &self, + ) -> Result< + models::CurationItemDeleteSchema, + Error, + > { + let params = curation_sets_api::DeleteCurationSetItemParams { + curation_set_name: self.curation_set_name.into(), + item_id: self.item_id.into(), + }; + execute_wrapper!(self, curation_sets_api::delete_curation_set_item, params) + } +} diff --git a/typesense/src/client/curation_set/items.rs b/typesense/src/client/curation_set/items.rs new file mode 100644 index 0000000..decaa35 --- /dev/null +++ b/typesense/src/client/curation_set/items.rs @@ -0,0 +1,64 @@ +//! Provides access to the API endpoints for managing items of a curation set. +//! +//! Curation sets allow you to include or exclude specific documents for a given query. +//! +//! A `CurationSetItems` instance is created via the main `client.curation_set("curation_set_name").items()` method. + +use ::std::borrow::Cow; + +use crate::{Client, Error, execute_wrapper}; +use typesense_codegen::{ + apis::curation_sets_api::{self, RetrieveCurationSetItemsParams}, + models, +}; + +/// Provides methods for managing items of a curation set. +/// +/// This struct is created by calling `client.curation_set("curation_set_name").items()`. +pub struct CurationSetItems<'a> { + pub(super) client: &'a Client, + pub(super) curation_set_name: &'a str, +} + +impl<'a> CurationSetItems<'a> { + /// Creates a new `CurationSetItems` instance. + #[inline] + pub(super) fn new(client: &'a Client, curation_set_name: &'a str) -> Self { + Self { + client, + curation_set_name, + } + } + + /// Retrieves all the items of this curation set. + pub async fn retrieve( + &self, + ) -> Result< + Vec, + Error, + > { + let params = RetrieveCurationSetItemsParams { + curation_set_name: self.curation_set_name.into(), + }; + execute_wrapper!(self, curation_sets_api::retrieve_curation_set_items, params) + } + + /// Creates or updates an existing item of a curation set. + /// + /// # Arguments + /// * `item_id` - The id of the curation set item to create or update. + /// * `schema` - A `CurationItemCreateSchema` object. + pub async fn upsert( + &self, + item_id: impl Into>, + schema: models::CurationItemCreateSchema<'_>, + ) -> Result> + { + let params = curation_sets_api::UpsertCurationSetItemParams { + item_id: item_id.into(), + curation_set_name: self.curation_set_name.into(), + curation_item_create_schema: schema, + }; + execute_wrapper!(self, curation_sets_api::upsert_curation_set_item, params) + } +} diff --git a/typesense/src/client/curation_set/mod.rs b/typesense/src/client/curation_set/mod.rs new file mode 100644 index 0000000..c9f87e3 --- /dev/null +++ b/typesense/src/client/curation_set/mod.rs @@ -0,0 +1,68 @@ +//! Provides access to the API endpoints for managing a specific curation set. +//! +//! Curation sets allow you to include or exclude specific documents for a given query. +//! +//! A `CurationSet` instance is created via the main `client.curation_set("curation_set_name")` method. + +mod item; +mod items; + +use crate::{Client, Error, execute_wrapper}; +use item::CurationSetItem; +use items::CurationSetItems; +use typesense_codegen::{ + apis::curation_sets_api::{self, RetrieveCurationSetParams}, + models, +}; + +/// Provides methods for managing a specific curation set. +/// +/// This struct is created by calling `client.curation_set("curation_set_name")`. +pub struct CurationSet<'a> { + pub(super) client: &'a Client, + pub(super) curation_set_name: &'a str, +} + +impl<'a> CurationSet<'a> { + /// Creates a new `CurationSet` instance. + #[inline] + pub(super) fn new(client: &'a Client, curation_set_name: &'a str) -> Self { + Self { + client, + curation_set_name, + } + } + + /// Provides access to the items of this curation set. + #[inline] + pub fn items(&self) -> CurationSetItems<'_> { + CurationSetItems::new(self.client, self.curation_set_name) + } + + /// Provides access to this specific item of this curation set. + #[inline] + pub fn item(&self, item_id: &'a str) -> CurationSetItem<'a> { + CurationSetItem::new(self.client, self.curation_set_name, item_id) + } + + /// Retrieves the details of this curation set. + pub async fn retrieve( + &self, + ) -> Result> { + let params = RetrieveCurationSetParams { + curation_set_name: self.curation_set_name.into(), + }; + execute_wrapper!(self, curation_sets_api::retrieve_curation_set, params) + } + + /// Delete this curation set. + pub async fn delete( + &self, + ) -> Result> + { + let params = curation_sets_api::DeleteCurationSetParams { + curation_set_name: self.curation_set_name.into(), + }; + execute_wrapper!(self, curation_sets_api::delete_curation_set, params) + } +} diff --git a/typesense/src/client/curation_sets.rs b/typesense/src/client/curation_sets.rs new file mode 100644 index 0000000..d8941cb --- /dev/null +++ b/typesense/src/client/curation_sets.rs @@ -0,0 +1,49 @@ +//! Provides access to the API endpoints for managing curation sets. +//! +//! Curation sets allow you to include or exclude specific documents for a given query. +//! +//! A `CurationSets` instance is created via the main `client.curation_sets()` method. + +use crate::{Client, Error, execute_wrapper}; +use ::std::borrow::Cow; +use typesense_codegen::{apis::curation_sets_api, models}; + +/// Provides methods for managing all of your Typesense curation sets. +/// +/// This struct is created by calling `client.curation_sets()`. +pub struct CurationSets<'a> { + pub(super) client: &'a Client, +} + +impl<'a> CurationSets<'a> { + /// Creates a new `CurationSets` instance. + #[inline] + pub(super) fn new(client: &'a Client) -> Self { + Self { client } + } + + /// Retrieves the details of all curation sets. + pub async fn retrieve( + &self, + ) -> Result, Error> + { + execute_wrapper!(self, curation_sets_api::retrieve_curation_sets) + } + + /// Creates or updates an existing curation set. + /// + /// # Arguments + /// * `name` - The name of the curation set to create or update. + /// * `schema` - A `CurationSetCreateSchema` object. + pub async fn upsert( + &self, + name: impl Into>, + schema: models::CurationSetCreateSchema<'_>, + ) -> Result> { + let params = curation_sets_api::UpsertCurationSetParams { + curation_set_name: name.into(), + curation_set_create_schema: schema, + }; + execute_wrapper!(self, curation_sets_api::upsert_curation_set, params) + } +} diff --git a/typesense/src/client/mod.rs b/typesense/src/client/mod.rs index a20b4d8..8a5f1e6 100644 --- a/typesense/src/client/mod.rs +++ b/typesense/src/client/mod.rs @@ -112,6 +112,8 @@ mod analytics; mod collection; mod collections; mod conversations; +mod curation_set; +mod curation_sets; mod key; mod keys; mod multi_search; @@ -121,6 +123,8 @@ mod presets; mod stemming; mod stopword; mod stopwords; +mod synonym_set; +mod synonym_sets; use crate::{Error, traits::Document}; use alias::Alias; @@ -129,6 +133,8 @@ use analytics::Analytics; use collection::Collection; use collections::Collections; use conversations::Conversations; +use curation_set::CurationSet; +use curation_sets::CurationSets; use key::Key; use keys::Keys; use operations::Operations; @@ -137,6 +143,8 @@ use presets::Presets; use stemming::Stemming; use stopword::Stopword; use stopwords::Stopwords; +use synonym_set::SynonymSet; +use synonym_sets::SynonymSets; #[cfg(not(target_arch = "wasm32"))] use reqwest_middleware::ClientBuilder as ReqwestMiddlewareClientBuilder; @@ -624,6 +632,54 @@ impl Client { Conversations::new(self) } + /// Provides access to endpoints for managing curation sets. + /// # Example + /// ```no_run + /// # #[cfg(not(target_family = "wasm"))] + /// # { + /// # use typesense::Client; + /// # + /// # #[tokio::main] + /// # async fn main() -> Result<(), Box> { + /// # let client = Client::builder() + /// # .nodes(vec!["http://localhost:8108"]) + /// # .api_key("xyz") + /// # .build() + /// # .unwrap(); + /// let curation_sets = client.curation_sets().retrieve().await.unwrap(); + /// # Ok(()) + /// # } + /// # } + /// ``` + #[inline] + pub fn curation_sets(&self) -> CurationSets<'_> { + CurationSets::new(self) + } + + /// Provides access to endpoints for managing a specific curation set. + /// # Example + /// ```no_run + /// # #[cfg(not(target_family = "wasm"))] + /// # { + /// # use typesense::Client; + /// # + /// # #[tokio::main] + /// # async fn main() -> Result<(), Box> { + /// # let client = Client::builder() + /// # .nodes(vec!["http://localhost:8108"]) + /// # .api_key("xyz") + /// # .build() + /// # .unwrap(); + /// let curation_set = client.curation_set("curation_set_name").retrieve().await.unwrap(); + /// # Ok(()) + /// # } + /// # } + /// ``` + #[inline] + pub fn curation_set<'a>(&'a self, curation_set_name: &'a str) -> CurationSet<'a> { + CurationSet::new(self, curation_set_name) + } + /// Provides access to endpoints for managing the collection of API keys. /// /// # Example @@ -873,6 +929,59 @@ impl Client { pub fn stopword<'a>(&'a self, set_id: &'a str) -> Stopword<'a> { Stopword::new(self, set_id) } + + /// Provides access to endpoints for managing all synonym sets. + /// + /// # Example + /// ```no_run + /// # #[cfg(not(target_family = "wasm"))] + /// # { + /// # use typesense::Client; + /// # + /// # #[tokio::main] + /// # async fn main() -> Result<(), Box> { + /// # let client = Client::builder() + /// # .nodes(vec!["http://localhost:8108"]) + /// # .api_key("xyz") + /// # .build() + /// # .unwrap(); + /// let all_synonym_sets = client.synonym_sets().retrieve().await.unwrap(); + /// # Ok(()) + /// # } + /// # } + /// ``` + #[inline] + pub fn synonym_sets(&self) -> SynonymSets<'_> { + SynonymSets::new(self) + } + + /// Provides access to endpoints for managing a single synonym set. + /// + /// # Arguments + /// * `synonym_set_name` - The name of the synonym set to manage. + /// + /// # Example + /// ```no_run + /// # #[cfg(not(target_family = "wasm"))] + /// # { + /// # use typesense::Client; + /// # + /// # #[tokio::main] + /// # async fn main() -> Result<(), Box> { + /// # let client = Client::builder() + /// # .nodes(vec!["http://localhost:8108"]) + /// # .api_key("xyz") + /// # .build() + /// # .unwrap(); + /// let my_synonym_set = client.synonym_set("synonym_set_name").retrieve().await.unwrap(); + /// # Ok(()) + /// # } + /// # } + /// ``` + #[inline] + pub fn synonym_set<'a>(&'a self, synonym_set_name: &'a str) -> SynonymSet<'a> { + SynonymSet::new(self, synonym_set_name) + } } /// A helper function to determine if an error is worth retrying on another node. diff --git a/typesense/src/client/synonym_set/item.rs b/typesense/src/client/synonym_set/item.rs new file mode 100644 index 0000000..e30c9ba --- /dev/null +++ b/typesense/src/client/synonym_set/item.rs @@ -0,0 +1,52 @@ +//! Provides access to the API endpoints for managing a synonym set item. +//! +//! Synonym sets allows you to define search terms that should be considered equivalent. +//! +//! A `SynonymSetItem` instance is created via the main `client.synonym_set("synonym_set_name").item("item_id")` method. + +use crate::{Client, Error, execute_wrapper}; +use typesense_codegen::{apis::synonyms_api, models}; + +/// Provides methods for managing a synonym set item. +/// +/// This struct is created by calling `client.synonym_set("synonym_set_name").item("item_id")`. +pub struct SynonymSetItem<'a> { + pub(super) client: &'a Client, + pub(super) synonym_set_name: &'a str, + pub(super) item_id: &'a str, +} + +impl<'a> SynonymSetItem<'a> { + /// Creates a new `SynonymSetItem` instance. + #[inline] + pub(super) fn new(client: &'a Client, synonym_set_name: &'a str, item_id: &'a str) -> Self { + Self { + client, + synonym_set_name, + item_id, + } + } + + /// Retrieve this synonym set item. + pub async fn retrieve( + &self, + ) -> Result> { + let params = synonyms_api::RetrieveSynonymSetItemParams { + synonym_set_name: self.synonym_set_name.into(), + item_id: self.item_id.into(), + }; + execute_wrapper!(self, synonyms_api::retrieve_synonym_set_item, params) + } + + /// Delete this synonym set item. + pub async fn delete( + &self, + ) -> Result> + { + let params = synonyms_api::DeleteSynonymSetItemParams { + synonym_set_name: self.synonym_set_name.into(), + item_id: self.item_id.into(), + }; + execute_wrapper!(self, synonyms_api::delete_synonym_set_item, params) + } +} diff --git a/typesense/src/client/synonym_set/items.rs b/typesense/src/client/synonym_set/items.rs new file mode 100644 index 0000000..7ff3492 --- /dev/null +++ b/typesense/src/client/synonym_set/items.rs @@ -0,0 +1,58 @@ +//! Provides access to the API endpoints for managing items of a synonym set. +//! +//! Synonym sets allows you to define search terms that should be considered equivalent. +//! +//! A `SynonymSetItems` instance is created via the main `client.synonym_set("synonym_set_name").items()` method. + +use ::std::borrow::Cow; + +use crate::{Client, Error, execute_wrapper}; +use typesense_codegen::{apis::synonyms_api, models}; + +/// Provides methods for managing items of a synonym set. +/// +/// This struct is created by calling `client.synonym_set("synonym_set_name").items()`. +pub struct SynonymSetItems<'a> { + pub(super) client: &'a Client, + pub(super) synonym_set_name: &'a str, +} + +impl<'a> SynonymSetItems<'a> { + /// Creates a new `SynonymSetItems` instance. + #[inline] + pub(super) fn new(client: &'a Client, synonym_set_name: &'a str) -> Self { + Self { + client, + synonym_set_name, + } + } + + /// Retrieves all the items of this synonym set. + pub async fn retrieve( + &self, + ) -> Result, Error> + { + let params = synonyms_api::RetrieveSynonymSetItemsParams { + synonym_set_name: self.synonym_set_name.into(), + }; + execute_wrapper!(self, synonyms_api::retrieve_synonym_set_items, params) + } + + /// Creates or updates an existing item of a synonym set. + /// + /// # Arguments + /// * `item_id` - The id of the synonym set item to create or update. + /// * `schema` - A `SynonymItemUpsertSchema` object. + pub async fn upsert( + &self, + item_id: impl Into>, + schema: models::SynonymItemUpsertSchema<'_>, + ) -> Result> { + let params = synonyms_api::UpsertSynonymSetItemParams { + item_id: item_id.into(), + synonym_set_name: self.synonym_set_name.into(), + synonym_item_upsert_schema: schema, + }; + execute_wrapper!(self, synonyms_api::upsert_synonym_set_item, params) + } +} diff --git a/typesense/src/client/synonym_set/mod.rs b/typesense/src/client/synonym_set/mod.rs new file mode 100644 index 0000000..c8a98f7 --- /dev/null +++ b/typesense/src/client/synonym_set/mod.rs @@ -0,0 +1,64 @@ +//! Provides access to the API endpoints for managing a specific synonym set. +//! +//! Synonym sets allows you to define search terms that should be considered equivalent. +//! +//! A `SynonymSet` instance is created via the main `client.synonym_set("synonym_set_name")` method. + +mod item; +mod items; + +use crate::{Client, Error, execute_wrapper}; +use item::SynonymSetItem; +use items::SynonymSetItems; +use typesense_codegen::{apis::synonyms_api, models}; + +/// Provides methods for managing a specific synonym set. +/// +/// This struct is created by calling `client.synonym_set("synonym_set_name")`. +pub struct SynonymSet<'a> { + pub(super) client: &'a Client, + pub(super) synonym_set_name: &'a str, +} + +impl<'a> SynonymSet<'a> { + /// Creates a new `SynonymSet` instance. + #[inline] + pub(super) fn new(client: &'a Client, synonym_set_name: &'a str) -> Self { + Self { + client, + synonym_set_name, + } + } + + /// Provides access to the items of this synonym set. + #[inline] + pub fn items(&self) -> SynonymSetItems<'_> { + SynonymSetItems::new(self.client, self.synonym_set_name) + } + + /// Provides access to this specific item of this synonym set. + #[inline] + pub fn item(&self, item_id: &'a str) -> SynonymSetItem<'a> { + SynonymSetItem::new(self.client, self.synonym_set_name, item_id) + } + + /// Retrieves the details of this synonym set. + pub async fn retrieve( + &self, + ) -> Result> { + let params = synonyms_api::RetrieveSynonymSetParams { + synonym_set_name: self.synonym_set_name.into(), + }; + execute_wrapper!(self, synonyms_api::retrieve_synonym_set, params) + } + + /// Delete this synonym set. + pub async fn delete( + &self, + ) -> Result> { + let params = synonyms_api::DeleteSynonymSetParams { + synonym_set_name: self.synonym_set_name.into(), + }; + execute_wrapper!(self, synonyms_api::delete_synonym_set, params) + } +} diff --git a/typesense/src/client/synonym_sets.rs b/typesense/src/client/synonym_sets.rs new file mode 100644 index 0000000..86ddf55 --- /dev/null +++ b/typesense/src/client/synonym_sets.rs @@ -0,0 +1,48 @@ +//! Provides access to the API endpoints for managing synonym sets. +//! +//! Synonym sets allows you to define search terms that should be considered equivalent. +//! +//! A `SynonymSets` instance is created via the main `client.synonym_sets()` method. + +use crate::{Client, Error, execute_wrapper}; +use ::std::borrow::Cow; +use typesense_codegen::{apis::synonyms_api, models}; + +/// Provides methods for managing all of your Typesense synonym sets. +/// +/// This struct is created by calling `client.synonym_sets()`. +pub struct SynonymSets<'a> { + pub(super) client: &'a Client, +} + +impl<'a> SynonymSets<'a> { + /// Creates a new `SynonymSets` instance. + #[inline] + pub(super) fn new(client: &'a Client) -> Self { + Self { client } + } + + /// Retrieves the details of all synonym sets. + pub async fn retrieve( + &self, + ) -> Result, Error> { + execute_wrapper!(self, synonyms_api::retrieve_synonym_sets) + } + + /// Creates or updates an existing synonym set. + /// + /// # Arguments + /// * `name` - The name of the synonym set to create or update. + /// * `schema` - A `SynonymSetCreateSchema` object. + pub async fn upsert( + &self, + name: impl Into>, + schema: models::SynonymSetCreateSchema, + ) -> Result> { + let params = synonyms_api::UpsertSynonymSetParams { + synonym_set_name: name.into(), + synonym_set_create_schema: schema, + }; + execute_wrapper!(self, synonyms_api::upsert_synonym_set, params) + } +} diff --git a/typesense/src/models/mod.rs b/typesense/src/models/mod.rs index aaa3ad7..e095807 100644 --- a/typesense/src/models/mod.rs +++ b/typesense/src/models/mod.rs @@ -7,7 +7,7 @@ pub use document_index_parameters::*; pub use scoped_key_parameters::*; pub use typesense_codegen::{ apis::{analytics_api::GetAnalyticsEventsParams, operations_api::TakeSnapshotParams}, - models::*, + models::{curation_rule::Match as CurationRuleMatch, *}, }; pub use multi_search::MultiSearchBody; diff --git a/typesense/tests/client/curation_sets_test.rs b/typesense/tests/client/curation_sets_test.rs new file mode 100644 index 0000000..0a6f7fe --- /dev/null +++ b/typesense/tests/client/curation_sets_test.rs @@ -0,0 +1,168 @@ +use std::vec; + +use super::{get_client, new_id}; +use typesense::models; + +async fn run_test_curation_sets_and_items_lifecycle() { + let client = get_client(); + let curation_set_name = new_id("curation_set"); + let item_id = "customize-apple"; + let item2_id = "customize-apple-2"; + + // Create a curation set + let create_schema = models::CurationSetCreateSchema { + items: vec![models::CurationItemCreateSchema { + id: Some(item_id.into()), + rule: Box::new(models::CurationRule { + query: Some("apple".into()), + r#match: Some(models::CurationRuleMatch::Exact), + ..Default::default() + }), + includes: Some(vec![models::CurationInclude { + id: "1".into(), + position: 1, + }]), + excludes: Some(vec![models::CurationExclude { id: "2".into() }]), + ..Default::default() + }], + ..Default::default() + }; + + let create_result = client + .curation_sets() + .upsert(&curation_set_name, create_schema.clone()) + .await; + assert!(create_result.is_ok(), "Failed to create curation set"); + let created_set = create_result.unwrap(); + assert_eq!(created_set.name, curation_set_name); + assert_eq!(created_set.items[0].id, create_schema.items[0].id); + + let this_curation_set = client.curation_set(&curation_set_name); + + // Retrieve the specific curation set + let retrieve_one_result = this_curation_set.retrieve().await; + assert!( + retrieve_one_result.is_ok(), + "Failed to retrieve the newly created set." + ); + let retrieved_set = retrieve_one_result.unwrap(); + assert_eq!(retrieved_set.name, curation_set_name); + + // Retrieve all curation sets + let retrieve_all_result = client.curation_sets().retrieve().await; + assert!( + retrieve_all_result.is_ok(), + "Failed to retrieve the list of curation sets." + ); + let all_sets_response = retrieve_all_result.unwrap(); + assert!( + all_sets_response.len() >= 1, + "Expected at least one curation set to be present." + ); + assert!( + all_sets_response + .iter() + .any(|r| r.name == curation_set_name) + ); + + // Create curation item + let create_item_result = this_curation_set + .items() + .upsert( + item2_id, + models::CurationItemCreateSchema { + rule: Box::new(models::CurationRule { + query: Some("apple".into()), + r#match: Some(models::CurationRuleMatch::Exact), + ..Default::default() + }), + includes: Some(vec![models::CurationInclude { + id: "1".into(), + position: 1, + }]), + excludes: Some(vec![models::CurationExclude { id: "2".into() }]), + ..Default::default() + }, + ) + .await; + + assert!( + create_item_result.is_ok(), + "Failed to upsert curation item." + ); + assert_eq!(create_item_result.unwrap().id, item2_id); + + // Retrieve a curation item + let retrieve_item_result = this_curation_set.item(item2_id).retrieve().await; + + assert!( + retrieve_item_result.is_ok(), + "Failed to retrieve curation item." + ); + assert_eq!(retrieve_item_result.unwrap().id, item2_id); + + // Retrieve all curation items + let retrieve_all_items_result = this_curation_set.items().retrieve().await; + assert!( + retrieve_all_items_result.is_ok(), + "Failed to retrieve all curation items." + ); + let all_items_response = retrieve_all_items_result.unwrap(); + assert!( + all_items_response.iter().any(|r| r.id == item2_id), + "Expected to find the created curation item in the list." + ); + + // delete a curation item + let delete_item_result = this_curation_set.item(item2_id).delete().await; + assert!( + delete_item_result.is_ok(), + "Failed to delete curation item." + ); + let deleted_item_response = delete_item_result.unwrap(); + assert_eq!(deleted_item_response.id, item2_id); + + // Verify deletion of curation item + let get_after_delete_item_result = this_curation_set.item(item2_id).retrieve().await; + assert!( + get_after_delete_item_result.is_err(), + "Curation item should not exist after deletion" + ); + + // Delete a curation set + let delete_result = client.curation_set(&curation_set_name).delete().await; + assert!(delete_result.is_ok(), "Failed to delete curation set"); + let deleted_response = delete_result.unwrap(); + assert_eq!(deleted_response.name, curation_set_name); + + // Verify deletion + let get_after_delete_result = client.curation_set(&curation_set_name).delete().await; + assert!( + get_after_delete_result.is_err(), + "Curation set should not exist after deletion" + ); +} + +#[cfg(all(test, not(target_arch = "wasm32")))] +mod tokio_test { + use super::*; + + #[tokio::test] + async fn test_curation_sets_and_items_lifecycl() { + run_test_curation_sets_and_items_lifecycle().await; + } +} + +#[cfg(all(test, target_arch = "wasm32"))] +mod wasm_test { + use super::*; + use wasm_bindgen_test::wasm_bindgen_test; + + wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); + + #[wasm_bindgen_test] + async fn test_curation_sets_and_items_lifecycl() { + console_error_panic_hook::set_once(); + run_test_curation_sets_and_items_lifecycle().await; + } +} diff --git a/typesense/tests/client/mod.rs b/typesense/tests/client/mod.rs index e3c14e7..ecafdee 100644 --- a/typesense/tests/client/mod.rs +++ b/typesense/tests/client/mod.rs @@ -3,6 +3,7 @@ mod analytics_test; mod client_test; mod collections_test; mod conversation_models_test; +mod curation_sets_test; mod derive_integration_test; mod documents_test; mod keys_test; @@ -11,6 +12,7 @@ mod operations_test; mod presets_test; mod stemming_dictionaries_test; mod stopwords_test; +mod synonym_sets_test; use std::time::Duration; use typesense::{Client, ExponentialBackoff}; diff --git a/typesense/tests/client/synonym_sets_test.rs b/typesense/tests/client/synonym_sets_test.rs new file mode 100644 index 0000000..8275917 --- /dev/null +++ b/typesense/tests/client/synonym_sets_test.rs @@ -0,0 +1,145 @@ +use std::vec; + +use super::{get_client, new_id}; +use typesense::models::{self, SynonymItemSchema}; + +async fn run_test_synonym_sets_and_items_lifecycle() { + let client = get_client(); + let synonym_set_name = new_id("clothing-synonyms"); + let item_id = "customize-apple"; + let item2_id = "customize-apple-2"; + + // Create a synonym set + let create_schema = models::SynonymSetCreateSchema { + items: vec![SynonymItemSchema { + id: item_id.to_owned(), + synonyms: vec!["blazer".to_owned(), "coat".to_owned(), "jacket".to_owned()], + ..Default::default() + }], + ..Default::default() + }; + + let create_result = client + .synonym_sets() + .upsert(&synonym_set_name, create_schema.clone()) + .await; + assert!(create_result.is_ok(), "Failed to create synonym set"); + let created_set = create_result.unwrap(); + assert_eq!(created_set.name, synonym_set_name); + assert_eq!(created_set.items[0].id, create_schema.items[0].id); + + let this_synonym_set = client.synonym_set(&synonym_set_name); + + // Retrieve the specific synonym set + let retrieve_one_result = this_synonym_set.retrieve().await; + assert!( + retrieve_one_result.is_ok(), + "Failed to retrieve the newly created set." + ); + let retrieved_set = retrieve_one_result.unwrap(); + assert_eq!(retrieved_set.name, synonym_set_name); + + // Retrieve all synonym sets + let retrieve_all_result = client.synonym_sets().retrieve().await; + assert!( + retrieve_all_result.is_ok(), + "Failed to retrieve the list of synonym sets." + ); + let all_sets_response = retrieve_all_result.unwrap(); + assert!( + all_sets_response.len() >= 1, + "Expected at least one synonym set to be present." + ); + assert!(all_sets_response.iter().any(|r| r.name == synonym_set_name)); + + // Create synonym item + let create_item_result = this_synonym_set + .items() + .upsert( + item2_id, + models::SynonymItemUpsertSchema { + root: Some("smartphone".into()), + synonyms: vec![ + "iphone".to_owned(), + "android phone".to_owned(), + "mobile".to_owned(), + ], + ..Default::default() + }, + ) + .await; + + assert!(create_item_result.is_ok(), "Failed to upsert synonym item."); + assert_eq!(create_item_result.unwrap().id, item2_id); + + // Retrieve a synonym item + let retrieve_item_result = this_synonym_set.item(item2_id).retrieve().await; + + assert!( + retrieve_item_result.is_ok(), + "Failed to retrieve synonym item." + ); + assert_eq!(retrieve_item_result.unwrap().id, item2_id); + + // Retrieve all synonym items + let retrieve_all_items_result = this_synonym_set.items().retrieve().await; + assert!( + retrieve_all_items_result.is_ok(), + "Failed to retrieve all synonym items." + ); + let all_items_response = retrieve_all_items_result.unwrap(); + assert!( + all_items_response.iter().any(|r| r.id == item2_id), + "Expected to find the created synonym item in the list." + ); + + // delete a synonym item + let delete_item_result = this_synonym_set.item(item2_id).delete().await; + assert!(delete_item_result.is_ok(), "Failed to delete synonym item."); + let deleted_item_response = delete_item_result.unwrap(); + assert_eq!(deleted_item_response.id, item2_id); + + // Verify deletion of synonym item + let get_after_delete_item_result = this_synonym_set.item(item2_id).retrieve().await; + assert!( + get_after_delete_item_result.is_err(), + "Synonym item should not exist after deletion" + ); + + // Delete a synonym set + let delete_result = this_synonym_set.delete().await; + assert!(delete_result.is_ok(), "Failed to delete synonym set"); + let deleted_response = delete_result.unwrap(); + assert_eq!(deleted_response.name, synonym_set_name); + + // Verify deletion + let get_after_delete_result = this_synonym_set.delete().await; + assert!( + get_after_delete_result.is_err(), + "Synonym set should not exist after deletion" + ); +} + +#[cfg(all(test, not(target_arch = "wasm32")))] +mod tokio_test { + use super::*; + + #[tokio::test] + async fn test_synonym_sets_and_items_lifecycl() { + run_test_synonym_sets_and_items_lifecycle().await; + } +} + +#[cfg(all(test, target_arch = "wasm32"))] +mod wasm_test { + use super::*; + use wasm_bindgen_test::wasm_bindgen_test; + + wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); + + #[wasm_bindgen_test] + async fn test_synonym_sets_and_items_lifecycl() { + console_error_panic_hook::set_once(); + run_test_synonym_sets_and_items_lifecycle().await; + } +} diff --git a/typesense_codegen/docs/CurationSetsApi.md b/typesense_codegen/docs/CurationSetsApi.md index 0f9e018..a6a5146 100644 --- a/typesense_codegen/docs/CurationSetsApi.md +++ b/typesense_codegen/docs/CurationSetsApi.md @@ -78,7 +78,7 @@ Name | Type | Description | Required | Notes ## retrieve_curation_set -> models::CurationSetCreateSchema retrieve_curation_set(curation_set_name) +> models::CurationSetSchema retrieve_curation_set(curation_set_name) Retrieve a curation set Retrieve a specific curation set by its name @@ -92,7 +92,7 @@ Name | Type | Description | Required | Notes ### Return type -[**models::CurationSetCreateSchema**](CurationSetCreateSchema.md) +[**models::CurationSetSchema**](CurationSetSchema.md) ### Authorization diff --git a/typesense_codegen/docs/SynonymsApi.md b/typesense_codegen/docs/SynonymsApi.md index 7a3ce15..df1281b 100644 --- a/typesense_codegen/docs/SynonymsApi.md +++ b/typesense_codegen/docs/SynonymsApi.md @@ -78,7 +78,7 @@ Name | Type | Description | Required | Notes ## retrieve_synonym_set -> models::SynonymSetCreateSchema retrieve_synonym_set(synonym_set_name) +> models::SynonymSetSchema retrieve_synonym_set(synonym_set_name) Retrieve a synonym set Retrieve a specific synonym set by its name @@ -92,7 +92,7 @@ Name | Type | Description | Required | Notes ### Return type -[**models::SynonymSetCreateSchema**](SynonymSetCreateSchema.md) +[**models::SynonymSetSchema**](SynonymSetSchema.md) ### Authorization diff --git a/typesense_codegen/src/apis/curation_sets_api.rs b/typesense_codegen/src/apis/curation_sets_api.rs index f6a3ee2..2e67cf7 100644 --- a/typesense_codegen/src/apis/curation_sets_api.rs +++ b/typesense_codegen/src/apis/curation_sets_api.rs @@ -267,7 +267,7 @@ pub async fn delete_curation_set_item( pub async fn retrieve_curation_set( configuration: &configuration::Configuration, params: &RetrieveCurationSetParams<'_>, -) -> Result, Error> { +) -> Result> { let uri_str = format!( "{}/curation_sets/{curationSetName}", configuration.base_path, @@ -304,12 +304,12 @@ pub async fn retrieve_curation_set( ContentType::Json => serde_json::from_str(&content).map_err(Error::from), ContentType::Text => { return Err(Error::from(serde_json::Error::custom( - "Received `text/plain` content type response that cannot be converted to `models::CurationSetCreateSchema`", + "Received `text/plain` content type response that cannot be converted to `models::CurationSetSchema`", ))); } ContentType::Unsupported(unknown_type) => { return Err(Error::from(serde_json::Error::custom(format!( - "Received `{unknown_type}` content type response that cannot be converted to `models::CurationSetCreateSchema`" + "Received `{unknown_type}` content type response that cannot be converted to `models::CurationSetSchema`" )))); } } diff --git a/typesense_codegen/src/apis/synonyms_api.rs b/typesense_codegen/src/apis/synonyms_api.rs index 8e7ee3c..ef7c929 100644 --- a/typesense_codegen/src/apis/synonyms_api.rs +++ b/typesense_codegen/src/apis/synonyms_api.rs @@ -267,7 +267,7 @@ pub async fn delete_synonym_set_item( pub async fn retrieve_synonym_set( configuration: &configuration::Configuration, params: &RetrieveSynonymSetParams<'_>, -) -> Result> { +) -> Result> { let uri_str = format!( "{}/synonym_sets/{synonymSetName}", configuration.base_path, @@ -304,12 +304,12 @@ pub async fn retrieve_synonym_set( ContentType::Json => serde_json::from_str(&content).map_err(Error::from), ContentType::Text => { return Err(Error::from(serde_json::Error::custom( - "Received `text/plain` content type response that cannot be converted to `models::SynonymSetCreateSchema`", + "Received `text/plain` content type response that cannot be converted to `models::SynonymSetSchema`", ))); } ContentType::Unsupported(unknown_type) => { return Err(Error::from(serde_json::Error::custom(format!( - "Received `{unknown_type}` content type response that cannot be converted to `models::SynonymSetCreateSchema`" + "Received `{unknown_type}` content type response that cannot be converted to `models::SynonymSetSchema`" )))); } }