MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / crdt_apply

Function crdt_apply

nodedb/src/control/server/http/routes/crdt.rs:32–71  ·  view source on GitHub ↗

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>,
)

Source from the content-addressed store, hash-verified

30/// }
31/// ```
32pub 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}

Callers

nothing calls this directly

Calls 11

resolve_identityFunction · 0.85
extract_request_idFunction · 0.85
to_stringMethod · 0.80
tenant_request_startMethod · 0.80
tenant_request_endMethod · 0.80
dispatch_planFunction · 0.70
hex_decodeFunction · 0.50
okFunction · 0.50
assignMethod · 0.45
as_bytesMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected