Giter Club home page Giter Club logo

atrium's Introduction

ATrium

ATrium is a collection of Rust libraries designed to work with the AT Protocol, providing a versatile and coherent ecosystem for developers. The name is inspired by the concept of an "atrium" with a view of the open bluesky, reflecting the open nature of the project.

Our goal is to provide a comprehensive, easy-to-use, and efficient library that caters to various use cases and scenarios involving the AT Protocol.

Please note that ATrium is still under active development and many features may be subject to change or enhancement. We appreciate your understanding and patience during this phase.

Overview

ATrium is divided into several sub-projects to address different aspects of the AT Protocol and provide a modular design:

A library consisting of models and messaging definitions for XRPC, primarily generated using the codegen library.

Definitions for XRPC request/response, and their associated errors.

A library provides clients that implement the XrpcClient defined in atrium-xrpc

ATrium-based SDK for Bluesky.

A command-line app using this API library.

Code generation

The models and messaging definitions for XRPC are generated with these crates:

A library that provides type definitions for parsing the AT Protocol's Lexicon schema, ensuring compatibility with the lexicon.

A library that generates Rust code for the atrium-api based on the analyzed lexicon definitions.

lexgen command

cd lexicon && cargo run -p lexgen -- --lexdir $HOME/.ghq/github.com/bluesky-social/atproto/lexicons

Contribution

We welcome contributions from the community to help us improve and expand ATrium. If you're interested in contributing, please feel free to submit issues or pull requests on the GitHub repository. We appreciate your support!

License

ATrium is released under the MIT License.

Related works

Below are some related projects that might be of interest:

atrium's People

Contributors

dependabot[bot] avatar futsuuu avatar github-actions[bot] avatar naim94a avatar pmsanford avatar sanhajio avatar str4d avatar sugyan avatar timfpark avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

atrium's Issues

MST and repository parsing APIs

As part of #118, and to enable consuming #commit events from the firehose, we need APIs for parsing and interacting with MSTs and repository CARs.

[suggestion] Consider making XrpcClient::auth return an owned value

I've written a quick example client to learn about the API. One feature I wanted for my client was to use interior mutability so that the client could refresh its tokens transparently to the consumer, even behind an immutable reference. As you can see, I used a mutex for this - but the fact that auth returns Option<&str> made that pretty difficult. It would also be difficult if you wanted to, for instance, retrieve a token from the environment dynamically in the auth method. My app runs against a branch in my fork that makes the simple change of returning Option<String> instead. You mentioned you were in the middle of refactoring this trait so I thought I'd make this suggestion now.

Thanks for all the work on this! It's been fun to use.

axum support

Hey,
love the work you did so far for atrium.
Do you plan on adding axum support for the xrpc-server or what are your plans with this crate?

Best regards
icepuma

`app.bsky.feed.getPosts` fails with more than a certain number of arguments `uris`

Versions

  • atrium-api: 0.21.0
  • atrium-xrpc: 0.10.4
  • atrium-xrpc-client: 0.5.2

How to reproduce

use atrium_api::client::AtpServiceClient;
use atrium_api::types::string::AtIdentifier;
use atrium_xrpc_client::reqwest::ReqwestClient;
use itertools::Itertools;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = AtpServiceClient::new(ReqwestClient::new("https://api.bsky.app"));
    let uris = client
        .service
        .app
        .bsky
        .feed
        .get_author_feed(atrium_api::app::bsky::feed::get_author_feed::Parameters {
            actor: AtIdentifier::Handle("atproto.com".parse()?),
            cursor: None,
            filter: None,
            limit: 30.try_into().ok(),
        })
        .await?
        .feed
        .iter()
        .map(|post| post.post.uri.clone())
        .unique()
        .collect_vec();
    client
        .service
        .app
        .bsky
        .feed
        .get_posts(atrium_api::app::bsky::feed::get_posts::Parameters {
            uris: uris.into_iter().take(22).collect(),
        })
        .await?;
    Ok(())
}

Output:

Error: XrpcResponse(XrpcError { status: 400, error: Some(Undefined(ErrorResponseBody { error: Some("InvalidRequest"), message: Some("Error: uris/0 must be a valid at-uri") })) })

If .take(22) is less than 21, no error occurs.

Suggestion: Change code writer

Hey,
you folks could use a set of crates to assemble the generated code in a more structured manner:

