Skip to content

Commit 0d96f6b

Browse files
committed
integration tests
1 parent 46a2208 commit 0d96f6b

31 files changed

+3118
-820
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/target
22
Cargo.lock
3-
.env
3+
.env
4+
/typesense-data

compose.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
services:
2+
typesense:
3+
image: typesense/typesense:29.0
4+
restart: on-failure
5+
ports:
6+
- '8108:8108'
7+
volumes:
8+
- ./typesense-data:/data
9+
command: '--data-dir /data --api-key=xyz --enable-cors'

typesense/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ dotenvy = "0.15"
3535
trybuild = "1.0.42"
3636
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
3737
wiremock = "0.5"
38+
nanoid = "0.4"
3839

3940
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
4041
tokio = { version = "1.5", features = ["macros", "rt", "rt-multi-thread"] }

typesense/src/client/collection/document.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use typesense_codegen::apis::{configuration, documents_api};
1010

1111
/// Provides methods for interacting with a single document within a specific Typesense collection.
1212
///
13-
/// This struct is created by calling a method like `collection.document("document_id")`.
13+
/// This struct is created by calling a method like `client.collection("collection_name").document("document_id")`.
1414
pub struct Document<'a> {
1515
pub(super) client: &'a Client,
1616
pub(super) collection_name: &'a str,
@@ -29,7 +29,9 @@ impl<'a> Document<'a> {
2929
}
3030

