···11use core::fmt;2233use data_encoding::BASE64URL_NOPAD as Encoding;44-use gordian_types::{Nsid, OwnedDid};44+use gordian_types::{Nsid, DidBuf};55use serde::{Deserialize, Serialize, de::DeserializeOwned};6677use crate::verification_key::{Unspecified, VerificationKey};···6666pub struct Claims {6767 /// Account DID associated with the service that the request is being6868 /// sent to.6969- pub iss: OwnedDid,6969+ pub iss: DidBuf,70707171 /// Service DID associated with the service that the request is being7272 /// sent to.7373- pub aud: OwnedDid,7373+ pub aud: DidBuf,74747575 /// Token creation time as a UNIX timestamp.7676 pub iat: i64,
···11use std::collections::HashSet;2233-use gordian_types::OwnedDid;33+use gordian_types::DidBuf;44use serde::{Deserialize, Serialize};5566use crate::{Did, Nsid};···3030 /// Repository DIDs to filter which records are received.3131 ///3232 /// Maximum: `10_000`3333- pub wanted_dids: HashSet<OwnedDid>,3333+ pub wanted_dids: HashSet<DidBuf>,34343535 /// Maximum message size in bytes the subscriber wants to receive.3636 ///···7979 /// Returns an error if adding `did` would cause [`SubscriberOptions`] to exceed the maximum8080 /// number of subscribed DIDs.8181 ///8282- pub fn add_did(&mut self, did: OwnedDid) -> Result<bool, OwnedDid> {8282+ pub fn add_did(&mut self, did: DidBuf) -> Result<bool, DidBuf> {8383 if self.wanted_dids.len() == MAX_WANTED_DIDS && !self.wanted_dids.contains(&did) {8484 return Err(did);8585 }···218218#[serde(rename_all = "camelCase")]219219pub struct OptionsUpdate<'a> {220220 wanted_collections: &'a HashSet<Box<Nsid>>,221221- wanted_dids: &'a HashSet<OwnedDid>,221221+ wanted_dids: &'a HashSet<DidBuf>,222222 #[serde(with = "max_message_size")]223223 max_message_size_bytes: &'a i64,224224}
+2-2
crates/gordian-knot/src/cli/hook.rs
···8899use axum::http::{HeaderMap, HeaderName, HeaderValue};1010use bytes::Bytes;1111-use gordian_types::OwnedDid;1111+use gordian_types::DidBuf;1212use reqwest::header::InvalidHeaderName;1313use url::Url;1414···24242525 /// DID of the repository owner.2626 #[arg(long, env = gordian_knot::private::ENV_REPO_DID)]2727- pub repo_did: OwnedDid,2727+ pub repo_did: DidBuf,28282929 /// Record key of the repository.3030 #[arg(long, env = gordian_knot::private::ENV_REPO_RKEY)]
+2-2
crates/gordian-knot/src/cli/serve.rs
···1313 },1414 services::database::DataStore,1515};1616-use gordian_types::OwnedDid;1616+use gordian_types::DidBuf;1717use tokio::{net::TcpListener, signal, task::JoinSet};1818use tokio_util::sync::CancellationToken;1919use tower::ServiceBuilder;···38383939 /// Handle or DID of the knot owner.4040 #[arg(long, short, env = "KNOT_OWNER")]4141- pub owner: OwnedDid,4141+ pub owner: DidBuf,42424343 /// Base path for repositories.4444 #[arg(long, short, value_hint = ValueHint::DirPath, env = "KNOT_REPO_BASE")]
+3-3
crates/gordian-knot/src/mock.rs
···33 services::database::DataStore,44};55use gordian_identity::Resolver;66-use gordian_types::OwnedDid;66+use gordian_types::DidBuf;7788pub use gordian_pds::Pds;99···2121 axum::serve(listener, pds_api).await.unwrap();2222 });23232424- let owner_did = OwnedDid::parse(owner_did).expect("owner DID must be valid");2525- let instance = OwnedDid::parse(format!("did:web:{instance_name}"))2424+ let owner_did = DidBuf::parse(owner_did).expect("owner DID must be valid");2525+ let instance = DidBuf::parse(format!("did:web:{instance_name}"))2626 .expect("instance name should form a valid DID");27272828 let database = DataStore::new(pool);
···99use gordian_lexicon::sh_tangled::git::{1010 CommitCount, CommitCountBreakdown, Language, LanguageBreakdown, Meta, RefUpdate,1111};1212-use gordian_types::OwnedDid;1212+use gordian_types::DidBuf;1313use serde::{Deserialize, Serialize};1414use time::OffsetDateTime;1515use tokio_rayon::AsyncThreadPool as _;···8585}86868787/// Extracts the 'X-Gordian-User-Did' header from a request.8888-pub struct ActorDid(pub OwnedDid);8888+pub struct ActorDid(pub DidBuf);89899090impl<S: Sync> FromRequestParts<S> for ActorDid {9191 type Rejection = (StatusCode, Cow<'static, str>);
+15-15
crates/gordian-knot/src/services/database.rs
···55use gordian_auth::jwt;66use gordian_jetstream::Value;77use gordian_lexicon::sh_tangled::{PublicKey, knot::Member, repo::Repo};88-use gordian_types::{Did, OwnedDid};88+use gordian_types::{Did, DidBuf};99use serde::Serialize;1010use sqlx::{SqlitePool, error::ErrorKind};1111use time::OffsetDateTime;···6262 Ok(())6363 }64646565- pub fn knot_members(&self) -> BoxStream<'_, Result<OwnedDid, DataStoreError>> {6666- sqlx::query!(r#"SELECT subject AS "subject: OwnedDid" FROM knot_member ORDER BY rkey, rev"#)6565+ pub fn knot_members(&self) -> BoxStream<'_, Result<DidBuf, DataStoreError>> {6666+ sqlx::query!(r#"SELECT subject AS "subject: DidBuf" FROM knot_member ORDER BY rkey, rev"#)6767 .fetch(&self.db)6868 .map(|record| Ok(record?.subject))6969 .boxed()7070 }71717272 /// Get all the knot members and repository collaborators associated with the knot.7373- pub fn members(&self) -> BoxStream<'_, Result<OwnedDid, DataStoreError>> {7474- sqlx::query!(r#"SELECT DISTINCT subject AS "subject: OwnedDid" FROM knot_member UNION SELECT DISTINCT subject AS "subject: OwnedDid" FROM repository_collaborator"#)7373+ pub fn members(&self) -> BoxStream<'_, Result<DidBuf, DataStoreError>> {7474+ sqlx::query!(r#"SELECT DISTINCT subject AS "subject: DidBuf" FROM knot_member UNION SELECT DISTINCT subject AS "subject: DidBuf" FROM repository_collaborator"#)7575 .fetch(&self.db)7676 .map(|record| Ok(record?.subject))7777 .boxed()···121121 &self,122122 rkey: &str,123123 rev: &str,124124- ) -> Result<Option<OwnedDid>, DataStoreError> {124124+ ) -> Result<Option<DidBuf>, DataStoreError> {125125 let result = sqlx::query!(126126- r#"DELETE FROM knot_member WHERE rkey = ? AND rev <= ? RETURNING subject AS "subject: OwnedDid""#,126126+ r#"DELETE FROM knot_member WHERE rkey = ? AND rev <= ? RETURNING subject AS "subject: DidBuf""#,127127 rkey,128128 rev129129 )···183183 &self,184184 did: &Did,185185 rkey: &str,186186- ) -> Result<(OwnedDid, String, OwnedDid), DataStoreError> {186186+ ) -> Result<(DidBuf, String, DidBuf), DataStoreError> {187187 let result = sqlx::query!(188188- r#"SELECT repo_did as "repo_did: OwnedDid", repo_rkey, subject as "subject: OwnedDid" FROM repository_collaborator WHERE did = ? AND rkey = ?"#,188188+ r#"SELECT repo_did as "repo_did: DidBuf", repo_rkey, subject as "subject: DidBuf" FROM repository_collaborator WHERE did = ? AND rkey = ?"#,189189 did,190190 rkey191191 )···200200 did: &Did,201201 rkey: &str,202202 rev: &str,203203- ) -> Result<Option<OwnedDid>, DataStoreError> {203203+ ) -> Result<Option<DidBuf>, DataStoreError> {204204 let result = sqlx::query!(205205- r#"DELETE FROM repository_collaborator WHERE did = ? AND rkey = ? AND rev <= ? RETURNING subject AS "subject: OwnedDid""#,205205+ r#"DELETE FROM repository_collaborator WHERE did = ? AND rkey = ? AND rev <= ? RETURNING subject AS "subject: DidBuf""#,206206 did,207207 rkey,208208 rev···271271 rev: &str,272272 ) -> Result<Option<DeletedRecord>, DataStoreError> {273273 let record = sqlx::query!(274274- r#"DELETE FROM public_key WHERE did = ? AND rkey = ? AND rev <= ? RETURNING did AS "did: OwnedDid", rkey, rev, cid"#,274274+ r#"DELETE FROM public_key WHERE did = ? AND rkey = ? AND rev <= ? RETURNING did AS "did: DidBuf", rkey, rev, cid"#,275275 did,276276 rkey,277277 rev···354354 subject: &Did,355355 ) -> Result<bool, DataStoreError> {356356 let member = sqlx::query!(357357- r#"SELECT repo_did as "repo_did: OwnedDid", repo_rkey, subject as "subject: OwnedDid" FROM repository_collaborator WHERE repo_did = ? AND repo_rkey = ? AND subject = ?"#,357357+ r#"SELECT repo_did as "repo_did: DidBuf", repo_rkey, subject as "subject: DidBuf" FROM repository_collaborator WHERE repo_did = ? AND repo_rkey = ? AND subject = ?"#,358358 repo_did,359359 repo_rkey,360360 subject···369369370370 pub async fn is_knot_member(&self, did: &Did) -> Result<bool, DataStoreError> {371371 let member = sqlx::query!(372372- r#"SELECT subject as "subject: OwnedDid" FROM knot_member WHERE subject = ? LIMIT 1"#,372372+ r#"SELECT subject as "subject: DidBuf" FROM knot_member WHERE subject = ? LIMIT 1"#,373373 did,374374 )375375 .fetch_optional(&self.db)···527527 assert_eq!(rec.collection, "sh.tangled.repo");528528529529 let record = sqlx::query!(530530- r#"DELETE FROM repository WHERE did = ? AND rkey = ? AND rev <= ? RETURNING did AS "did: OwnedDid", rkey, rev, cid, name"#,530530+ r#"DELETE FROM repository WHERE did = ? AND rkey = ? AND rev <= ? RETURNING did AS "did: DidBuf", rkey, rev, cid, name"#,531531 rec.did,532532 rec.rkey,533533 rec.rev
···11-use gordian_types::OwnedDid;11+use gordian_types::DidBuf;22use serde::{Deserialize, Serialize};3344use crate::extra::objectid::ObjectId;···1313 pub r#ref: String,14141515 /// DID of the user that push this ref.1616- pub committer_did: OwnedDid,1616+ pub committer_did: DidBuf,17171818 /// DID of the owner of the repo.1919- pub repo_did: OwnedDid,1919+ pub repo_did: DidBuf,20202121 /// Name of the repo.2222 pub repo_name: String,
···22//! <https://tangled.org/@tangled.org/core/blob/master/lexicons/repo/delete.json>33//!4455-use gordian_types::OwnedDid;55+use gordian_types::DidBuf;66use serde::{Deserialize, Serialize};7788/// Parameters for the `sh.tangled.repo.delete` procedure.···1212#[serde(rename_all = "camelCase")]1313pub struct Input {1414 /// DID of the repository owner.1515- pub did: OwnedDid,1515+ pub did: DidBuf,16161717 /// Record key of the repository record.1818 pub rkey: String,
···33//!44use std::borrow::Cow;5566-use gordian_types::OwnedDid;66+use gordian_types::DidBuf;77use serde::{Deserialize, Serialize};8899/// Parameters for the `sh.tangled.repo.mergeCheck` query.···1212#[derive(Debug, Deserialize)]1313pub struct Input {1414 /// DID of the repository owner1515- pub did: OwnedDid,1515+ pub did: DidBuf,16161717 /// Name of the repository1818 pub name: String,
···1515 http::StatusCode,1616 response::IntoResponse,1717 };1818- use gordian_types::OwnedDid;1818+ use gordian_types::DidBuf;1919 use serde_json::Value;2020 use sqlx::Row as _;2121···36363737 #[derive(serde::Deserialize)]3838 pub struct Params {3939- repo: OwnedDid,3939+ repo: DidBuf,4040 collection: String,4141 rkey: String,4242 cid: Option<String>,···88888989 #[derive(serde::Deserialize)]9090 struct Params {9191- repo: OwnedDid,9191+ repo: DidBuf,9292 collection: String,9393 }9494
+2-2
crates/gordian-pds/src/state.rs
···88use futures_util::FutureExt as _;99use gordian_auth::jwt;1010use gordian_identity::DidDocument;1111-use gordian_types::{OwnedDid, Tid};1111+use gordian_types::{DidBuf, Tid};1212use sqlx::{1313 SqlitePool,1414 sqlite::{SqliteConnectOptions, SqlitePoolOptions},···173173 fn resolve_handle<'s: 'h, 'h>(174174 &'s self,175175 handle: &'h str,176176- ) -> futures_util::future::BoxFuture<'h, Result<OwnedDid, gordian_identity::ResolveError>> {176176+ ) -> futures_util::future::BoxFuture<'h, Result<DidBuf, gordian_identity::ResolveError>> {177177 use sqlx::Row as _;178178 async move {179179 let result = sqlx::query("SELECT did FROM identity WHERE handle = ?")
+32-32
crates/gordian-types/src/did.rs
···185185186186/// An owned [`Did`] buffer with small-string optimization.187187#[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]188188-pub struct OwnedDid {188188+pub struct DidBuf {189189 inner: SmallDid,190190}191191192192-impl OwnedDid {192192+impl DidBuf {193193 fn new(did: impl Into<SmallDid>) -> Self {194194 let inner = did.into();195195 Self { inner }···231231 }232232}233233234234-impl fmt::Debug for OwnedDid {234234+impl fmt::Debug for DidBuf {235235 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {236236 fmt::Debug::fmt(&self.inner, f)237237 }238238}239239240240-impl fmt::Display for OwnedDid {240240+impl fmt::Display for DidBuf {241241 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {242242 fmt::Display::fmt(&self.inner, f)243243 }244244}245245246246-impl AsRef<Did> for OwnedDid {246246+impl AsRef<Did> for DidBuf {247247 #[inline]248248 fn as_ref(&self) -> &Did {249249 Did::new(&self.inner)250250 }251251}252252253253-impl borrow::Borrow<Did> for OwnedDid {253253+impl borrow::Borrow<Did> for DidBuf {254254 fn borrow(&self) -> &Did {255255 Did::new(&self.inner)256256 }257257}258258259259impl ToOwned for Did {260260- type Owned = OwnedDid;260260+ type Owned = DidBuf;261261 #[inline]262262 fn to_owned(&self) -> Self::Owned {263263- OwnedDid::new(self.as_str())263263+ DidBuf::new(self.as_str())264264 }265265}266266267267-impl ops::Deref for OwnedDid {267267+impl ops::Deref for DidBuf {268268 type Target = Did;269269 fn deref(&self) -> &Self::Target {270270 self.as_ref()271271 }272272}273273274274-impl From<&Did> for OwnedDid {274274+impl From<&Did> for DidBuf {275275 fn from(value: &Did) -> Self {276276 value.to_owned()277277 }···279279280280macro_rules! impl_owned_tryfrom {281281 ($t:ty) => {282282- impl TryFrom<$t> for OwnedDid {282282+ impl TryFrom<$t> for DidBuf {283283 type Error = Error;284284 fn try_from(value: $t) -> Result<Self, Self::Error> {285285 validate_did(&value)?;···293293impl_owned_tryfrom!(String);294294impl_owned_tryfrom!(Box<str>);295295296296-impl std::str::FromStr for OwnedDid {296296+impl std::str::FromStr for DidBuf {297297 type Err = Error;298298 fn from_str(s: &str) -> Result<Self, Self::Err> {299299 s.try_into()300300 }301301}302302303303-impl From<OwnedDid> for std::borrow::Cow<'_, Did> {303303+impl From<DidBuf> for std::borrow::Cow<'_, Did> {304304 #[inline]305305- fn from(value: OwnedDid) -> Self {305305+ fn from(value: DidBuf) -> Self {306306 std::borrow::Cow::Owned(value)307307 }308308}···314314 }315315}316316317317-impl From<std::borrow::Cow<'_, Did>> for OwnedDid {317317+impl From<std::borrow::Cow<'_, Did>> for DidBuf {318318 fn from(value: std::borrow::Cow<'_, Did>) -> Self {319319 use std::borrow::Cow;320320 match value {···324324 }325325}326326327327-impl_partial_eq!(OwnedDid, &Did);328328-impl_partial_eq!(OwnedDid, &str);327327+impl_partial_eq!(DidBuf, &Did);328328+impl_partial_eq!(DidBuf, &str);329329330330#[cfg(feature = "serde")]331331-impl_str_wrapper_serde!(Did, OwnedDid);331331+impl_str_wrapper_serde!(Did, DidBuf);332332333333#[cfg(feature = "sqlx")]334334mod sqlx_impl {335335- use super::{Did, OwnedDid};335335+ use super::{Did, DidBuf};336336 impl_str_wrapper_sqlx!(ref Did);337337 impl_str_wrapper_sqlx!(Box<Did>);338338- impl_str_wrapper_sqlx!(OwnedDid);338338+ impl_str_wrapper_sqlx!(DidBuf);339339}340340341341#[cfg(test)]342342mod tests {343343- use super::{Did, Error, OwnedDid};343343+ use super::{Did, DidBuf, Error};344344345345 /// An example DID.346346 const EXAMPLE_DID: &str = "did:plc:65gha4t3avpfpzmvpbwovss7";···414414 #[should_panic]415415 fn reject_invalid_static() {416416 let _ = Did::from_static("did:_plc:asdf");417417- let _ = OwnedDid::from_static("did:plc65gha4t3avpfpzmvpbwovss7");417417+ let _ = DidBuf::from_static("did:plc65gha4t3avpfpzmvpbwovss7");418418 }419419420420 #[test]···424424 assert_eq!(format!("{did}"), EXAMPLE_DID);425425 assert_eq!(format!("{did:?}"), format!("{EXAMPLE_DID:?}"));426426427427- let owned: OwnedDid = did.into();427427+ let owned: DidBuf = did.into();428428 assert_eq!(format!("{owned}"), EXAMPLE_DID);429429 assert_eq!(format!("{owned:?}"), format!("{EXAMPLE_DID:?}"));430430 }···436436437437 #[test]438438 fn can_parse_to_owned() {439439- let _: OwnedDid = EXAMPLE_DID.parse().unwrap();439439+ let _: DidBuf = EXAMPLE_DID.parse().unwrap();440440 }441441442442 #[test]443443 fn can_convert_static() {444444 let _: &'static str = EXAMPLE_DID.try_into().unwrap();445445- let _: OwnedDid = EXAMPLE_DID.try_into().unwrap();446446- let _ = OwnedDid::from_static(EXAMPLE_DID);445445+ let _: DidBuf = EXAMPLE_DID.try_into().unwrap();446446+ let _ = DidBuf::from_static(EXAMPLE_DID);447447 }448448449449 #[test]···499499 fn can_serde_owned() {500500 #[derive(serde::Deserialize, serde::Serialize)]501501 struct Test {502502- did: OwnedDid,502502+ did: DidBuf,503503 }504504505505 let test = Test {506506- did: OwnedDid::from_static(EXAMPLE_DID),506506+ did: DidBuf::from_static(EXAMPLE_DID),507507 };508508509509 let json = serde_json::to_string(&test).unwrap();···603603 did: Cow<'a, Did>,604604 }605605606606- let did = OwnedDid::parse(EXAMPLE_DID).unwrap();606606+ let did = DidBuf::parse(EXAMPLE_DID).unwrap();607607 let test = Test {608608 did: Cow::Owned(did),609609 };···620620 fn can_convert_cow() {621621 use std::borrow::Cow;622622623623- let did = OwnedDid::from_static(EXAMPLE_DID);623623+ let did = DidBuf::from_static(EXAMPLE_DID);624624 let cow: Cow<_> = did.into();625625 assert!(matches!(cow, Cow::Owned(_)));626626627627 // Convert back to owned.628628- let _: OwnedDid = cow.into();628628+ let _: DidBuf = cow.into();629629630630 let did = Did::from_static(EXAMPLE_DID);631631 let cow: Cow<_> = did.into();···634634635635 #[test]636636 fn owned_plc_doesnt_allocate() {637637- let did = OwnedDid::parse("did:plc:65gha4t3avpfpzmvpbwovss7").unwrap();637637+ let did = DidBuf::parse("did:plc:65gha4t3avpfpzmvpbwovss7").unwrap();638638 assert!(!did.inner.spilled(), "DID PLC should not spill onto heap");639639 }640640}
+1-1
crates/gordian-types/src/lib.rs
···1111pub mod tid;1212pub mod uri;13131414-pub use did::{Did, OwnedDid};1414+pub use did::{Did, DidBuf};1515pub use handle::Handle;1616pub use nsid::Nsid;1717pub use tid::{Tid, TidClock};
+4-4
crates/gordian-types/src/uri.rs
···11-use crate::{Did, did::OwnedDid};11+use crate::{Did, did::DidBuf};2233/// A fully defined Atmosphere URI pointing to a record.44///···66///77#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]88pub struct RecordUri {99- pub authority: OwnedDid,99+ pub authority: DidBuf,1010 pub collection: String,1111 pub rkey: String,1212}13131414impl RecordUri {1515 pub fn new(1616- authority: impl Into<OwnedDid>,1616+ authority: impl Into<DidBuf>,1717 collection: impl Into<String>,1818 rkey: impl Into<String>,1919 ) -> Self {···6060 let mut parts = uri.splitn(3, '/');6161 let authority = parts6262 .next()6363- .map(OwnedDid::parse)6363+ .map(DidBuf::parse)6464 .transpose()?6565 .ok_or(Error::Error)?;6666 let collection = parts.next().ok_or(Error::Error)?.to_string();