Skip to content

Commit 462e47d

Browse files
authored
feat: add Curation sets & Synonym API (#69)
* fetch & codegen * feat: curation API * code gen * feat: synonym API
1 parent bc99b84 commit 462e47d

File tree

19 files changed

+899
-24
lines changed

19 files changed

+899
-24
lines changed

openapi.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ paths:
495495
content:
496496
application/json:
497497
schema:
498-
$ref: "#/components/schemas/SynonymSetRetrieveSchema"
498+
$ref: "#/components/schemas/SynonymSetSchema"
499499
"404":
500500
description: Synonym set not found
501501
content:
@@ -735,7 +735,7 @@ paths:
735735
content:
736736
application/json:
737737
schema:
738-
$ref: "#/components/schemas/CurationSetRetrieveSchema"
738+
$ref: "#/components/schemas/CurationSetSchema"
739739
"404":
740740
description: Curation set not found
741741
content:
@@ -4432,8 +4432,6 @@ components:
44324432
items:
44334433
$ref: "#/components/schemas/SynonymSetSchema"
44344434

4435-
SynonymSetRetrieveSchema:
4436-
$ref: "#/components/schemas/SynonymSetCreateSchema"
44374435

44384436
SynonymSetDeleteSchema:
44394437
type: object
@@ -4595,9 +4593,6 @@ components:
45954593
type: string
45964594
description: document id that should be excluded from the search results.
45974595

4598-
CurationSetRetrieveSchema:
4599-
$ref: '#/components/schemas/CurationSetCreateSchema'
4600-
46014596
CurationSetDeleteSchema:
46024597
type: object
46034598
required:

preprocessed_openapi.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ paths:
883883
content:
884884
application/json:
885885
schema:
886-
$ref: '#/components/schemas/SynonymSetRetrieveSchema'
886+
$ref: '#/components/schemas/SynonymSetSchema'
887887
'404':
888888
description: Synonym set not found
889889
content:
@@ -1118,7 +1118,7 @@ paths:
11181118
content:
11191119
application/json:
11201120
schema:
1121-
$ref: '#/components/schemas/CurationSetRetrieveSchema'
1121+
$ref: '#/components/schemas/CurationSetSchema'
11221122
'404':
11231123
description: Curation set not found
11241124
content:
@@ -4924,8 +4924,6 @@ components:
49244924
description: Array of synonym sets
49254925
items:
49264926
$ref: '#/components/schemas/SynonymSetSchema'
4927-
SynonymSetRetrieveSchema:
4928-
$ref: '#/components/schemas/SynonymSetCreateSchema'
49294927
SynonymSetDeleteSchema:
49304928
type: object
49314929
required:
@@ -5074,8 +5072,6 @@ components:
50745072
id:
50755073
type: string
50765074
description: document id that should be excluded from the search results.
5077-
CurationSetRetrieveSchema:
5078-
$ref: '#/components/schemas/CurationSetCreateSchema'
50795075
CurationSetDeleteSchema:
50805076
type: object
50815077
required:
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//! Provides access to the API endpoints for managing a curation set item.
2+
//!
3+
//! Curation sets allow you to include or exclude specific documents for a given query.
4+
//!
5+
//! A `CurationSetItem` instance is created via the main `client.curation_set("curation_set_name").item("item_id")` method.
6+
use crate::{Client, Error, execute_wrapper};
7+
use typesense_codegen::{
8+
apis::curation_sets_api::{self, RetrieveCurationSetItemParams},
9+
models,
10+
};
11+
12+
/// Provides methods for managing a curation set item.
13+
///
14+
/// This struct is created by calling `client.curation_set("curation_set_name").item("item_id")`.
15+
pub struct CurationSetItem<'a> {
16+
pub(super) client: &'a Client,
17+
pub(super) curation_set_name: &'a str,
18+
pub(super) item_id: &'a str,
19+
}
20+
21+
impl<'a> CurationSetItem<'a> {
22+
/// Creates a new `CurationSetItem` instance.
23+
#[inline]
24+
pub(super) fn new(client: &'a Client, curation_set_name: &'a str, item_id: &'a str) -> Self {
25+
Self {
26+
client,
27+
curation_set_name,
28+
item_id,
29+
}
30+
}
31+
32+
/// Retrieve this curation set item.
33+
pub async fn retrieve(
34+
&self,
35+
) -> Result<models::CurationItemSchema, Error<curation_sets_api::RetrieveCurationSetItemError>>
36+
{
37+
let params = RetrieveCurationSetItemParams {
38+
curation_set_name: self.curation_set_name.into(),
39+
item_id: self.item_id.into(),
40+
};
41+
execute_wrapper!(self, curation_sets_api::retrieve_curation_set_item, params)
42+
}
43+
44+
/// Delete this curation set item.
45+
pub async fn delete(
46+
&self,
47+
) -> Result<
48+
models::CurationItemDeleteSchema,
49+
Error<curation_sets_api::DeleteCurationSetItemError>,
50+
> {
51+
let params = curation_sets_api::DeleteCurationSetItemParams {
52+
curation_set_name: self.curation_set_name.into(),
53+
item_id: self.item_id.into(),
54+
};
55+
execute_wrapper!(self, curation_sets_api::delete_curation_set_item, params)
56+
}
57+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
//! Provides access to the API endpoints for managing items of a curation set.
2+
//!
3+
//! Curation sets allow you to include or exclude specific documents for a given query.
4+
//!
5+
//! A `CurationSetItems` instance is created via the main `client.curation_set("curation_set_name").items()` method.
6+
7+
use ::std::borrow::Cow;
8+
9+
use crate::{Client, Error, execute_wrapper};
10+
use typesense_codegen::{
11+
apis::curation_sets_api::{self, RetrieveCurationSetItemsParams},
12+
models,
13+
};
14+
15+
/// Provides methods for managing items of a curation set.
16+
///
17+
/// This struct is created by calling `client.curation_set("curation_set_name").items()`.
18+
pub struct CurationSetItems<'a> {
19+
pub(super) client: &'a Client,
20+
pub(super) curation_set_name: &'a str,
21+
}
22+
23+
impl<'a> CurationSetItems<'a> {
24+
/// Creates a new `CurationSetItems` instance.
25+
#[inline]
26+
pub(super) fn new(client: &'a Client, curation_set_name: &'a str) -> Self {
27+
Self {
28+
client,
29+
curation_set_name,
30+
}
31+
}
32+
33+
/// Retrieves all the items of this curation set.
34+
pub async fn retrieve(
35+
&self,
36+
) -> Result<
37+
Vec<models::CurationItemSchema>,
38+
Error<curation_sets_api::RetrieveCurationSetItemsError>,
39+
> {
40+
let params = RetrieveCurationSetItemsParams {
41+
curation_set_name: self.curation_set_name.into(),
42+
};
43+
execute_wrapper!(self, curation_sets_api::retrieve_curation_set_items, params)
44+
}
45+
46+
/// Creates or updates an existing item of a curation set.
47+
///
48+
/// # Arguments
49+
/// * `item_id` - The id of the curation set item to create or update.
50+
/// * `schema` - A `CurationItemCreateSchema` object.
51+
pub async fn upsert(
52+
&self,
53+
item_id: impl Into<Cow<'_, str>>,
54+
schema: models::CurationItemCreateSchema<'_>,
55+
) -> Result<models::CurationItemSchema, Error<curation_sets_api::UpsertCurationSetItemError>>
56+
{
57+
let params = curation_sets_api::UpsertCurationSetItemParams {
58+
item_id: item_id.into(),
59+
curation_set_name: self.curation_set_name.into(),
60+
curation_item_create_schema: schema,
61+
};
62+
execute_wrapper!(self, curation_sets_api::upsert_curation_set_item, params)
63+
}
64+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//! Provides access to the API endpoints for managing a specific curation set.
2+
//!
3+
//! Curation sets allow you to include or exclude specific documents for a given query.
4+
//!
5+
//! A `CurationSet` instance is created via the main `client.curation_set("curation_set_name")` method.
6+
7+
mod item;
8+
mod items;
9+
10+
use crate::{Client, Error, execute_wrapper};
11+
use item::CurationSetItem;
12+
use items::CurationSetItems;
13+
use typesense_codegen::{
14+
apis::curation_sets_api::{self, RetrieveCurationSetParams},
15+
models,
16+
};
17+
18+
/// Provides methods for managing a specific curation set.
19+
///
20+
/// This struct is created by calling `client.curation_set("curation_set_name")`.
21+
pub struct CurationSet<'a> {
22+
pub(super) client: &'a Client,
23+
pub(super) curation_set_name: &'a str,
24+
}
25+
26+
impl<'a> CurationSet<'a> {
27+
/// Creates a new `CurationSet` instance.
28+
#[inline]
29+
pub(super) fn new(client: &'a Client, curation_set_name: &'a str) -> Self {
30+
Self {
31+
client,
32+
curation_set_name,
33+
}
34+
}
35+
36+
/// Provides access to the items of this curation set.
37+
#[inline]
38+
pub fn items(&self) -> CurationSetItems<'_> {
39+
CurationSetItems::new(self.client, self.curation_set_name)
40+
}
41+
42+
/// Provides access to this specific item of this curation set.
43+
#[inline]
44+
pub fn item(&self, item_id: &'a str) -> CurationSetItem<'a> {
45+
CurationSetItem::new(self.client, self.curation_set_name, item_id)
46+
}
47+
48+
/// Retrieves the details of this curation set.
49+
pub async fn retrieve(
50+
&self,
51+
) -> Result<models::CurationSetSchema, Error<curation_sets_api::RetrieveCurationSetError>> {
52+
let params = RetrieveCurationSetParams {
53+
curation_set_name: self.curation_set_name.into(),
54+
};
55+
execute_wrapper!(self, curation_sets_api::retrieve_curation_set, params)
56+
}
57+
58+
/// Delete this curation set.
59+
pub async fn delete(
60+
&self,
61+
) -> Result<models::CurationSetDeleteSchema, Error<curation_sets_api::DeleteCurationSetError>>
62+
{
63+
let params = curation_sets_api::DeleteCurationSetParams {
64+
curation_set_name: self.curation_set_name.into(),
65+
};
66+
execute_wrapper!(self, curation_sets_api::delete_curation_set, params)
67+
}
68+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//! Provides access to the API endpoints for managing curation sets.
2+
//!
3+
//! Curation sets allow you to include or exclude specific documents for a given query.
4+
//!
5+
//! A `CurationSets` instance is created via the main `client.curation_sets()` method.
6+
7+
use crate::{Client, Error, execute_wrapper};
8+
use ::std::borrow::Cow;
9+
use typesense_codegen::{apis::curation_sets_api, models};
10+
11+
/// Provides methods for managing all of your Typesense curation sets.
12+
///
13+
/// This struct is created by calling `client.curation_sets()`.
14+
pub struct CurationSets<'a> {
15+
pub(super) client: &'a Client,
16+
}
17+
18+
impl<'a> CurationSets<'a> {
19+
/// Creates a new `CurationSets` instance.
20+
#[inline]
21+
pub(super) fn new(client: &'a Client) -> Self {
22+
Self { client }
23+
}
24+
25+
/// Retrieves the details of all curation sets.
26+
pub async fn retrieve(
27+
&self,
28+
) -> Result<Vec<models::CurationSetSchema>, Error<curation_sets_api::RetrieveCurationSetsError>>
29+
{
30+
execute_wrapper!(self, curation_sets_api::retrieve_curation_sets)
31+
}
32+
33+
/// Creates or updates an existing curation set.
34+
///
35+
/// # Arguments
36+
/// * `name` - The name of the curation set to create or update.
37+
/// * `schema` - A `CurationSetCreateSchema` object.
38+
pub async fn upsert(
39+
&self,
40+
name: impl Into<Cow<'_, str>>,
41+
schema: models::CurationSetCreateSchema<'_>,
42+
) -> Result<models::CurationSetSchema, Error<curation_sets_api::UpsertCurationSetError>> {
43+
let params = curation_sets_api::UpsertCurationSetParams {
44+
curation_set_name: name.into(),
45+
curation_set_create_schema: schema,
46+
};
47+
execute_wrapper!(self, curation_sets_api::upsert_curation_set, params)
48+
}
49+
}

0 commit comments

Comments
 (0)