The basic idea:

  1. Assemble lots of small TokenStreams to a large one
  2. Convert TokenStream to &str using https://docs.rs/proc-macro2/1.0.56/proc_macro2/struct.TokenStream.html#method.to_string
  3. Pipe the generated string through https://docs.rs/syn/2.0.15/syn/fn.parse_file.html to generate a https://docs.rs/syn/2.0.15/syn/struct.File.html
  4. Pipe https://docs.rs/syn/2.0.15/syn/struct.File.html through https://docs.rs/prettyplease/0.2.4/prettyplease/fn.unparse.html to have a pretty printed String

Given this approach of having a TokenStream you get proper error messages, when something is not a legit AST token and you could add your own pretty printer, ...

If the idea is not clear enough, please ask :)

`atrium_xrpc_server` isn't compatible with `tokio::spawn`

atrium_xrpc_server::stream::frames::Frame::try_from returns Result<Self, Box<dyn std::error::Error>>. The problem is that dyn std::error::Error is not Send, which means that if the result of Frame::try_from is potentially used across an await, the entire future is not Send.

To reproduce this, modify the firehose example to spawn the firehose running method instead of running it directly with #[tokio::main]. I tested this at commit 7d99ccd.

It would be helpful if the error type was Send + Sync + 'static, to also make it compatible with the anyhow crate. But that can be handled by rewriting the error as a string, whereas the future not being Send is more problematic for usage.

Error on atrium-cli get-timeline

Hello I started running atrium-cli; and came accross this error:

  (base) 22:27:12 ➜  rbsky git:(main) ✗ cargo install atrium-cli
  (base) 22:24:05 ➜  rbsky git:(main) ✗ atrium-cli --version
  atrium-cli 0.1.5

  (base) 22:25:55 ➜  rbsky git:(main) ✗ atrium-cli get-timeline
  Error: serde_json error: missing field `sig` at line 1 column 3311
  
  Caused by:
      missing field `sig` at line 1 column 3311

Remove support for surf HTTP client

I designed ATrium to allow developers to choose an async http client, and in atrium-xrpc-client I added an implementation that uses surf as one of its options.
However, this uses old rustls and appears to be in an unmaintained state.
http-rs/surf#352

I would like to remove the xrpc client implementation using surf and the related dependencies.

Upgrade to version 1.0 of the http crate?

The http crate version was upgraded to v1 in the recent reqwest v0.12.0 release.
https://github.com/seanmonstar/reqwest/blob/master/CHANGELOG.md#v0120

I'm considering upgrading http to v1 on atrium-xrpc along with this, but isahc, which can be used with atrium-xrpc-client, still depends on 0.2, and it seems it will be a few more months before isahc upgrades to v1.0, as discussed in this issue
sagebind/isahc#432

  • Maintain the current configuration unchanged until isahc supports http v1.0.
  • Temporarily remove the feature that depends on the isahc client until an updated isahc version becomes available.
  • Consider alternative approaches.

This note serves as a reminder of the current situation and the decisions that need consideration.

Progress update / coverage?

I've been exploring the rust atproto ecosystem lately and your implementation seems to be the main one still actively being developed. How much of atproto would you say you've covered so far, and what's still missing?

wasm32 support?

If we try to use ATrium in an environment such as Cloudflare Workers (not sure if there is such a use case), it will be built with --target wasm32-....

However, the current atrium-api cannot be built with that target. Perhaps we encount the following error.

future created by async block is not `Send`.

This is because async_trait converts async functions to require dyn Future + Send, which seems to cause the build to fail on the wasm32 target.
It seems that we can write #[async_trait(?Send)] to work around this limitation.
https://docs.rs/async-trait/latest/async_trait/#non-threadsafe-futures

Many projects seem to use target_arch = "wasm32" to switch whether to add ?Send or not.
ATrium seems to be able to solve this problem in the same way.
https://github.com/search?q=%22%2C+async_trait%28%3FSend%29%29%5D%22+language%3ARust&type=code

By the way, if we can change MSRV to 1.75 in the future, we won't need to use async_trait, but we will probably use trait_variant::make then.
https://blog.rust-lang.org/2023/12/21/async-fn-rpit-in-traits.html#async-fn-in-public-traits

Introduction of Builders

When dealing with Inputs or Params that have many fields, it becomes tedious to set all the values. Using libraries such as derive_builder or typed-builder, we can easily add Builders to all structs, which might make the code more concise for developers using the atrium-api.

Should we consider introducing this as an additional feature first?

Subscribe repos example?

Regarding atrium-api/src/com/atproto/sync/subscribe_repos.rs

It would be great to see some sort of example on how to use this. From brief reading of the code, it seems to not be implemented yet, as I cannot find anything regarding reading streams, events or anything like that. Is that correct?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.