3131
/// Fetches this individual document from the collection.
32-
pub async fn get(&self) -> Result<serde_json::Value, Error<documents_api::GetDocumentError>> {
32+
pub async fn retrieve(
33+
&self,
34+
) -> Result<serde_json::Value, Error<documents_api::GetDocumentError>> {
3335
let params = documents_api::GetDocumentParams {
3436
collection_name: self.collection_name.to_string(),
3537
document_id: self.document_id.to_string(),

typesense/src/client/collection/documents.rs

Lines changed: 36 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ use super::{Client, Error};
77
use std::sync::Arc;
88
use typesense_codegen::{
99
apis::{configuration, documents_api},
10-
models,
10+
models::{
11+
self, DeleteDocumentsParameters, ExportDocumentsParameters, ImportDocumentsParameters,
12+
UpdateDocumentsParameters,
13+
},
1114
};
1215

1316
/// Provides methods for interacting with documents within a specific Typesense collection.
@@ -82,27 +85,6 @@ impl<'a> Documents<'a> {
8285
self.index(document, "upsert").await
8386
}
8487

85-
/// Fetches an individual document from the collection by its ID.
86-
///
87-
/// # Arguments
88-
/// * `document_id` - The ID of the document to retrieve.
89-
pub async fn retrieve(
90-
&self,
91-
document_id: &str,
92-
) -> Result<serde_json::Value, Error<documents_api::GetDocumentError>> {
93-
let params = documents_api::GetDocumentParams {
94-
collection_name: self.collection_name.to_string(),
95-
document_id: document_id.to_string(),
96-
};
97-
98-
self.client
99-
.execute(|config: Arc<configuration::Configuration>| {
100-
let params_for_move = params.clone();
101-
async move { documents_api::get_document(&config, params_for_move).await }
102-
})
103-
.await
104-
}
105-
10688
// --- Bulk Operation Methods ---
10789

10890
/// Imports a batch of documents in JSONL format.
@@ -111,15 +93,23 @@ impl<'a> Documents<'a> {
11193
///
11294
/// # Arguments
11395
/// * `documents_jsonl` - A string containing the documents in JSONL format.
114-
/// * `params` - An `ImportDocumentsParams` struct containing options like `action` and `batch_size`.
115-
/// The `collection_name` field will be overwritten.
96+
/// * `params` - An `ImportDocumentsParameters` struct containing options like `action` and `batch_size`.
11697
pub async fn import(
11798
&self,
11899
documents_jsonl: String,
119-
mut params: documents_api::ImportDocumentsParams,
100+
params: ImportDocumentsParameters,
120101
) -> Result<String, Error<documents_api::ImportDocumentsError>> {
121-
params.collection_name = self.collection_name.to_string();
122-
params.body = documents_jsonl;
102+
let params = documents_api::ImportDocumentsParams {
103+
body: documents_jsonl,
104+
collection_name: self.collection_name.to_string(),
105+
106+
action: params.action,
107+
batch_size: params.batch_size,
108+
dirty_values: params.dirty_values,
109+
remote_embedding_batch_size: params.remote_embedding_batch_size,
110+
return_doc: params.return_doc,
111+
return_id: params.return_id,
112+
};
123113

124114
self.client
125115
.execute(|config: Arc<configuration::Configuration>| {
@@ -132,13 +122,17 @@ impl<'a> Documents<'a> {
132122
/// Exports all documents in a collection in JSONL format.
133123
///
134124
/// # Arguments
135-
/// * `params` - An `ExportDocumentsParams` struct containing options like `filter_by` and `include_fields`.
136-
/// The `collection_name` field will be overwritten.
125+
/// * `params` - An `ExportDocumentsParameters` struct containing options like `filter_by` and `include_fields`.
137126
pub async fn export(
138127
&self,
139-
mut params: documents_api::ExportDocumentsParams,
128+
params: ExportDocumentsParameters,
140129
) -> Result<String, Error<documents_api::ExportDocumentsError>> {
141-
params.collection_name = self.collection_name.to_string();
130+
let params = documents_api::ExportDocumentsParams {
131+
collection_name: self.collection_name.to_string(),
132+
exclude_fields: params.exclude_fields,
133+
filter_by: params.filter_by,
134+
include_fields: params.include_fields,
135+
};
142136

143137
self.client
144138
.execute(|config: Arc<configuration::Configuration>| {
@@ -151,20 +145,18 @@ impl<'a> Documents<'a> {
151145
/// Deletes a batch of documents matching a specific filter condition.
152146
///
153147
/// # Arguments
154-
/// * `filter_by` - The filter condition for deleting documents.
155-
/// * `batch_size` - The number of documents to delete at a time.
156-
pub async fn delete_by_filter(
148+
/// * `params` - A `DeleteDocumentsParameters` describing the conditions for deleting documents.
149+
pub async fn delete(
157150
&self,
158-
filter_by: &str,
159-
batch_size: Option<i32>,
151+
params: DeleteDocumentsParameters,
160152
) -> Result<models::DeleteDocuments200Response, Error<documents_api::DeleteDocumentsError>>
161153
{
162154
let params = documents_api::DeleteDocumentsParams {
163155
collection_name: self.collection_name.to_string(),
164-
filter_by: Some(filter_by.to_string()),
165-
batch_size,
166-
ignore_not_found: None,
167-
truncate: None,
156+
filter_by: Some(params.filter_by),
157+
batch_size: params.batch_size,
158+
ignore_not_found: params.ignore_not_found,
159+
truncate: params.truncate,
168160
};
169161
self.client
170162
.execute(|config: Arc<configuration::Configuration>| {
@@ -177,17 +169,17 @@ impl<'a> Documents<'a> {
177169
/// Updates a batch of documents matching a specific filter condition.
178170
///
179171
/// # Arguments
180-
/// * `filter_by` - The filter condition for updating documents.
181172
/// * `document` - A `serde_json::Value` containing the fields to update.
182-
pub async fn update_by_filter(
173+
/// * `params` - A `UpdateDocumentsParameters` describing the conditions for updating documents.
174+
pub async fn update(
183175
&self,
184-
filter_by: &str,
185176
document: serde_json::Value,
177+
params: UpdateDocumentsParameters,
186178
) -> Result<models::UpdateDocuments200Response, Error<documents_api::UpdateDocumentsError>>
187179
{
188180
let params = documents_api::UpdateDocumentsParams {
189181
collection_name: self.collection_name.to_string(),
190-
filter_by: Some(filter_by.to_string()),
182+
filter_by: params.filter_by,
191183
body: document,
192184
};
193185
self.client

typesense/src/client/collection/search_override.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use typesense_codegen::{
1111

1212
/// Provides methods for interacting with a specific search override.
1313
///
14-
/// This struct is created by calling `documents.search_override("override_id")`.
14+
/// This struct is created by calling `client.collection("colelction_name").search_override("override_id")`.
1515
pub struct SearchOverride<'a> {
1616
pub(super) client: &'a Client,
1717
pub(super) collection_name: &'a str,

typesense/src/client/collection/search_overrides.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use typesense_codegen::{
1111

1212
/// Provides methods for interacting with a collection of search overrides.
1313
///
14-
/// This struct is created by calling `client.collection("collection_name").overrides()`.
14+
/// This struct is created by calling `client.collection("collection_name").search_overrides()`.
1515
pub struct SearchOverrides<'a> {
1616
pub(super) client: &'a Client,
1717
pub(super) collection_name: &'a str,

typesense/src/client/collections.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl<'a> Collections<'a> {
5050
///
5151
/// The collections are returned sorted by creation date, with the most
5252
/// recent collections appearing first.
53-
pub async fn list_all(
53+
pub async fn retrieve(
5454
&self,
5555
) -> Result<Vec<models::CollectionResponse>, Error<collections_api::GetCollectionsError>> {
5656
self.client

0 commit comments

Comments
 (0)