Skip to content

Conversation

@kumarUjjawal
Copy link
Contributor

@kumarUjjawal kumarUjjawal commented Oct 28, 2025

Pull Request

Related issue

Fixes #695

What does this PR do?

PR checklist

Please check if your PR fulfills the following requirements:

  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
  • Have you read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!

Summary by CodeRabbit

  • New Features
    • Export tasks can now be created and enqueued with flexible configuration including API key, payload size, and per-index settings
    • Export task details are now included in task information responses for comprehensive monitoring and status tracking
    • Payload size can be specified in bytes or human-readable formats

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 28, 2025

Walkthrough

This PR adds client-side support for the Meilisearch /export API, introducing configurable export payload structures, per-index options, and a create_export method on the HTTP client. Task-related types are extended to represent export task details, and a code example is added to the samples.

Changes

Cohort / File(s) Summary
Code sample documentation
.code-samples.meilisearch.yaml
Added export_post_1 code sample demonstrating creation of an export task with API key, payload size, and index override settings.
Export API module
src/export.rs
New module implementing export functionality: ExportPayload and ExportIndexOptions structs with builder methods, ExportPayloadSize enum supporting bytes and human-readable formats, Client<Http>::create_export() method for POSTing to /export, and comprehensive unit tests.
Module declaration
src/lib.rs
Added public export module export with documentation.
Task type extensions
src/tasks.rs
Added Export variant to TaskType enum, new ExportTaskDetails struct capturing export configuration, and ExportTaskIndexDetails struct with per-index export metadata. Updated imports to include BTreeMap.

Sequence Diagram

sequenceDiagram
    participant User
    participant Client
    participant Meilisearch

    User->>User: Build ExportPayload<br/>(url, api_key, indexes, etc.)
    User->>Client: create_export(payload)
    Client->>Meilisearch: POST /export<br/>(with configured payload)
    Meilisearch-->>Client: 202 Accepted<br/>TaskInfo
    Client-->>User: TaskInfo<br/>(task_uid, status, etc.)
    Note over User: Task can be tracked<br/>via existing task APIs
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–25 minutes

  • src/export.rs: New module with builder patterns, payload serialization, and test coverage; logic is straightforward but requires validation of serde configurations and From trait implementations.
  • src/tasks.rs: Enum variant addition and new struct definitions; verify compatibility with existing task deserialization and that serde defaults align with API contract.
  • .code-samples.meilisearch.yaml: Validate that example code reflects public API correctly and matches typical usage patterns.

Suggested labels

enhancement

Suggested reviewers

  • curquiza

Poem

🐰 A new path opens wide, where exports run free,
Payloads dance with settings, indexed for all to see!
From bytes to readable strings, the rabbit hops with glee—
Tasks enqueued and tracked with grace, a feature full of spree! ✨

Pre-merge checks and finishing touches

✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "Add support for export API" is clear, concise, and directly describes the main change in the changeset. It accurately summarizes the primary objective of implementing support for the Meilisearch export API, which is reflected across all modified files (src/export.rs, src/lib.rs, src/tasks.rs, and .code-samples.meilisearch.yaml). The title is specific enough to convey meaning without unnecessary details.
Linked Issues Check ✅ Passed The PR fulfills all three coding-related requirements from linked issue #695. First, it adds necessary methods to interact with the export API by introducing the ExportPayload struct, ExportIndexOptions configuration, ExportPayloadSize enum, and the create_export method on Client in src/export.rs. Second, comprehensive unit tests are provided (test_create_export_returns_task and test_create_export_with_index_configuration) covering basic and index-configured export scenarios. Third, an example code snippet is added to .code-samples.meilisearch.yaml under the export_post_1 key demonstrating export task creation. Supporting infrastructure changes to src/tasks.rs (TaskType::Export variant and related structs) and src/lib.rs (export module export) enable proper task representation and API organization.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/tasks.rs (1)

105-121: Redact api_key in Debug to avoid accidental secret leakage.

ExportTaskDetails derives Debug and includes api_key; Debug prints often end up in logs. Recommend redacting in Debug.

Apply this diff:

-#[derive(Debug, Clone, Deserialize)]
+#[derive(Clone, Deserialize)]
 pub struct ExportTaskDetails {
     pub url: Option<String>,
     pub api_key: Option<String>,
     pub payload_size: Option<String>,
     pub indexes: Option<BTreeMap<String, ExportTaskIndexDetails>>,
 }
+
+impl std::fmt::Debug for ExportTaskDetails {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("ExportTaskDetails")
+            .field("url", &self.url)
+            .field("api_key", &self.api_key.as_ref().map(|_| "****"))
+            .field("payload_size", &self.payload_size)
+            .field("indexes", &self.indexes)
+            .finish()
+    }
+}
src/export.rs (2)

131-137: Make with_filter accept Into for ergonomics.

Allows passing &str or String directly without json!/into() ceremony.

Apply this diff:

-    pub fn with_filter(mut self, filter: Value) -> Self {
-        self.filter = Some(filter);
+    pub fn with_filter<T: Into<Value>>(mut self, filter: T) -> Self {
+        self.filter = Some(filter.into());
         self
     }

199-307: Add a test to assert default fields are omitted from the payload.

Verify overrideSettings: false and payloadSize: None don’t serialize.

Example to add under cfg(feature = "reqwest"):

#[tokio::test]
async fn test_create_export_omits_defaults() -> Result<(), Error> {
    let mut server = mockito::Server::new_async().await;
    let base = server.url();

    let _mock = server
        .mock("POST", "/export")
        .match_header("authorization", "Bearer masterKey")
        .match_header("content-type", "application/json")
        .match_body(Matcher::Json(serde_json::json!({
            "url": "https://ms-cloud.example.com",
            "indexes": { "movies": { "filter": "genres = action" } }
        })))
        .with_status(202)
        .with_body(r#"{"enqueuedAt":"2024-01-01T00:00:00Z","status":"enqueued","taskUid":3,"type":"export"}"#)
        .create_async()
        .await;

    let client = Client::new(base, Some("masterKey")).unwrap();
    let payload = ExportPayload::new("https://ms-cloud.example.com")
        .with_index("movies", ExportIndexOptions::new().with_filter("genres = action"));
    let _ = client.create_export(payload).await?;
    Ok(())
}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e90a3c2 and 91f15c4.

📒 Files selected for processing (4)
  • .code-samples.meilisearch.yaml (1 hunks)
  • src/export.rs (1 hunks)
  • src/lib.rs (1 hunks)
  • src/tasks.rs (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: integration-tests
🔇 Additional comments (3)
.code-samples.meilisearch.yaml (1)

1348-1357: Sample looks correct and aligned with the new API.

The snippet correctly demonstrates create_export with URL, API key, payload size, and index-wide override settings. No changes needed.

src/lib.rs (1)

241-243: Public export module exposure LGTM.

Clean addition; docs will link through.

src/tasks.rs (1)

48-50: New TaskType::Export variant fits the task model.

Enum tagging remains camelCase; “Export” → "export" matches server payloads.

@kumarUjjawal kumarUjjawal deleted the feat/exportApi branch October 28, 2025 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[v1.16] Add support for /export API

1 participant