POST /v1/collections/{name}/crdt/apply Apply a CRDT delta to a document in the collection. Request body: ```json { "doc_id": "doc-1", "delta": "hex_encoded_delta_bytes" } ```
(
headers: HeaderMap,
State(state): State<AppState>,
Path(collection): Path<String>,
axum::Json(body): axum::Json<HttpCrdtApplyRequest>,
)
| 30 | /// } |
| 31 | /// ``` |
| 32 | pub async fn crdt_apply( |
| 33 | headers: HeaderMap, |
| 34 | State(state): State<AppState>, |
| 35 | Path(collection): Path<String>, |
| 36 | axum::Json(body): axum::Json<HttpCrdtApplyRequest>, |
| 37 | ) -> Result<impl IntoResponse, ApiError> { |
| 38 | let identity = resolve_identity(&headers, &state, "http")?; |
| 39 | |
| 40 | // Decode delta from hex. |
| 41 | let delta = hex_decode(&body.delta) |
| 42 | .ok_or_else(|| ApiError::BadRequest("invalid hex in 'delta' field".into()))?; |
| 43 | |
| 44 | let _trace_id = extract_request_id(&headers); |
| 45 | |
| 46 | let surrogate = state |
| 47 | .shared |
| 48 | .surrogate_assigner |
| 49 | .assign(&collection, body.doc_id.as_bytes()) |
| 50 | .map_err(|e| ApiError::Internal(e.to_string()))?; |
| 51 | |
| 52 | let plan = PhysicalPlan::Crdt(CrdtOp::Apply { |
| 53 | collection: collection.clone(), |
| 54 | document_id: body.doc_id.clone(), |
| 55 | delta, |
| 56 | peer_id: identity.user_id, |
| 57 | mutation_id: 0, |
| 58 | surrogate, |
| 59 | }); |
| 60 | |
| 61 | state.shared.tenant_request_start(identity.tenant_id); |
| 62 | let result = dispatch_plan(&state, identity.tenant_id, &collection, plan).await; |
| 63 | state.shared.tenant_request_end(identity.tenant_id); |
| 64 | |
| 65 | result?; |
| 66 | |
| 67 | Ok(axum::Json(HttpCrdtApplyResponse::ok( |
| 68 | collection, |
| 69 | body.doc_id, |
| 70 | ))) |
| 71 | } |
nothing calls this directly
no test coverage detected