Skip to main content

edgequake_sdk/resources/
documents.rs

1//! Documents resource.
2
3use crate::client::EdgeQuakeClient;
4use crate::error::Result;
5use crate::types::documents::*;
6use crate::types::operations::DocumentFullLineage;
7
8pub struct DocumentsResource<'a> {
9    pub(crate) client: &'a EdgeQuakeClient,
10}
11
12impl<'a> DocumentsResource<'a> {
13    /// `GET /api/v1/documents`
14    pub async fn list(&self) -> Result<ListDocumentsResponse> {
15        self.client.get("/api/v1/documents").await
16    }
17
18    /// `GET /api/v1/documents/{id}`
19    pub async fn get(&self, id: &str) -> Result<DocumentSummary> {
20        self.client.get(&format!("/api/v1/documents/{id}")).await
21    }
22
23    /// `DELETE /api/v1/documents/{id}`
24    pub async fn delete(&self, id: &str) -> Result<()> {
25        self.client.delete_no_content(&format!("/api/v1/documents/{id}")).await
26    }
27
28    /// `GET /api/v1/documents/{id}/status`
29    pub async fn status(&self, id: &str) -> Result<TrackStatusResponse> {
30        self.client
31            .get(&format!("/api/v1/documents/{id}/status"))
32            .await
33    }
34
35    /// `POST /api/v1/documents/upload/text`
36    pub async fn upload_text(&self, body: &serde_json::Value) -> Result<UploadDocumentResponse> {
37        self.client
38            .post("/api/v1/documents/upload/text", Some(body))
39            .await
40    }
41
42    /// `POST /api/v1/documents/scan`
43    pub async fn scan(&self, req: &ScanRequest) -> Result<ScanResponse> {
44        self.client.post("/api/v1/documents/scan", Some(req)).await
45    }
46
47    /// `GET /api/v1/documents/{id}/deletion-impact`
48    pub async fn deletion_impact(&self, id: &str) -> Result<DeletionImpactResponse> {
49        self.client
50            .get(&format!("/api/v1/documents/{id}/deletion-impact"))
51            .await
52    }
53
54    /// `GET /api/v1/documents/track/{track_id}`
55    pub async fn track(&self, track_id: &str) -> Result<TrackStatusResponse> {
56        self.client
57            .get(&format!("/api/v1/documents/track/{track_id}"))
58            .await
59    }
60
61    // ========================================================================
62    // Lineage Methods (OODA-14)
63    // ========================================================================
64
65    /// `GET /api/v1/documents/{id}/lineage`
66    ///
67    /// Returns complete document lineage (persisted pipeline lineage + metadata).
68    /// @implements F5 — Single API call retrieves complete lineage tree.
69    pub async fn get_lineage(&self, id: &str) -> Result<DocumentFullLineage> {
70        self.client
71            .get(&format!("/api/v1/documents/{id}/lineage"))
72            .await
73    }
74
75    /// `GET /api/v1/documents/{id}/metadata`
76    ///
77    /// Returns all document metadata stored in KV storage.
78    /// @implements F1 — All document metadata retrievable.
79    pub async fn get_metadata(&self, id: &str) -> Result<serde_json::Value> {
80        self.client
81            .get(&format!("/api/v1/documents/{id}/metadata"))
82            .await
83    }
84
85    // ========================================================================
86    // Bulk / Recovery Operations (OODA-32)
87    // ========================================================================
88
89    /// `DELETE /api/v1/documents` — Delete all documents in workspace.
90    pub async fn delete_all(&self) -> Result<serde_json::Value> {
91        self.client.delete("/api/v1/documents").await
92    }
93
94    /// `POST /api/v1/documents/reprocess` — Retry all failed documents.
95    pub async fn reprocess(&self) -> Result<serde_json::Value> {
96        self.client
97            .post::<(), serde_json::Value>("/api/v1/documents/reprocess", None)
98            .await
99    }
100
101    /// `POST /api/v1/documents/recover-stuck` — Recover stuck processing docs.
102    pub async fn recover_stuck(&self) -> Result<serde_json::Value> {
103        self.client
104            .post::<(), serde_json::Value>("/api/v1/documents/recover-stuck", None)
105            .await
106    }
107
108    /// `POST /api/v1/documents/{id}/retry-chunks` — Retry failed chunks for a document.
109    pub async fn retry_chunks(&self, id: &str) -> Result<serde_json::Value> {
110        self.client
111            .post::<(), serde_json::Value>(
112                &format!("/api/v1/documents/{id}/retry-chunks"),
113                None,
114            )
115            .await
116    }
117
118    /// `GET /api/v1/documents/{id}/failed-chunks` — List failed chunks for a document.
119    pub async fn failed_chunks(&self, id: &str) -> Result<Vec<serde_json::Value>> {
120        self.client
121            .get(&format!("/api/v1/documents/{id}/failed-chunks"))
122            .await
123    }
124}