mirror of
https://git.asonix.dog/asonix/activitystreams.git
synced 2024-06-09 16:59:23 +00:00
Compare commits
4 commits
8bf3f2fc17
...
2d2756c2bb
Author | SHA1 | Date | |
---|---|---|---|
2d2756c2bb | |||
658f832d08 | |||
b928f8e77f | |||
8f9e2a3f3c |
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -2,3 +2,5 @@
|
||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
Cargo.lock
|
Cargo.lock
|
||||||
/*/target
|
/*/target
|
||||||
|
/.direnv
|
||||||
|
/.envrc
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "activitystreams"
|
name = "activitystreams"
|
||||||
description = "A set of core types and traits for activitystreams data"
|
description = "A set of core types and traits for activitystreams data"
|
||||||
version = "0.7.0-alpha.24"
|
version = "0.7.0-alpha.25"
|
||||||
license = "GPL-3.0"
|
license = "GPL-3.0"
|
||||||
authors = ["asonix <asonix@asonix.dog>"]
|
authors = ["asonix <asonix@asonix.dog>"]
|
||||||
repository = "https://git.asonix.dog/asonix/activitystreams"
|
repository = "https://git.asonix.dog/asonix/activitystreams"
|
||||||
|
|
61
flake.lock
Normal file
61
flake.lock
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"flake-utils": {
|
||||||
|
"inputs": {
|
||||||
|
"systems": "systems"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1687709756,
|
||||||
|
"narHash": "sha256-Y5wKlQSkgEK2weWdOu4J3riRd+kV/VCgHsqLNTTWQ/0=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "dbabf0ca0c0c4bce6ea5eaf65af5cb694d2082c7",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1688590700,
|
||||||
|
"narHash": "sha256-ZF055rIUP89cVwiLpG5xkJzx00gEuuGFF60Bs/LM3wc=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "f292b4964cb71f9dfbbd30dc9f511d6165cd109b",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixos-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-utils": "flake-utils",
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"systems": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1681028828,
|
||||||
|
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
25
flake.nix
Normal file
25
flake.nix
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
{
|
||||||
|
description = "activitystreams";
|
||||||
|
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
|
flake-utils.url = "github:numtide/flake-utils";
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = { self, nixpkgs, flake-utils }:
|
||||||
|
flake-utils.lib.eachDefaultSystem (system:
|
||||||
|
let
|
||||||
|
pkgs = import nixpkgs {
|
||||||
|
inherit system;
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
packages.default = pkgs.hello;
|
||||||
|
|
||||||
|
devShell = with pkgs; mkShell {
|
||||||
|
nativeBuildInputs = [ cargo cargo-outdated cargo-zigbuild clippy gcc protobuf rust-analyzer rustc rustfmt ];
|
||||||
|
|
||||||
|
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
77
src/actor.rs
77
src/actor.rs
|
@ -21,6 +21,8 @@
|
||||||
//! # Ok(())
|
//! # Ok(())
|
||||||
//! # }
|
//! # }
|
||||||
//! ```
|
//! ```
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
base::{AsBase, Base, Extends},
|
base::{AsBase, Base, Extends},
|
||||||
checked::CheckError,
|
checked::CheckError,
|
||||||
|
@ -823,7 +825,7 @@ pub trait ApActorExt: AsApActor {
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
fn endpoints<'a>(&'a self) -> Result<Option<Endpoints<&'a IriString>>, CheckError>
|
fn endpoints<'a>(&'a self) -> Result<Option<&'a Endpoints<IriString>>, CheckError>
|
||||||
where
|
where
|
||||||
Self: BaseExt,
|
Self: BaseExt,
|
||||||
Self::Inner: 'a,
|
Self::Inner: 'a,
|
||||||
|
@ -833,28 +835,38 @@ pub trait ApActorExt: AsApActor {
|
||||||
|
|
||||||
endpoints
|
endpoints
|
||||||
.proxy_url
|
.proxy_url
|
||||||
|
.as_ref()
|
||||||
.map(|i| check_opt(i, authority_opt.as_ref()))
|
.map(|i| check_opt(i, authority_opt.as_ref()))
|
||||||
.transpose()?;
|
.transpose()?;
|
||||||
endpoints
|
endpoints
|
||||||
.oauth_authorization_endpoint
|
.oauth_authorization_endpoint
|
||||||
|
.as_ref()
|
||||||
.map(|i| check_opt(i, authority_opt.as_ref()))
|
.map(|i| check_opt(i, authority_opt.as_ref()))
|
||||||
.transpose()?;
|
.transpose()?;
|
||||||
endpoints
|
endpoints
|
||||||
.oauth_token_endpoint
|
.oauth_token_endpoint
|
||||||
|
.as_ref()
|
||||||
.map(|i| check_opt(i, authority_opt.as_ref()))
|
.map(|i| check_opt(i, authority_opt.as_ref()))
|
||||||
.transpose()?;
|
.transpose()?;
|
||||||
endpoints
|
endpoints
|
||||||
.provide_client_key
|
.provide_client_key
|
||||||
|
.as_ref()
|
||||||
.map(|i| check_opt(i, authority_opt.as_ref()))
|
.map(|i| check_opt(i, authority_opt.as_ref()))
|
||||||
.transpose()?;
|
.transpose()?;
|
||||||
endpoints
|
endpoints
|
||||||
.sign_client_key
|
.sign_client_key
|
||||||
|
.as_ref()
|
||||||
.map(|i| check_opt(i, authority_opt.as_ref()))
|
.map(|i| check_opt(i, authority_opt.as_ref()))
|
||||||
.transpose()?;
|
.transpose()?;
|
||||||
endpoints
|
endpoints
|
||||||
.shared_inbox
|
.shared_inbox
|
||||||
|
.as_ref()
|
||||||
.map(|i| check_opt(i, authority_opt.as_ref()))
|
.map(|i| check_opt(i, authority_opt.as_ref()))
|
||||||
.transpose()?;
|
.transpose()?;
|
||||||
|
endpoints
|
||||||
|
.nonstandard
|
||||||
|
.values()
|
||||||
|
.try_for_each(|v| check_opt(v, authority_opt.as_ref()))?;
|
||||||
|
|
||||||
return Ok(Some(endpoints));
|
return Ok(Some(endpoints));
|
||||||
}
|
}
|
||||||
|
@ -873,11 +885,11 @@ pub trait ApActorExt: AsApActor {
|
||||||
/// println!("{:?}", endpoints);
|
/// println!("{:?}", endpoints);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
fn endpoints_unchecked<'a>(&'a self) -> Option<Endpoints<&'a IriString>>
|
fn endpoints_unchecked<'a>(&'a self) -> Option<&'a Endpoints<IriString>>
|
||||||
where
|
where
|
||||||
Self::Inner: 'a,
|
Self::Inner: 'a,
|
||||||
{
|
{
|
||||||
self.ap_actor_ref().endpoints.as_ref().map(|e| e.as_ref())
|
self.ap_actor_ref().endpoints.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mutably fetch the endpoints for the current actor
|
/// Mutably fetch the endpoints for the current actor
|
||||||
|
@ -894,11 +906,11 @@ pub trait ApActorExt: AsApActor {
|
||||||
/// println!("{:?}", endpoints);
|
/// println!("{:?}", endpoints);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
fn endpoints_mut<'a>(&'a mut self) -> Option<Endpoints<&'a mut IriString>>
|
fn endpoints_mut<'a>(&'a mut self) -> Option<&'a mut Endpoints<IriString>>
|
||||||
where
|
where
|
||||||
Self::Inner: 'a,
|
Self::Inner: 'a,
|
||||||
{
|
{
|
||||||
self.ap_actor_mut().endpoints.as_mut().map(|e| e.as_mut())
|
self.ap_actor_mut().endpoints.as_mut()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the endpoints for the current actor
|
/// Set the endpoints for the current actor
|
||||||
|
@ -1139,6 +1151,14 @@ pub struct Endpoints<T> {
|
||||||
/// - Functional: true
|
/// - Functional: true
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub shared_inbox: Option<T>,
|
pub shared_inbox: Option<T>,
|
||||||
|
|
||||||
|
/// Any nonstandard endpoints present in the endpoints record end up here.
|
||||||
|
///
|
||||||
|
/// Software like Pleroma and Akkoma provide additional URLs here and extending Endpoints
|
||||||
|
/// specifically the way objects are normally extended isn't possible for nested structs like
|
||||||
|
/// this.
|
||||||
|
#[serde(flatten)]
|
||||||
|
pub nonstandard: HashMap<String, T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A simple type to create an Actor out of any Object
|
/// A simple type to create an Actor out of any Object
|
||||||
|
@ -1325,47 +1345,6 @@ impl<Inner> ApActor<Inner> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Endpoints<T> {
|
impl<T> Endpoints<T> {
|
||||||
/// Borrow the current Endpoints struct
|
|
||||||
///
|
|
||||||
/// ```rust
|
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
|
||||||
/// use activitystreams::{actor::Endpoints, iri};
|
|
||||||
/// use iri_string::types::IriString;
|
|
||||||
///
|
|
||||||
/// let uri = iri!("https://example.com");
|
|
||||||
///
|
|
||||||
/// let endpoints: Endpoints<IriString> = Endpoints {
|
|
||||||
/// shared_inbox: Some(uri.clone()),
|
|
||||||
/// ..Default::default()
|
|
||||||
/// };
|
|
||||||
///
|
|
||||||
/// assert_eq!(endpoints.as_ref().shared_inbox, Some(&uri));
|
|
||||||
/// # Ok(())
|
|
||||||
/// # }
|
|
||||||
/// ```
|
|
||||||
pub fn as_ref(&self) -> Endpoints<&T> {
|
|
||||||
Endpoints {
|
|
||||||
proxy_url: self.proxy_url.as_ref(),
|
|
||||||
oauth_authorization_endpoint: self.oauth_authorization_endpoint.as_ref(),
|
|
||||||
oauth_token_endpoint: self.oauth_token_endpoint.as_ref(),
|
|
||||||
provide_client_key: self.provide_client_key.as_ref(),
|
|
||||||
sign_client_key: self.sign_client_key.as_ref(),
|
|
||||||
shared_inbox: self.shared_inbox.as_ref(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Mutably borrow the endpoints struct
|
|
||||||
pub fn as_mut(&mut self) -> Endpoints<&mut T> {
|
|
||||||
Endpoints {
|
|
||||||
proxy_url: self.proxy_url.as_mut(),
|
|
||||||
oauth_authorization_endpoint: self.oauth_authorization_endpoint.as_mut(),
|
|
||||||
oauth_token_endpoint: self.oauth_token_endpoint.as_mut(),
|
|
||||||
provide_client_key: self.provide_client_key.as_mut(),
|
|
||||||
sign_client_key: self.sign_client_key.as_mut(),
|
|
||||||
shared_inbox: self.shared_inbox.as_mut(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Map the URLs in Endpoints from T to U
|
/// Map the URLs in Endpoints from T to U
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
@ -1395,6 +1374,11 @@ impl<T> Endpoints<T> {
|
||||||
provide_client_key: self.provide_client_key.map(f),
|
provide_client_key: self.provide_client_key.map(f),
|
||||||
sign_client_key: self.sign_client_key.map(f),
|
sign_client_key: self.sign_client_key.map(f),
|
||||||
shared_inbox: self.shared_inbox.map(f),
|
shared_inbox: self.shared_inbox.map(f),
|
||||||
|
nonstandard: self
|
||||||
|
.nonstandard
|
||||||
|
.into_iter()
|
||||||
|
.map(|(k, v)| (k, (f)(v)))
|
||||||
|
.collect(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1408,6 +1392,7 @@ impl<T> Default for Endpoints<T> {
|
||||||
provide_client_key: None,
|
provide_client_key: None,
|
||||||
sign_client_key: None,
|
sign_client_key: None,
|
||||||
shared_inbox: None,
|
shared_inbox: None,
|
||||||
|
nonstandard: HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,7 +222,16 @@ impl From<&str> for Unit {
|
||||||
|
|
||||||
/// A list of units of length that represent valid units for certain ActivityStreams objects
|
/// A list of units of length that represent valid units for certain ActivityStreams objects
|
||||||
#[derive(
|
#[derive(
|
||||||
Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, serde::Deserialize, serde::Serialize,
|
Clone,
|
||||||
|
Debug,
|
||||||
|
Default,
|
||||||
|
Eq,
|
||||||
|
Hash,
|
||||||
|
Ord,
|
||||||
|
PartialEq,
|
||||||
|
PartialOrd,
|
||||||
|
serde::Deserialize,
|
||||||
|
serde::Serialize,
|
||||||
)]
|
)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
enum Length {
|
enum Length {
|
||||||
|
@ -238,6 +247,7 @@ enum Length {
|
||||||
#[serde(rename = "km")]
|
#[serde(rename = "km")]
|
||||||
Kilometers,
|
Kilometers,
|
||||||
|
|
||||||
|
#[default]
|
||||||
#[serde(rename = "m")]
|
#[serde(rename = "m")]
|
||||||
Meters,
|
Meters,
|
||||||
}
|
}
|
||||||
|
@ -276,12 +286,6 @@ impl Length {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Length {
|
|
||||||
fn default() -> Self {
|
|
||||||
Length::Meters
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::str::FromStr for Length {
|
impl std::str::FromStr for Length {
|
||||||
type Err = LengthError;
|
type Err = LengthError;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue