···1//! PDS repository endpoints /xrpc/com.atproto.repo.*)
0002use std::{collections::HashSet, str::FromStr};
34use anyhow::{Context as _, anyhow};
5-use atrium_api::com::atproto::repo::apply_writes::{self, InputWritesItem, OutputResultsItem};
006use atrium_api::{
7 com::atproto::repo::{self, defs::CommitMetaData},
8 types::{
···25use serde::Deserialize;
26use tokio::io::AsyncWriteExt as _;
270028use crate::{
29 AppState, Db, Error, Result, SigningKey,
30 actor_store::{ActorStore, ActorStoreReader, ActorStoreTransactor, ActorStoreWriter},
···111 Ok((did.to_owned(), handle.to_owned()))
112}
113114-/// Apply a batch transaction of repository creates, updates, and deletes. Requires auth, implemented by PDS.
115-/// - POST /xrpc/com.atproto.repo.applyWrites
116-/// ### Request Body
117-/// - `repo`: `at-identifier` // The handle or DID of the repo (aka, current account).
118-/// - `validate`: `boolean` // Can be set to 'false' to skip Lexicon schema validation of record data across all operations, 'true' to require it, or leave unset to validate only for known Lexicons.
119-/// - `writes`: `object[]` // One of:
120-/// - - com.atproto.repo.applyWrites.create
121-/// - - com.atproto.repo.applyWrites.update
122-/// - - com.atproto.repo.applyWrites.delete
123-/// - `swap_commit`: `cid` // If provided, the entire operation will fail if the current repo commit CID does not match this value. Used to prevent conflicting repo mutations.
124-async fn apply_writes(
125- user: AuthenticatedUser,
126- State(actor_store): State<ActorStore>,
127- State(skey): State<SigningKey>,
128- State(config): State<AppConfig>,
129- State(db): State<Db>,
130- State(fhp): State<FirehoseProducer>,
131- Json(input): Json<repo::apply_writes::Input>,
132-) -> Result<Json<repo::apply_writes::Output>> {
133- // TODO: Implement validation when `input.validate` is set
134-135- // Ensure that we are updating the correct repository.
136- todo!();
137- // Convert ATProto writes to our internal format
138- todo!();
139- // Process the writes using the actor store
140- todo!();
141-142- // Update metrics
143- counter!(REPO_COMMITS).increment(1);
144- todo!();
145-146- // Send commit to firehose
147- todo!();
148-149- // Convert to API response format
150- todo!();
151-}
152-153/// Create a single new repository record. Requires auth, implemented by PDS.
154/// - POST /xrpc/com.atproto.repo.createRecord
155/// ### Request Body
···172 State(fhp): State<FirehoseProducer>,
173 Json(input): Json<repo::create_record::Input>,
174) -> Result<Json<repo::create_record::Output>> {
175- let write_result = apply_writes(
176 user,
177 State(actor_store),
178 State(skey),
···265 }
266 .into();
267268- let write_result = apply_writes(
269 user,
270 State(actor_store),
271 State(skey),
···329330 Ok(Json(
331 repo::delete_record::OutputData {
332- commit: apply_writes(
333 user,
334 State(actor_store),
335 State(skey),