From b1f365edbb7fef79f343d8b4996e3d5d68f085aa Mon Sep 17 00:00:00 2001 From: zertex Date: Fri, 22 Sep 2023 20:44:25 -0400 Subject: [PATCH 01/35] Update GuildDefaults to use new enums --- src/types/config/types/subconfigs/defaults/guild.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/types/config/types/subconfigs/defaults/guild.rs b/src/types/config/types/subconfigs/defaults/guild.rs index 966c7af..a709f82 100644 --- a/src/types/config/types/subconfigs/defaults/guild.rs +++ b/src/types/config/types/subconfigs/defaults/guild.rs @@ -1,13 +1,15 @@ use serde::{Deserialize, Serialize}; +use crate::types::{ExplicitContentFilterLevel, MessageNotificationLevel}; + #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct GuildDefaults { pub max_presences: u64, pub max_video_channel_users: u16, pub afk_timeout: u16, - pub default_message_notifications: u8, - pub explicit_content_filter: u8, + pub default_message_notifications: MessageNotificationLevel, + pub explicit_content_filter: ExplicitContentFilterLevel, } impl Default for GuildDefaults { @@ -16,8 +18,8 @@ impl Default for GuildDefaults { max_presences: 250_000, max_video_channel_users: 200, afk_timeout: 300, - default_message_notifications: 1, - explicit_content_filter: 0, + default_message_notifications: MessageNotificationLevel::OnlyMentions, + explicit_content_filter: ExplicitContentFilterLevel::Disabled, } } } From 30909212a6a53f884ab1110d09611162821d86b3 Mon Sep 17 00:00:00 2001 From: zertex Date: Fri, 22 Sep 2023 20:44:56 -0400 Subject: [PATCH 02/35] Make new enums derive sqlx::Type --- src/types/entities/guild.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/types/entities/guild.rs b/src/types/entities/guild.rs index bb4db0c..2a63ad0 100644 --- a/src/types/entities/guild.rs +++ b/src/types/entities/guild.rs @@ -343,6 +343,7 @@ pub struct VoiceRegion { } #[derive(Serialize_repr, Deserialize_repr, Debug, Default, Clone, Eq, PartialEq, Hash, Copy)] +#[cfg_attr(feature = "sqlx", derive(sqlx::Type))] #[repr(u8)] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] /// See @@ -353,6 +354,7 @@ pub enum MessageNotificationLevel { } #[derive(Serialize_repr, Deserialize_repr, Debug, Default, Clone, Eq, PartialEq, Hash, Copy)] +#[cfg_attr(feature = "sqlx", derive(sqlx::Type))] #[repr(u8)] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] /// See @@ -364,6 +366,7 @@ pub enum ExplicitContentFilterLevel { } #[derive(Serialize_repr, Deserialize_repr, Debug, Default, Clone, Eq, PartialEq, Hash, Copy)] +#[cfg_attr(feature = "sqlx", derive(sqlx::Type))] #[repr(u8)] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] /// See @@ -377,6 +380,7 @@ pub enum VerificationLevel { } #[derive(Serialize_repr, Deserialize_repr, Debug, Default, Clone, Eq, PartialEq, Hash, Copy)] +#[cfg_attr(feature = "sqlx", derive(sqlx::Type))] #[repr(u8)] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] /// See @@ -387,6 +391,7 @@ pub enum MFALevel { } #[derive(Serialize_repr, Deserialize_repr, Debug, Default, Clone, Eq, PartialEq, Hash, Copy)] +#[cfg_attr(feature = "sqlx", derive(sqlx::Type))] #[repr(u8)] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] /// See @@ -399,6 +404,7 @@ pub enum NSFWLevel { } #[derive(Serialize_repr, Deserialize_repr, Debug, Default, Clone, Eq, PartialEq, Hash, Copy)] +#[cfg_attr(feature = "sqlx", derive(sqlx::Type))] #[repr(u8)] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] /// See From f78f869f4cac6df206058b21f0419bb47addfee1 Mon Sep 17 00:00:00 2001 From: zertex Date: Fri, 22 Sep 2023 20:45:19 -0400 Subject: [PATCH 03/35] Feature lock UpdateMessage implementations --- src/types/events/guild.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/types/events/guild.rs b/src/types/events/guild.rs index 0c6bb05..89e4a75 100644 --- a/src/types/events/guild.rs +++ b/src/types/events/guild.rs @@ -29,6 +29,7 @@ pub struct GuildCreate { pub json: String, } +#[cfg(feature = "client")] impl UpdateMessage for GuildCreate { fn id(&self) -> Option { match &self.d { @@ -89,6 +90,7 @@ pub struct GuildUpdate { impl WebSocketEvent for GuildUpdate {} +#[cfg(feature = "client")] impl UpdateMessage for GuildUpdate { fn id(&self) -> Option { Some(self.guild.id) @@ -107,6 +109,7 @@ pub struct GuildDelete { pub json: String, } +#[cfg(feature = "client")] impl UpdateMessage for GuildDelete { fn id(&self) -> Option { Some(self.guild.id) From 72b954af00826906ddfc2f68bda69371f33f39b4 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Wed, 22 Nov 2023 18:38:23 +0100 Subject: [PATCH 04/35] Token login test --- tests/auth.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/auth.rs b/tests/auth.rs index 086c8ba..2b593c1 100644 --- a/tests/auth.rs +++ b/tests/auth.rs @@ -20,3 +20,36 @@ async fn test_registration() { bundle.instance.clone().register_account(reg).await.unwrap(); common::teardown(bundle).await; } + +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[cfg_attr(not(target_arch = "wasm32"), tokio::test)] +async fn test_login_with_token() { + let mut bundle = common::setup().await; + + let token = &bundle.user.token; + let other_user = bundle + .instance + .login_with_token(token.clone()) + .await + .unwrap(); + assert_eq!( + bundle.user.object.read().unwrap().id, + other_user.object.read().unwrap().id + ); + assert_eq!(bundle.user.token, other_user.token); + + common::teardown(bundle).await; +} + +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[cfg_attr(not(target_arch = "wasm32"), tokio::test)] +async fn test_login_with_invalid_token() { + let mut bundle = common::setup().await; + + let token = "invalid token lalalalala".to_string(); + let other_user = bundle.instance.login_with_token(token.clone()).await; + + assert!(other_user.is_err()); + + common::teardown(bundle).await; +} From 7954e386434e91b8b89a55fedad5ef45968f1081 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Wed, 22 Nov 2023 18:48:37 +0100 Subject: [PATCH 05/35] Change: register/login no longer require ownership Register/login used to require ownership of `instance`. This wasn't really necessary and has been changed. --- src/api/auth/login.rs | 2 +- src/api/auth/register.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/api/auth/login.rs b/src/api/auth/login.rs index 1d9fc8a..ff99be8 100644 --- a/src/api/auth/login.rs +++ b/src/api/auth/login.rs @@ -14,7 +14,7 @@ impl Instance { /// /// # Reference /// See - pub async fn login_account(mut self, login_schema: LoginSchema) -> ChorusResult { + pub async fn login_account(&mut self, login_schema: LoginSchema) -> ChorusResult { let endpoint_url = self.urls.api.clone() + "/auth/login"; let chorus_request = ChorusRequest { request: Client::new() diff --git a/src/api/auth/register.rs b/src/api/auth/register.rs index 2ea7d57..aa0b483 100644 --- a/src/api/auth/register.rs +++ b/src/api/auth/register.rs @@ -19,7 +19,7 @@ impl Instance { /// # Reference /// See pub async fn register_account( - mut self, + &mut self, register_schema: RegisterSchema, ) -> ChorusResult { let endpoint_url = self.urls.api.clone() + "/auth/register"; @@ -43,7 +43,7 @@ impl Instance { self.limits_information.as_mut().unwrap().ratelimits = shell.limits.unwrap(); } let user_object = self.get_user(token.clone(), None).await.unwrap(); - let settings = ChorusUser::get_settings(&token, &self.urls.api.clone(), &mut self).await?; + let settings = ChorusUser::get_settings(&token, &self.urls.api.clone(), self).await?; let mut identify = GatewayIdentifyPayload::common(); let gateway: GatewayHandle = Gateway::spawn(self.urls.wss.clone()).await.unwrap(); identify.token = token.clone(); From 05fd02a717343bcecc0a420f308b7df1ee8679b0 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Wed, 22 Nov 2023 18:48:44 +0100 Subject: [PATCH 06/35] Add tests for coverage --- examples/login.rs | 2 +- tests/auth.rs | 53 ++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/examples/login.rs b/examples/login.rs index b06eade..6b56a47 100644 --- a/examples/login.rs +++ b/examples/login.rs @@ -9,7 +9,7 @@ async fn main() { "wss://example.com/".to_string(), "https://example.com/cdn".to_string(), ); - let instance = Instance::new(bundle, true) + let mut instance = Instance::new(bundle, true) .await .expect("Failed to connect to the Spacebar server"); // Assume, you already have an account created on this instance. Registering an account works diff --git a/tests/auth.rs b/tests/auth.rs index 2b593c1..538e5cc 100644 --- a/tests/auth.rs +++ b/tests/auth.rs @@ -1,4 +1,6 @@ -use chorus::types::RegisterSchema; +use std::borrow::BorrowMut; + +use chorus::types::{LoginSchema, RegisterSchema}; // PRETTYFYME: Move common wasm setup to common.rs #[cfg(target_arch = "wasm32")] use wasm_bindgen_test::*; @@ -10,14 +12,59 @@ mod common; #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] #[cfg_attr(not(target_arch = "wasm32"), tokio::test)] async fn test_registration() { - let bundle = common::setup().await; + let mut bundle = common::setup().await; let reg = RegisterSchema { username: "Hiiii".into(), date_of_birth: Some("2000-01-01".to_string()), consent: true, ..Default::default() }; - bundle.instance.clone().register_account(reg).await.unwrap(); + bundle.instance.register_account(reg).await.unwrap(); + common::teardown(bundle).await; +} + +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[cfg_attr(not(target_arch = "wasm32"), tokio::test)] +async fn test_login() { + let mut bundle = common::setup().await; + let reg = RegisterSchema { + username: "Hiiii".into(), + email: Some("testuser1@integrationtesting.xyz".into()), + password: Some("Correct-Horse-Battery-Staple1".into()), + date_of_birth: Some("2000-01-01".to_string()), + consent: true, + ..Default::default() + }; + bundle.instance.register_account(reg).await.unwrap(); + let login = LoginSchema { + login: "testuser1@integrationtesting.xyz".into(), + password: "Correct-Horse-Battery-Staple1".into(), + ..Default::default() + }; + bundle.instance.login_account(login).await.unwrap(); + common::teardown(bundle).await; +} + +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[cfg_attr(not(target_arch = "wasm32"), tokio::test)] +async fn test_wrong_login() { + let mut bundle = common::setup().await; + let reg = RegisterSchema { + username: "Hiiii".into(), + email: Some("testuser2@integrationtesting.xyz".into()), + password: Some("Correct-Horse-Battery-Staple1".into()), + date_of_birth: Some("2000-01-01".to_string()), + consent: true, + ..Default::default() + }; + bundle.instance.register_account(reg).await.unwrap(); + let login = LoginSchema { + login: "testuser2@integrationtesting.xyz".into(), + password: "Correct-Horse-Battery-Staple2".into(), + ..Default::default() + }; + let res = bundle.instance.login_account(login).await; + assert!(res.is_err()); common::teardown(bundle).await; } From 9d581441e82244e8dd213fb66cf2f24a2b22df09 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Wed, 22 Nov 2023 20:54:51 +0100 Subject: [PATCH 07/35] Remove "prettyfyme" -> solved --- tests/auth.rs | 1 - tests/channels.rs | 1 - tests/gateway.rs | 1 - tests/guilds.rs | 1 - tests/instance.rs | 1 - tests/invites.rs | 1 - tests/members.rs | 1 - tests/messages.rs | 1 - tests/relationships.rs | 1 - tests/roles.rs | 1 - 10 files changed, 10 deletions(-) diff --git a/tests/auth.rs b/tests/auth.rs index 538e5cc..c105841 100644 --- a/tests/auth.rs +++ b/tests/auth.rs @@ -1,7 +1,6 @@ use std::borrow::BorrowMut; use chorus::types::{LoginSchema, RegisterSchema}; -// PRETTYFYME: Move common wasm setup to common.rs #[cfg(target_arch = "wasm32")] use wasm_bindgen_test::*; #[cfg(target_arch = "wasm32")] diff --git a/tests/channels.rs b/tests/channels.rs index 864165a..d9842c6 100644 --- a/tests/channels.rs +++ b/tests/channels.rs @@ -4,7 +4,6 @@ use chorus::types::{ }; mod common; -// PRETTYFYME: Move common wasm setup to common.rs #[cfg(target_arch = "wasm32")] use wasm_bindgen_test::*; diff --git a/tests/gateway.rs b/tests/gateway.rs index 68a203a..5bf5865 100644 --- a/tests/gateway.rs +++ b/tests/gateway.rs @@ -5,7 +5,6 @@ use std::sync::{Arc, RwLock}; use chorus::errors::GatewayError; use chorus::gateway::*; use chorus::types::{self, ChannelModifySchema, RoleCreateModifySchema, RoleObject}; -// PRETTYFYME: Move common wasm setup to common.rs #[cfg(target_arch = "wasm32")] use wasm_bindgen_test::*; #[cfg(target_arch = "wasm32")] diff --git a/tests/guilds.rs b/tests/guilds.rs index 360113d..ab955de 100644 --- a/tests/guilds.rs +++ b/tests/guilds.rs @@ -3,7 +3,6 @@ use chorus::types::{ }; mod common; -// PRETTYFYME: Move common wasm setup to common.rs #[cfg(target_arch = "wasm32")] use wasm_bindgen_test::*; #[cfg(target_arch = "wasm32")] diff --git a/tests/instance.rs b/tests/instance.rs index 56f4d6d..f1243a5 100644 --- a/tests/instance.rs +++ b/tests/instance.rs @@ -1,5 +1,4 @@ mod common; -// PRETTYFYME: Move common wasm setup to common.rs #[cfg(target_arch = "wasm32")] use wasm_bindgen_test::*; #[cfg(target_arch = "wasm32")] diff --git a/tests/invites.rs b/tests/invites.rs index d830ee8..ae1b9ab 100644 --- a/tests/invites.rs +++ b/tests/invites.rs @@ -1,6 +1,5 @@ mod common; use chorus::types::CreateChannelInviteSchema; -// PRETTYFYME: Move common wasm setup to common.rs #[cfg(target_arch = "wasm32")] use wasm_bindgen_test::*; #[cfg(target_arch = "wasm32")] diff --git a/tests/members.rs b/tests/members.rs index c9072ef..9b415c3 100644 --- a/tests/members.rs +++ b/tests/members.rs @@ -1,5 +1,4 @@ use chorus::{errors::ChorusResult, types::GuildMember}; -// PRETTYFYME: Move common wasm setup to common.rs #[cfg(target_arch = "wasm32")] use wasm_bindgen_test::*; #[cfg(target_arch = "wasm32")] diff --git a/tests/messages.rs b/tests/messages.rs index fc59a42..7ff7598 100644 --- a/tests/messages.rs +++ b/tests/messages.rs @@ -2,7 +2,6 @@ use std::fs::File; use std::io::{BufReader, Read}; use chorus::types::{self, Guild, Message, MessageSearchQuery}; -// PRETTYFYME: Move common wasm setup to common.rs #[cfg(target_arch = "wasm32")] use wasm_bindgen_test::*; #[cfg(target_arch = "wasm32")] diff --git a/tests/relationships.rs b/tests/relationships.rs index 156f6eb..c8ee9cc 100644 --- a/tests/relationships.rs +++ b/tests/relationships.rs @@ -1,5 +1,4 @@ use chorus::types::{self, Relationship, RelationshipType}; -// PRETTYFYME: Move common wasm setup to common.rs #[cfg(target_arch = "wasm32")] use wasm_bindgen_test::*; #[cfg(target_arch = "wasm32")] diff --git a/tests/roles.rs b/tests/roles.rs index ca58582..8dda704 100644 --- a/tests/roles.rs +++ b/tests/roles.rs @@ -1,5 +1,4 @@ use chorus::types::{self, RoleCreateModifySchema, RoleObject}; -// PRETTYFYME: Move common wasm setup to common.rs #[cfg(target_arch = "wasm32")] use wasm_bindgen_test::*; #[cfg(target_arch = "wasm32")] From 9336c7ac9b47c6b908e61c28c9bb2a5967b86819 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Fri, 24 Nov 2023 21:37:30 +0100 Subject: [PATCH 08/35] Change text passages for better clarity --- README.md | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 89d849f..0106942 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,6 @@ [![Discord]][Discord-invite] [![Build][build-shield]][build-url] [![Coverage][coverage-shield]][coverage-url] -[![Contributors][contributors-shield]][contributors-url]
@@ -16,12 +15,12 @@


- Explore the docs » + Explore the docs »

Report Bug · - Request Feature + crates.io · Join Discord

@@ -29,20 +28,23 @@ -Chorus is a Rust library that allows developers to interact with multiple Spacebar-compatible APIs and Gateways (Including -Discord.com) simultaneously. The library provides a simple and efficient way to communicate with these services, making it easier for developers to build applications that rely on them. Chorus is open-source and welcomes contributions from the community. +Chorus is a Rust library which poses as an API wrapper for [Spacebar Chat](https://github.com/spacebarchat/) +and Discord. It is designed to be easy to use, and to be compatible with both Discord and Spacebar Chat. + +You can establish as many connections to as many servers as you want, and you can use them all at the same time. ## A Tour of Chorus -Chorus combines all the required functionalities of a user-centric Spacebar library into one package. The library -handles a lot of things for you, such as rate limiting, authentication, and more. This means that you can focus on -building your application, instead of worrying about the underlying implementation details. +Chorus combines all the required functionalities of a user-centric Spacebar library into one package. +The library handles various aspects on your behalf, such as rate limiting, authentication and maintaining +a WebSocket connection to the Gateway. This means that you can focus on building your application, +instead of worrying about the underlying implementation details. To get started with Chorus, import it into your project by adding the following to your `Cargo.toml` file: ```toml [dependencies] -chorus = "0" +chorus = "0.12.0" ``` ### Establishing a Connection From c9501e6fadebc91cba5cbca8b597b7136e23e65e Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Fri, 24 Nov 2023 22:21:57 +0100 Subject: [PATCH 09/35] Add README information into lib.rs --- src/lib.rs | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 91 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 47bbaab..e187e44 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,94 @@ -//! A library for interacting with one or multiple Spacebar-compatible APIs and Gateways. -//! -//! # About -//!Chorus is a Rust library that allows developers to interact with multiple Spacebar-compatible APIs and Gateways simultaneously. The library provides a simple and efficient way to communicate with these services, making it easier for developers to build applications that rely on them. Chorus is open-source and welcomes contributions from the community. +/*! +Chorus combines all the required functionalities of a user-centric Spacebar library into one package. +The library handles various aspects on your behalf, such as rate limiting, authentication and maintaining +a WebSocket connection to the Gateway. This means that you can focus on building your application, +instead of worrying about the underlying implementation details. + +### Establishing a Connection + +To connect to a Spacebar compatible server, you need to create an [`Instance`](https://docs.rs/chorus/latest/chorus/instance/struct.Instance.html) like this: + +``` +use chorus::instance::Instance; +use chorus::UrlBundle; + +#[tokio::main] +async fn main() { + let bundle = UrlBundle::new( + "https://example.com/api".to_string(), + "wss://example.com/".to_string(), + "https://example.com/cdn".to_string(), + ); + let instance = Instance::new(bundle, true) + .await + .expect("Failed to connect to the Spacebar server"); + // You can create as many instances of `Instance` as you want, but each `Instance` should likely be unique. + dbg!(instance.instance_info); + dbg!(instance.limits_information); +} +``` + +This Instance can now be used to log in, register and from there on, interact with the server in all sorts of ways. + +### Logging In + +Logging in correctly provides you with an instance of [`ChorusUser`](https://docs.rs/chorus/latest/chorus/instance/struct.ChorusUser.html), with which you can interact with the server and +manipulate the account. Assuming you already have an account on the server, you can log in like this: + +``` +use chorus::types::LoginSchema; +// Assume, you already have an account created on this instance. Registering an account works +// the same way, but you'd use the Register-specific Structs and methods instead. +let login_schema = LoginSchema { + login: "user@example.com".to_string(), + password: "Correct-Horse-Battery-Staple".to_string(), + ..Default::default() +}; +// Each user connects to the Gateway. The Gateway connection lives on a seperate thread. Depending on +// the runtime feature you choose, this can potentially take advantage of all of your computers' threads. +let user = instance + .login_account(login_schema) + .await + .expect("An error occurred during the login process"); +dbg!(user.belongs_to); +dbg!(&user.object.read().unwrap().username); +``` + +## Supported Platforms + +All major desktop operating systems (Windows, macOS (aarch64/x86_64), Linux (aarch64/x86_64)) are supported. +`wasm32-unknown-unknown` is a supported compilation target on versions `0.12.0` and up. This allows you to use +Chorus in your browser, or in any other environment that supports WebAssembly. + +We recommend checking out the examples directory, as well as the documentation for more information. + +## MSRV (Minimum Supported Rust Version) + +Rust **1.67.1**. This number might change at any point while Chorus is not yet at version 1.0.0. + +## Development Setup + +Make sure that you have at least Rust 1.67.1 installed. You can check your Rust version by running `cargo --version` +in your terminal. To compile for `wasm32-unknown-unknown`, you need to install the `wasm32-unknown-unknown` target. +You can do this by running `rustup target add wasm32-unknown-unknown`. + +### Testing + +In general, the tests will require you to run a local instance of the Spacebar server. You can find instructions on how +to do that [here](https://docs.spacebar.chat/setup/server/). You can find a pre-configured version of the server +[here](https://github.com/bitfl0wer/server). It is recommended to use the pre-configured version, as certain things +like "proxy connection checking" are already disabled on this version, which otherwise might break tests. + +### wasm + +To test for wasm, you will need to `cargo install wasm-pack`. You can then run +`wasm-pack test -- --headless -- --target wasm32-unknown-unknown --features="rt, client" --no-default-features` +to run the tests for wasm. + +## Versioning + +This crate uses Semantic Versioning 2.0.0 as its versioning scheme. You can read the specification [here](https://semver.org/spec/v2.0.0.html). +!*/ #![doc( html_logo_url = "https://raw.githubusercontent.com/polyphony-chat/design/main/branding/polyphony-chorus-round-8bit.png" )] From 4786d0c76712ba4e729f082afcb96b47b37ea9c4 Mon Sep 17 00:00:00 2001 From: Flori <39242991+bitfl0wer@users.noreply.github.com> Date: Sat, 25 Nov 2023 13:26:24 +0100 Subject: [PATCH 10/35] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 89d849f..711a1d4 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@
- Logo + The chorus logo. a dark, square background with rounded edges. on this background, there are three vertically stacked, purple lines. The lines each resemble a sine curve.

Chorus

From 28637ef731c82954d87b3873028243c71b2cb848 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sat, 2 Dec 2023 17:35:47 +0100 Subject: [PATCH 11/35] Add Default, Hash, etc. where needed --- src/instance.rs | 42 ++++++++++++++++++- src/lib.rs | 3 +- .../config/types/general_configuration.rs | 2 +- .../subconfigs/limits/ratelimits/auth.rs | 2 +- .../types/subconfigs/limits/ratelimits/mod.rs | 2 +- .../subconfigs/limits/ratelimits/route.rs | 2 +- .../config/types/subconfigs/limits/rates.rs | 2 +- src/types/entities/ratelimits.rs | 2 +- tests/auth.rs | 2 - 9 files changed, 48 insertions(+), 11 deletions(-) diff --git a/src/instance.rs b/src/instance.rs index 4ce4338..8e160b8 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -15,22 +15,60 @@ use crate::types::types::subconfigs::limits::rates::RateLimits; use crate::types::{GeneralConfiguration, Limit, LimitType, User, UserSettings}; use crate::UrlBundle; -#[derive(Debug, Clone, Default)] +#[derive(Debug, Clone, Default, Serialize, Deserialize)] /// The [`Instance`]; what you will be using to perform all sorts of actions on the Spacebar server. /// If `limits_information` is `None`, then the instance will not be rate limited. pub struct Instance { pub urls: UrlBundle, pub instance_info: GeneralConfiguration, pub limits_information: Option, + #[serde(skip)] pub client: Client, } -#[derive(Debug, Clone, Serialize, Deserialize, Default)] +impl PartialEq for Instance { + fn eq(&self, other: &Self) -> bool { + self.urls == other.urls + && self.instance_info == other.instance_info + && self.limits_information == other.limits_information + } +} + +impl Eq for Instance {} + +impl std::hash::Hash for Instance { + fn hash(&self, state: &mut H) { + self.urls.hash(state); + self.instance_info.hash(state); + if let Some(inf) = &self.limits_information { + inf.hash(state); + } + } +} + +#[derive(Debug, Clone, Serialize, Deserialize, Default, Eq)] pub struct LimitsInformation { pub ratelimits: HashMap, pub configuration: RateLimits, } +impl std::hash::Hash for LimitsInformation { + fn hash(&self, state: &mut H) { + for (k, v) in self.ratelimits.iter() { + k.hash(state); + v.hash(state); + } + self.configuration.hash(state); + } +} + +impl PartialEq for LimitsInformation { + fn eq(&self, other: &Self) -> bool { + self.ratelimits.iter().eq(other.ratelimits.iter()) + && self.configuration == other.configuration + } +} + impl Instance { /// Creates a new [`Instance`] from the [relevant instance urls](UrlBundle), where `limited` is whether or not to automatically use rate limits. pub async fn new(urls: UrlBundle, limited: bool) -> ChorusResult { diff --git a/src/lib.rs b/src/lib.rs index e187e44..278a002 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -104,6 +104,7 @@ This crate uses Semantic Versioning 2.0.0 as its versioning scheme. You can read #[cfg(all(feature = "rt", feature = "rt_multi_thread"))] compile_error!("feature \"rt\" and feature \"rt_multi_thread\" cannot be enabled at the same time"); +use serde::{Serialize, Deserialize}; use url::{ParseError, Url}; #[cfg(feature = "client")] @@ -119,7 +120,7 @@ pub mod types; #[cfg(feature = "client")] pub mod voice; -#[derive(Clone, Default, Debug, PartialEq, Eq, Hash)] +#[derive(Clone, Default, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] /// A URLBundle bundles together the API-, Gateway- and CDN-URLs of a Spacebar instance. /// /// # Notes diff --git a/src/types/config/types/general_configuration.rs b/src/types/config/types/general_configuration.rs index 13b3aa8..450fd52 100644 --- a/src/types/config/types/general_configuration.rs +++ b/src/types/config/types/general_configuration.rs @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize}; use crate::types::utils::Snowflake; -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Hash)] #[serde(rename_all = "camelCase")] pub struct GeneralConfiguration { pub instance_name: String, diff --git a/src/types/config/types/subconfigs/limits/ratelimits/auth.rs b/src/types/config/types/subconfigs/limits/ratelimits/auth.rs index f5abb0f..9815a5d 100644 --- a/src/types/config/types/subconfigs/limits/ratelimits/auth.rs +++ b/src/types/config/types/subconfigs/limits/ratelimits/auth.rs @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize}; use crate::types::config::types::subconfigs::limits::ratelimits::RateLimitOptions; -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Hash)] pub struct AuthRateLimit { pub login: RateLimitOptions, pub register: RateLimitOptions, diff --git a/src/types/config/types/subconfigs/limits/ratelimits/mod.rs b/src/types/config/types/subconfigs/limits/ratelimits/mod.rs index 66a2b78..934b922 100644 --- a/src/types/config/types/subconfigs/limits/ratelimits/mod.rs +++ b/src/types/config/types/subconfigs/limits/ratelimits/mod.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; pub mod auth; pub mod route; -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Hash)] #[serde(rename_all = "camelCase")] pub struct RateLimitOptions { pub bot: Option, diff --git a/src/types/config/types/subconfigs/limits/ratelimits/route.rs b/src/types/config/types/subconfigs/limits/ratelimits/route.rs index 5529af3..1aa0be2 100644 --- a/src/types/config/types/subconfigs/limits/ratelimits/route.rs +++ b/src/types/config/types/subconfigs/limits/ratelimits/route.rs @@ -4,7 +4,7 @@ use crate::types::config::types::subconfigs::limits::ratelimits::{ auth::AuthRateLimit, RateLimitOptions, }; -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Hash)] pub struct RouteRateLimit { pub guild: RateLimitOptions, pub webhook: RateLimitOptions, diff --git a/src/types/config/types/subconfigs/limits/rates.rs b/src/types/config/types/subconfigs/limits/rates.rs index 8fdd183..642dcc8 100644 --- a/src/types/config/types/subconfigs/limits/rates.rs +++ b/src/types/config/types/subconfigs/limits/rates.rs @@ -7,7 +7,7 @@ use crate::types::{ LimitType, }; -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Hash)] pub struct RateLimits { pub enabled: bool, pub ip: RateLimitOptions, diff --git a/src/types/entities/ratelimits.rs b/src/types/entities/ratelimits.rs index a95a2c6..f766a12 100644 --- a/src/types/entities/ratelimits.rs +++ b/src/types/entities/ratelimits.rs @@ -25,7 +25,7 @@ pub enum LimitType { /// A struct that represents the current ratelimits, either instance-wide or user-wide. /// See for more information. -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)] pub struct Limit { pub bucket: LimitType, pub limit: u64, diff --git a/tests/auth.rs b/tests/auth.rs index c105841..130bfb6 100644 --- a/tests/auth.rs +++ b/tests/auth.rs @@ -1,5 +1,3 @@ -use std::borrow::BorrowMut; - use chorus::types::{LoginSchema, RegisterSchema}; #[cfg(target_arch = "wasm32")] use wasm_bindgen_test::*; From 2a40f804c1edd2c1702ab296ce6b9ff49b8cfe2a Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sat, 2 Dec 2023 17:36:36 +0100 Subject: [PATCH 12/35] fix import order --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 278a002..c3c5957 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -104,7 +104,7 @@ This crate uses Semantic Versioning 2.0.0 as its versioning scheme. You can read #[cfg(all(feature = "rt", feature = "rt_multi_thread"))] compile_error!("feature \"rt\" and feature \"rt_multi_thread\" cannot be enabled at the same time"); -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use url::{ParseError, Url}; #[cfg(feature = "client")] From 734cbf8d302393c2cd4bdee0a5dcafa641e29083 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sat, 2 Dec 2023 17:44:24 +0100 Subject: [PATCH 13/35] Mark code blocks as no-run --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c3c5957..71e0553 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,7 +8,7 @@ instead of worrying about the underlying implementation details. To connect to a Spacebar compatible server, you need to create an [`Instance`](https://docs.rs/chorus/latest/chorus/instance/struct.Instance.html) like this: -``` +```rs use chorus::instance::Instance; use chorus::UrlBundle; @@ -35,7 +35,7 @@ This Instance can now be used to log in, register and from there on, interact wi Logging in correctly provides you with an instance of [`ChorusUser`](https://docs.rs/chorus/latest/chorus/instance/struct.ChorusUser.html), with which you can interact with the server and manipulate the account. Assuming you already have an account on the server, you can log in like this: -``` +```rs use chorus::types::LoginSchema; // Assume, you already have an account created on this instance. Registering an account works // the same way, but you'd use the Register-specific Structs and methods instead. From 367c0a8ca5f94fe40cca11da85f2205aba74a199 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sat, 2 Dec 2023 20:30:04 +0100 Subject: [PATCH 14/35] impl PartialEq for ChorusUser --- src/instance.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/instance.rs b/src/instance.rs index 8e160b8..fc0bcda 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -131,6 +131,16 @@ pub struct ChorusUser { pub gateway: GatewayHandle, } +impl PartialEq for ChorusUser { + fn eq(&self, other: &Self) -> bool { + self.token == other.token + && self.limits == other.limits + && self.gateway.url == other.gateway.url + } +} + +impl Eq for ChorusUser {} + impl ChorusUser { pub fn token(&self) -> String { self.token.clone() From 4aa45b3841eb3d6856b4a3e9e3e9d214735b1afc Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 3 Dec 2023 12:49:07 +0100 Subject: [PATCH 15/35] impl From reqwest::Error for ChorusError --- src/errors.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/errors.rs b/src/errors.rs index 4099a6b..7494433 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,5 +1,6 @@ //! Contains all the errors that can be returned by the library. use custom_error::custom_error; +use url::Url; use crate::types::WebSocketEvent; @@ -44,6 +45,18 @@ custom_error! { InvalidArguments{error: String} = "Invalid arguments were provided. Error: {error}" } +impl From for ChorusError { + fn from(value: reqwest::Error) -> Self { + ChorusError::RequestFailed { + url: match value.url() { + Some(url) => url.to_string(), + None => "None".to_string(), + }, + error: value.to_string(), + } + } +} + custom_error! { #[derive(PartialEq, Eq)] pub ObserverError From a27a3626f4120ddaf9a2ad654380e61caad95795 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 3 Dec 2023 12:49:22 +0100 Subject: [PATCH 16/35] impl from_root_domain for UrlBundle --- src/lib.rs | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 71e0553..3333bf0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -104,9 +104,12 @@ This crate uses Semantic Versioning 2.0.0 as its versioning scheme. You can read #[cfg(all(feature = "rt", feature = "rt_multi_thread"))] compile_error!("feature \"rt\" and feature \"rt_multi_thread\" cannot be enabled at the same time"); +use errors::ChorusResult; use serde::{Deserialize, Serialize}; use url::{ParseError, Url}; +use crate::errors::ChorusError; + #[cfg(feature = "client")] pub mod api; pub mod errors; @@ -168,7 +171,7 @@ impl UrlBundle { let url_fmt = format!("http://{}", url); return UrlBundle::parse_url(url_fmt); } - Err(_) => panic!("Invalid URL"), + Err(_) => panic!("Invalid URL"), // TODO: should not panic here }; // if the last character of the string is a slash, remove it. let mut url_string = url.to_string(); @@ -177,6 +180,52 @@ impl UrlBundle { } url_string } + + /// Performs a few HTTP requests to try and retrieve a `UrlBundle` from an instances' root domain. + /// The method tries to retrieve the `UrlBundle` via these three strategies, in order: + /// - GET: `$url/.well-known/spacebar` -> Retrieve UrlBundle via `$wellknownurl/api/policies/instance/domains` + /// - GET: `$url/api/policies/instance/domains` + /// - GET: `$url/policies/instance/domains` + /// + /// The URL stored at `.well-known/spacebar` is the instances' API endpoint. The API + /// stores the CDN and WSS URLs under the `$api/policies/instance/domains` endpoint. If all three + /// of the above approaches fail, it is very likely that the instance is misconfigured, unreachable, or that + /// a wrong URL was provided. + pub async fn from_root_domain(url: &str) -> ChorusResult { + let parsed = UrlBundle::parse_url(url.to_string()); + let client = reqwest::Client::new(); + let request_wellknown = client + .get(format!("{}/.well-known/spacebar", &parsed)) + .header(http::header::ACCEPT, "application/json") + .build()?; + let response_wellknown = client.execute(request_wellknown).await?; + if response_wellknown.status().is_success() { + let body = response_wellknown.json::().await?.api; + UrlBundle::from_api_url(&body).await + } else { + if let Ok(response_slash_api) = + UrlBundle::from_api_url(&format!("{}/api/policies/instance/domains", url)).await + { + return Ok(response_slash_api); + } + if let Ok(response_api) = + UrlBundle::from_api_url(&format!("{}/policies/instance/domains", url)).await + { + Ok(response_api) + } else { + Err(ChorusError::RequestFailed { url: url.to_string(), error: "Could not retrieve UrlBundle from url after trying 3 different approaches. Check the provided Url and if the instance is reachable.".to_string() } ) + } + } + } + + async fn from_api_url(url: &str) -> ChorusResult { + todo!() + } +} + +#[derive(Deserialize)] +struct WellKnownResponse { + pub(crate) api: String, } #[cfg(test)] From b6324173b5ce5f181258f9e5d126b0e589a1b954 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 3 Dec 2023 12:51:34 +0100 Subject: [PATCH 17/35] clean up imports --- src/errors.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/errors.rs b/src/errors.rs index 7494433..c20ac64 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,6 +1,5 @@ //! Contains all the errors that can be returned by the library. use custom_error::custom_error; -use url::Url; use crate::types::WebSocketEvent; From 8224acf8975277304978d7a594e1ba23b70a8f7d Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 3 Dec 2023 13:04:02 +0100 Subject: [PATCH 18/35] Create domains_config, create Domains struct --- .../config/types/domains_configuration.rs | 29 +++++++++++++++++++ src/types/config/types/mod.rs | 1 + 2 files changed, 30 insertions(+) create mode 100644 src/types/config/types/domains_configuration.rs diff --git a/src/types/config/types/domains_configuration.rs b/src/types/config/types/domains_configuration.rs new file mode 100644 index 0000000..297b827 --- /dev/null +++ b/src/types/config/types/domains_configuration.rs @@ -0,0 +1,29 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Deserialize, Serialize, Eq, PartialEq, Hash, Clone, Debug)] +/// Represents the result of the `$rooturl/.well-known/spacebar` endpoint. +/// +/// See for more information. +pub struct WellKnownResponse { + pub api: String, +} + +#[derive(Deserialize, Serialize, Eq, PartialEq, Hash, Clone, Debug)] +#[serde(rename_all = "camelCase")] +/// Represents the result of the `$api/policies/instance/domains` endpoint. +pub struct Domains { + pub cdn: String, + pub gateway: String, + pub api_endpoint: String, + pub default_api_version: String, +} + +impl std::fmt::Display for Domains { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{{\n\tCDN URL: {},\n\tGateway URL: {},\n\tAPI Endpoint: {},\n\tDefault API Version: {}\n}}", + self.cdn, self.gateway, self.api_endpoint, self.default_api_version + ) + } +} diff --git a/src/types/config/types/mod.rs b/src/types/config/types/mod.rs index dce4eb0..6ea2c03 100644 --- a/src/types/config/types/mod.rs +++ b/src/types/config/types/mod.rs @@ -1,6 +1,7 @@ pub mod api_configuration; pub mod cdn_configuration; pub mod defaults_configuration; +pub mod domains_configuration; pub mod email_configuration; pub mod endpoint_configuration; pub mod external_tokens_configuration; From 5792c61d09a1f5f04b4302f3a4805e8fc13b48f4 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 3 Dec 2023 13:04:17 +0100 Subject: [PATCH 19/35] move WellKnownResponse to src/types/ --- src/lib.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 3333bf0..8e38026 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -106,6 +106,7 @@ compile_error!("feature \"rt\" and feature \"rt_multi_thread\" cannot be enabled use errors::ChorusResult; use serde::{Deserialize, Serialize}; +use types::types::domains_configuration::WellKnownResponse; use url::{ParseError, Url}; use crate::errors::ChorusError; @@ -223,11 +224,6 @@ impl UrlBundle { } } -#[derive(Deserialize)] -struct WellKnownResponse { - pub(crate) api: String, -} - #[cfg(test)] mod lib { use super::*; From 0e1f52edba2ce8e9905c453587c61092e1f87c3c Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 3 Dec 2023 13:13:57 +0100 Subject: [PATCH 20/35] add warning lint for usage of todo!() --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index 8e38026..d2db694 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -101,6 +101,7 @@ This crate uses Semantic Versioning 2.0.0 as its versioning scheme. You can read clippy::new_without_default, clippy::useless_conversion )] +#![warn(clippy::todo, clippy::unimplemented)] #[cfg(all(feature = "rt", feature = "rt_multi_thread"))] compile_error!("feature \"rt\" and feature \"rt_multi_thread\" cannot be enabled at the same time"); From dc263dbd5ac42c885f7283c27d662346f08275cd Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 3 Dec 2023 13:16:34 +0100 Subject: [PATCH 21/35] impl from_api_url --- src/lib.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index d2db694..093d297 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -215,13 +215,29 @@ impl UrlBundle { { Ok(response_api) } else { - Err(ChorusError::RequestFailed { url: url.to_string(), error: "Could not retrieve UrlBundle from url after trying 3 different approaches. Check the provided Url and if the instance is reachable.".to_string() } ) + Err(ChorusError::RequestFailed { url: url.to_string(), error: "Could not retrieve UrlBundle from url after trying 3 different approaches. Check the provided Url and make sure the instance is reachable.".to_string() } ) } } } async fn from_api_url(url: &str) -> ChorusResult { - todo!() + let client = reqwest::Client::new(); + let request = client + .get(url) + .header(http::header::ACCEPT, "application/json") + .build()?; + let response = client.execute(request).await?; + if let Ok(body) = response + .json::() + .await + { + Ok(UrlBundle::new(body.api_endpoint, body.gateway, body.cdn)) + } else { + Err(ChorusError::RequestFailed { + url: url.to_string(), + error: "Could not retrieve a UrlBundle from the given url. Check the provided url and make sure the instance is reachable.".to_string(), + }) + } } } From d28ccf209af4260d41caa2b83ec9200751ad0283 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 3 Dec 2023 13:28:50 +0100 Subject: [PATCH 22/35] check for dbg! println! eprintln! in production code --- src/lib.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 093d297..47fda75 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -101,7 +101,13 @@ This crate uses Semantic Versioning 2.0.0 as its versioning scheme. You can read clippy::new_without_default, clippy::useless_conversion )] -#![warn(clippy::todo, clippy::unimplemented)] +#![warn( + clippy::todo, + clippy::unimplemented, + clippy::dbg_macro, + clippy::print_stdout, + clippy::print_stderr +)] #[cfg(all(feature = "rt", feature = "rt_multi_thread"))] compile_error!("feature \"rt\" and feature \"rt_multi_thread\" cannot be enabled at the same time"); @@ -206,16 +212,16 @@ impl UrlBundle { UrlBundle::from_api_url(&body).await } else { if let Ok(response_slash_api) = - UrlBundle::from_api_url(&format!("{}/api/policies/instance/domains", url)).await + UrlBundle::from_api_url(&format!("{}/api/policies/instance/domains", parsed)).await { return Ok(response_slash_api); } if let Ok(response_api) = - UrlBundle::from_api_url(&format!("{}/policies/instance/domains", url)).await + UrlBundle::from_api_url(&format!("{}/policies/instance/domains", parsed)).await { Ok(response_api) } else { - Err(ChorusError::RequestFailed { url: url.to_string(), error: "Could not retrieve UrlBundle from url after trying 3 different approaches. Check the provided Url and make sure the instance is reachable.".to_string() } ) + Err(ChorusError::RequestFailed { url: parsed.to_string(), error: "Could not retrieve UrlBundle from url after trying 3 different approaches. Check the provided Url and make sure the instance is reachable.".to_string() } ) } } } From bae3bc3aeff09ea554a49d778df881953ece7a54 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 3 Dec 2023 13:29:38 +0100 Subject: [PATCH 23/35] Write test to check basic functionality of UrlBundle::from_root_domain() --- tests/urlbundle.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 tests/urlbundle.rs diff --git a/tests/urlbundle.rs b/tests/urlbundle.rs new file mode 100644 index 0000000..296e86b --- /dev/null +++ b/tests/urlbundle.rs @@ -0,0 +1,12 @@ +use chorus::UrlBundle; +#[cfg(target_arch = "wasm32")] +use wasm_bindgen_test::*; +#[cfg(target_arch = "wasm32")] +wasm_bindgen_test_configure!(run_in_browser); + +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[cfg_attr(not(target_arch = "wasm32"), tokio::test)] +async fn test_parse_url() { + let url = url::Url::parse("http://localhost:3001/").unwrap(); + UrlBundle::from_root_domain(url.as_str()).await.unwrap(); +} From 906f2234f76cf54e3012d85b33b6348c663cdaeb Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 3 Dec 2023 13:33:24 +0100 Subject: [PATCH 24/35] Add test if an example well-known response gets parsed correctly. --- tests/urlbundle.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/urlbundle.rs b/tests/urlbundle.rs index 296e86b..94dcc6d 100644 --- a/tests/urlbundle.rs +++ b/tests/urlbundle.rs @@ -1,4 +1,6 @@ +use chorus::types::types::domains_configuration::WellKnownResponse; use chorus::UrlBundle; +use serde_json::json; #[cfg(target_arch = "wasm32")] use wasm_bindgen_test::*; #[cfg(target_arch = "wasm32")] @@ -7,6 +9,18 @@ wasm_bindgen_test_configure!(run_in_browser); #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] #[cfg_attr(not(target_arch = "wasm32"), tokio::test)] async fn test_parse_url() { + // TODO: Currently only tests two of the three branches in UrlBundle::from_root_domain. let url = url::Url::parse("http://localhost:3001/").unwrap(); UrlBundle::from_root_domain(url.as_str()).await.unwrap(); + let url = url::Url::parse("http://localhost:3001/api/").unwrap(); + UrlBundle::from_root_domain(url.as_str()).await.unwrap(); +} + +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[cfg_attr(not(target_arch = "wasm32"), tokio::test)] +async fn test_parse_wellknown() { + let json = json!({ + "api": "http://localhost:3001/api/v9" + }); + let _well_known: WellKnownResponse = serde_json::from_value(json).unwrap(); } From 7c5d7f731c5fdfb6ea1b47ee3cb5e8720aee4c9e Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 3 Dec 2023 13:37:32 +0100 Subject: [PATCH 25/35] Add Instance::from_root_domain(), change documentation wording --- src/instance.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/instance.rs b/src/instance.rs index fc0bcda..6a3b9af 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -70,7 +70,7 @@ impl PartialEq for LimitsInformation { } impl Instance { - /// Creates a new [`Instance`] from the [relevant instance urls](UrlBundle), where `limited` is whether or not to automatically use rate limits. + /// Creates a new [`Instance`] from the [relevant instance urls](UrlBundle), where `limited` is whether Chorus will track and enforce rate limits for this instance. pub async fn new(urls: UrlBundle, limited: bool) -> ChorusResult { let limits_information; if limited { @@ -99,12 +99,22 @@ impl Instance { }; Ok(instance) } + pub(crate) fn clone_limits_if_some(&self) -> Option> { if self.limits_information.is_some() { return Some(self.limits_information.as_ref().unwrap().ratelimits.clone()); } None } + + /// Creates a new [`Instance`] by trying to get the [relevant instance urls](UrlBundle) from a root domain. + /// Shorthand for `Instance::new(UrlBundle::from_root_domain(root_domain).await?)`. + /// + /// If `limited` is `true`, then Chorus will track and enforce rate limits for this instance. + pub async fn from_root_domain(root_domain: &str, limited: bool) -> ChorusResult { + let urls = UrlBundle::from_root_domain(root_domain).await?; + Instance::new(urls, limited).await + } } #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] From 4ad1201032457aad308a1cff897ba1cb072ec176 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 3 Dec 2023 13:39:23 +0100 Subject: [PATCH 26/35] Rename from_root_domain to from_root_url --- src/instance.rs | 6 +++--- src/lib.rs | 4 ++-- tests/urlbundle.rs | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/instance.rs b/src/instance.rs index 6a3b9af..90ee1fa 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -107,12 +107,12 @@ impl Instance { None } - /// Creates a new [`Instance`] by trying to get the [relevant instance urls](UrlBundle) from a root domain. + /// Creates a new [`Instance`] by trying to get the [relevant instance urls](UrlBundle) from a root url. /// Shorthand for `Instance::new(UrlBundle::from_root_domain(root_domain).await?)`. /// /// If `limited` is `true`, then Chorus will track and enforce rate limits for this instance. - pub async fn from_root_domain(root_domain: &str, limited: bool) -> ChorusResult { - let urls = UrlBundle::from_root_domain(root_domain).await?; + pub async fn from_root_url(root_url: &str, limited: bool) -> ChorusResult { + let urls = UrlBundle::from_root_url(root_url).await?; Instance::new(urls, limited).await } } diff --git a/src/lib.rs b/src/lib.rs index 47fda75..80374fb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -189,7 +189,7 @@ impl UrlBundle { url_string } - /// Performs a few HTTP requests to try and retrieve a `UrlBundle` from an instances' root domain. + /// Performs a few HTTP requests to try and retrieve a `UrlBundle` from an instances' root url. /// The method tries to retrieve the `UrlBundle` via these three strategies, in order: /// - GET: `$url/.well-known/spacebar` -> Retrieve UrlBundle via `$wellknownurl/api/policies/instance/domains` /// - GET: `$url/api/policies/instance/domains` @@ -199,7 +199,7 @@ impl UrlBundle { /// stores the CDN and WSS URLs under the `$api/policies/instance/domains` endpoint. If all three /// of the above approaches fail, it is very likely that the instance is misconfigured, unreachable, or that /// a wrong URL was provided. - pub async fn from_root_domain(url: &str) -> ChorusResult { + pub async fn from_root_url(url: &str) -> ChorusResult { let parsed = UrlBundle::parse_url(url.to_string()); let client = reqwest::Client::new(); let request_wellknown = client diff --git a/tests/urlbundle.rs b/tests/urlbundle.rs index 94dcc6d..790229b 100644 --- a/tests/urlbundle.rs +++ b/tests/urlbundle.rs @@ -11,9 +11,9 @@ wasm_bindgen_test_configure!(run_in_browser); async fn test_parse_url() { // TODO: Currently only tests two of the three branches in UrlBundle::from_root_domain. let url = url::Url::parse("http://localhost:3001/").unwrap(); - UrlBundle::from_root_domain(url.as_str()).await.unwrap(); + UrlBundle::from_root_url(url.as_str()).await.unwrap(); let url = url::Url::parse("http://localhost:3001/api/").unwrap(); - UrlBundle::from_root_domain(url.as_str()).await.unwrap(); + UrlBundle::from_root_url(url.as_str()).await.unwrap(); } #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] From df7ee4d2fc1d8fa1381e849154e82f0e85c3270d Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 3 Dec 2023 14:18:14 +0100 Subject: [PATCH 27/35] Change macOS Safari test strategy to no-fail-fast --- .github/workflows/build_and_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index a6abe43..6751f05 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -72,7 +72,7 @@ jobs: rustup target add wasm32-unknown-unknown curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash cargo binstall --no-confirm wasm-bindgen-cli --version "0.2.88" --force - SAFARIDRIVER=$(which safaridriver) cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" + SAFARIDRIVER=$(which safaridriver) cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" --no-fail-fast wasm-gecko: runs-on: macos-latest steps: From 0c92ffb64d8022175f44e119f440797a0322a3ff Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 3 Dec 2023 15:06:09 +0100 Subject: [PATCH 28/35] Try giving macos-safari its own cache key to fix CI --- .github/workflows/build_and_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 6751f05..bb28584 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -66,7 +66,7 @@ jobs: - uses: Swatinem/rust-cache@v2 with: cache-all-crates: "true" - prefix-key: "macos" + prefix-key: "macos-safari" - name: Run WASM tests with Safari, Firefox, Chrome run: | rustup target add wasm32-unknown-unknown From 0553ecb753f2b3d95d330110c4205175610ecbe8 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 3 Dec 2023 15:57:03 +0100 Subject: [PATCH 29/35] wasm-safari CI seems to be bugged - disabling for now --- .github/workflows/build_and_test.yml | 56 ++++++++++++++-------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index bb28584..0cf6fd9 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -45,34 +45,34 @@ jobs: cargo build --verbose --all-features cargo test --verbose --all-features fi - wasm-safari: - runs-on: macos-latest - steps: - - uses: actions/checkout@v4 - - name: Clone spacebar server - run: | - git clone https://github.com/bitfl0wer/server.git - - uses: actions/setup-node@v3 - with: - node-version: 18 - cache: 'npm' - cache-dependency-path: server/package-lock.json - - name: Prepare and start Spacebar server - run: | - npm install - npm run setup - npm run start & - working-directory: ./server - - uses: Swatinem/rust-cache@v2 - with: - cache-all-crates: "true" - prefix-key: "macos-safari" - - name: Run WASM tests with Safari, Firefox, Chrome - run: | - rustup target add wasm32-unknown-unknown - curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash - cargo binstall --no-confirm wasm-bindgen-cli --version "0.2.88" --force - SAFARIDRIVER=$(which safaridriver) cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" --no-fail-fast + # wasm-safari: + # runs-on: macos-latest + # steps: + # - uses: actions/checkout@v4 + # - name: Clone spacebar server + # run: | + # git clone https://github.com/bitfl0wer/server.git + # - uses: actions/setup-node@v3 + # with: + # node-version: 18 + # cache: 'npm' + # cache-dependency-path: server/package-lock.json + # - name: Prepare and start Spacebar server + # run: | + # npm install + # npm run setup + # npm run start & + # working-directory: ./server + # - uses: Swatinem/rust-cache@v2 + # with: + # cache-all-crates: "true" + # prefix-key: "macos-safari" + # - name: Run WASM tests with Safari, Firefox, Chrome + # run: | + # rustup target add wasm32-unknown-unknown + # curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash + # cargo binstall --no-confirm wasm-bindgen-cli --version "0.2.88" --force + # SAFARIDRIVER=$(which safaridriver) cargo test --target wasm32-unknown-unknown --no-default-features --features="client, rt" --no-fail-fast wasm-gecko: runs-on: macos-latest steps: From 37125e7973b29dbbe92523860d79c8e0f0606e07 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 3 Dec 2023 21:34:44 +0100 Subject: [PATCH 30/35] Remove "limited" parameter --- examples/instance.rs | 2 +- examples/login.rs | 2 +- tests/common/mod.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/instance.rs b/examples/instance.rs index d2a042f..b8f8518 100644 --- a/examples/instance.rs +++ b/examples/instance.rs @@ -8,7 +8,7 @@ async fn main() { "wss://example.com/".to_string(), "https://example.com/cdn".to_string(), ); - let instance = Instance::new(bundle, true) + let instance = Instance::new(bundle) .await .expect("Failed to connect to the Spacebar server"); dbg!(instance.instance_info); diff --git a/examples/login.rs b/examples/login.rs index 6b56a47..18b5db4 100644 --- a/examples/login.rs +++ b/examples/login.rs @@ -9,7 +9,7 @@ async fn main() { "wss://example.com/".to_string(), "https://example.com/cdn".to_string(), ); - let mut instance = Instance::new(bundle, true) + let mut instance = Instance::new(bundle) .await .expect("Failed to connect to the Spacebar server"); // Assume, you already have an account created on this instance. Registering an account works diff --git a/tests/common/mod.rs b/tests/common/mod.rs index b533fd2..d6aaa34 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -57,7 +57,7 @@ pub(crate) async fn setup() -> TestBundle { "ws://localhost:3001".to_string(), "http://localhost:3001".to_string(), ); - let instance = Instance::new(urls.clone(), true).await.unwrap(); + let instance = Instance::new(urls.clone()).await.unwrap(); // Requires the existance of the below user. let reg = RegisterSchema { username: "integrationtestuser".into(), From dc1991a9cccdc255a5d686cbfd7d2d9b3df0de7a Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 3 Dec 2023 21:42:41 +0100 Subject: [PATCH 31/35] Make get_limits_config part of public api --- src/ratelimiter.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ratelimiter.rs b/src/ratelimiter.rs index 88d4a02..f6a7c26 100644 --- a/src/ratelimiter.rs +++ b/src/ratelimiter.rs @@ -349,7 +349,7 @@ impl ChorusRequest { /// /// # Reference /// See - pub(crate) async fn get_limits_config(url_api: &str) -> ChorusResult { + pub async fn get_limits_config(url_api: &str) -> ChorusResult { let request = Client::new() .get(format!("{}/policies/instance/limits/", url_api)) .send() From 565670c5b76f1d38d27fe3a9068c4a13ffc42939 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 3 Dec 2023 21:44:08 +0100 Subject: [PATCH 32/35] Remove limited argument from Instance --- src/instance.rs | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/src/instance.rs b/src/instance.rs index 90ee1fa..cd9eb76 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -12,7 +12,9 @@ use crate::errors::ChorusResult; use crate::gateway::{Gateway, GatewayHandle}; use crate::ratelimiter::ChorusRequest; use crate::types::types::subconfigs::limits::rates::RateLimits; -use crate::types::{GeneralConfiguration, Limit, LimitType, User, UserSettings}; +use crate::types::{ + GeneralConfiguration, Limit, LimitType, LimitsConfiguration, User, UserSettings, +}; use crate::UrlBundle; #[derive(Debug, Clone, Default, Serialize, Deserialize)] @@ -71,23 +73,24 @@ impl PartialEq for LimitsInformation { impl Instance { /// Creates a new [`Instance`] from the [relevant instance urls](UrlBundle), where `limited` is whether Chorus will track and enforce rate limits for this instance. - pub async fn new(urls: UrlBundle, limited: bool) -> ChorusResult { - let limits_information; - if limited { - let limits_configuration = ChorusRequest::get_limits_config(&urls.api).await?.rate; - let limits = ChorusRequest::limits_config_to_hashmap(&limits_configuration); - limits_information = Some(LimitsInformation { + pub async fn new(urls: UrlBundle) -> ChorusResult { + let is_limited: Option = Instance::is_limited(&urls.api).await?; + let limit_information; + + if let Some(limits_configuration) = is_limited { + let limits = ChorusRequest::limits_config_to_hashmap(&limits_configuration.rate); + limit_information = Some(LimitsInformation { ratelimits: limits, - configuration: limits_configuration, + configuration: limits_configuration.rate, }); } else { - limits_information = None; + limit_information = None } let mut instance = Instance { urls: urls.clone(), // Will be overwritten in the next step instance_info: GeneralConfiguration::default(), - limits_information, + limits_information: limit_information, client: Client::new(), }; instance.instance_info = match instance.general_configuration_schema().await { @@ -111,9 +114,26 @@ impl Instance { /// Shorthand for `Instance::new(UrlBundle::from_root_domain(root_domain).await?)`. /// /// If `limited` is `true`, then Chorus will track and enforce rate limits for this instance. - pub async fn from_root_url(root_url: &str, limited: bool) -> ChorusResult { + pub async fn from_root_url(root_url: &str) -> ChorusResult { let urls = UrlBundle::from_root_url(root_url).await?; - Instance::new(urls, limited).await + Instance::new(urls).await + } + + pub async fn is_limited(api_url: &str) -> ChorusResult> { + let api_url = UrlBundle::parse_url(api_url.to_string()); + let client = Client::new(); + let request = client + .get(format!("{}/policies/instance/limits", &api_url)) + .header(http::header::ACCEPT, "application/json") + .build()?; + let resp = match client.execute(request).await { + Ok(response) => response, + Err(_) => return Ok(None), + }; + match resp.json::().await { + Ok(limits) => Ok(Some(limits)), + Err(_) => Ok(None), + } } } From bbdcd35b606b3ef4a1f48111a0effeea3b3290c2 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 3 Dec 2023 22:35:45 +0100 Subject: [PATCH 33/35] Bump version --- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2c7b5d2..6b238a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -189,7 +189,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chorus" -version = "0.12.0" +version = "0.13.0" dependencies = [ "async-trait", "base64 0.21.5", diff --git a/Cargo.toml b/Cargo.toml index 1d76722..fd7dffe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "chorus" description = "A library for interacting with multiple Spacebar-compatible Instances at once." -version = "0.12.0" +version = "0.13.0" license = "AGPL-3.0" edition = "2021" repository = "https://github.com/polyphony-chat/chorus" diff --git a/README.md b/README.md index 0106942..73ab449 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ To get started with Chorus, import it into your project by adding the following ```toml [dependencies] -chorus = "0.12.0" +chorus = "0.13.0" ``` ### Establishing a Connection From 6b0fd238c892000c9d0bf0f3177822565f80d0c1 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 10 Dec 2023 18:37:38 +0100 Subject: [PATCH 34/35] Update cargo lock --- Cargo.lock | 417 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 260 insertions(+), 157 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6b238a5..036dc73 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -91,6 +91,16 @@ dependencies = [ "num-traits", ] +[[package]] +name = "atomic-write-file" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edcdbedc2236483ab103a53415653d6b4442ea6141baf1ffa85df29635e88436" +dependencies = [ + "nix", + "rand", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -174,9 +184,9 @@ checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" [[package]] name = "cc" -version = "1.0.84" +version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f8e7c90afad890484a21653d08b6e209ae34770fb5ee298f9c699fcc1e5c856" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" dependencies = [ "libc", ] @@ -251,7 +261,7 @@ dependencies = [ "num-traits", "serde", "wasm-bindgen", - "windows-targets", + "windows-targets 0.48.5", ] [[package]] @@ -272,9 +282,9 @@ checksum = "28c122c3980598d243d63d9a704629a2d748d101f278052ff068be5a4423ab6f" [[package]] name = "core-foundation" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" dependencies = [ "core-foundation-sys", "libc", @@ -282,9 +292,9 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.8.4" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" [[package]] name = "cpufeatures" @@ -382,9 +392,9 @@ dependencies = [ [[package]] name = "data-encoding" -version = "2.4.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308" +checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5" [[package]] name = "der" @@ -399,9 +409,9 @@ dependencies = [ [[package]] name = "deranged" -version = "0.3.9" +version = "0.3.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f32d04922c60427da6f9fef14d042d9edddef64cb9d4ce0d64d0685fbeb1fd3" +checksum = "8eb30d70a07a3b04884d2677f06bec33509dc67ca60d92949e5535352d3191dc" dependencies = [ "powerfmt", "serde", @@ -451,12 +461,12 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.6" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c18ee0ed65a5f1f81cac6b1d213b69c35fa47d4252ad41f1486dbd8226fe36e" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -467,7 +477,7 @@ checksum = "136d1b5283a1ab77bd9257427ffd09d8667ced0570b6f938942bc7568ed5b943" dependencies = [ "cfg-if", "home", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -522,9 +532,9 @@ checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" [[package]] name = "form_urlencoded" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" dependencies = [ "percent-encoding", ] @@ -654,15 +664,15 @@ dependencies = [ [[package]] name = "gimli" -version = "0.28.0" +version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] name = "h2" -version = "0.3.21" +version = "0.3.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91fc23aa11be92976ef4729127f1a74adf36d8436f7816b185d18df956790833" +checksum = "4d6250322ef6e60f93f9a2162799302cd6f68f79f6e5d85c8c16f14d1d958178" dependencies = [ "bytes", "fnv", @@ -670,7 +680,7 @@ dependencies = [ "futures-sink", "futures-util", "http", - "indexmap 1.9.3", + "indexmap 2.1.0", "slab", "tokio", "tokio-util", @@ -685,9 +695,9 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "hashbrown" -version = "0.14.2" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" dependencies = [ "ahash", "allocator-api2", @@ -699,7 +709,7 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8094feaf31ff591f651a2664fb9cfd92bba7a60ce3197265e9482ebe753c8f7" dependencies = [ - "hashbrown 0.14.2", + "hashbrown 0.14.3", ] [[package]] @@ -771,7 +781,7 @@ version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb" dependencies = [ - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -798,9 +808,9 @@ dependencies = [ [[package]] name = "http-body" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" +checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" dependencies = [ "bytes", "http", @@ -887,9 +897,9 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "idna" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ "unicode-bidi", "unicode-normalization", @@ -913,7 +923,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" dependencies = [ "equivalent", - "hashbrown 0.14.2", + "hashbrown 0.14.3", "serde", ] @@ -934,24 +944,24 @@ dependencies = [ [[package]] name = "itertools" -version = "0.11.0" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" +checksum = "25db6b064527c5d482d0423354fcd07a89a2dfe07b67892e62411946db7f07b0" dependencies = [ "either", ] [[package]] name = "itoa" -version = "1.0.9" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" +checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] name = "js-sys" -version = "0.3.65" +version = "0.3.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54c0c35952f67de54bb584e9fd912b3023117cbafc0a77d8f3dee1fb5f572fe8" +checksum = "cee9c64da59eae3b50095c18d3e74f8b73c0b86d2792824ff01bbce68ba229ca" dependencies = [ "wasm-bindgen", ] @@ -981,9 +991,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.150" +version = "0.2.151" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" +checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" [[package]] name = "libm" @@ -993,9 +1003,9 @@ checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" [[package]] name = "libsqlite3-sys" -version = "0.26.0" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afc22eff61b133b115c6e8c74e818c628d6d5e7a502afea6f64dee076dd94326" +checksum = "cf4e226dcd58b4be396f7bd3c20da8fdee2911400705297ba7d2d7cc2c30f716" dependencies = [ "cc", "pkg-config", @@ -1004,9 +1014,9 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "969488b55f8ac402214f3f5fd243ebb7206cf82de60d3172994707a4bcc2b829" +checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456" [[package]] name = "lock_api" @@ -1079,13 +1089,13 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.9" +version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dce281c5e46beae905d4de1870d8b1509a9142b62eedf18b443b011ca8343d0" +checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" dependencies = [ "libc", "wasi", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1106,6 +1116,17 @@ dependencies = [ "tempfile", ] +[[package]] +name = "nix" +version = "0.27.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2eb04e9c688eff1c89d72b407f168cf79bb9e867a9d3323ed6c01519eb9cc053" +dependencies = [ + "bitflags 2.4.1", + "cfg-if", + "libc", +] + [[package]] name = "nom" version = "7.1.3" @@ -1196,15 +1217,15 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.18.0" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "openssl" -version = "0.10.59" +version = "0.10.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a257ad03cd8fb16ad4172fedf8094451e1af1c4b70097636ef2eac9a5f0cc33" +checksum = "6b8419dc8cc6d866deb801274bba2e6f8f6108c1bb7fcc10ee5ab864931dbb45" dependencies = [ "bitflags 2.4.1", "cfg-if", @@ -1234,9 +1255,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.95" +version = "0.9.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40a4130519a360279579c2053038317e40eff64d13fd3f004f9e1b72b8a6aaf9" +checksum = "c3eaad34cdd97d81de97964fc7f29e2d104f483840d906ef56daa1912338460b" dependencies = [ "cc", "libc", @@ -1264,7 +1285,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-targets", + "windows-targets 0.48.5", ] [[package]] @@ -1293,9 +1314,9 @@ dependencies = [ [[package]] name = "percent-encoding" -version = "2.3.0" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pharos" @@ -1348,9 +1369,9 @@ checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" [[package]] name = "poem" -version = "1.3.58" +version = "1.3.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebc7ae19f3e791ae8108b08801abb3708d64d3a16490c720e0b81040cae87b5d" +checksum = "504774c97b0744c1ee108a37e5a65a9745a4725c4c06277521dabc28eb53a904" dependencies = [ "async-trait", "bytes", @@ -1359,6 +1380,7 @@ dependencies = [ "http", "hyper", "mime", + "nix", "parking_lot", "percent-encoding", "pin-project-lite", @@ -1373,13 +1395,14 @@ dependencies = [ "tokio", "tokio-util", "tracing", + "wildmatch", ] [[package]] name = "poem-derive" -version = "1.3.58" +version = "1.3.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2550a0bce7273b278894ef3ccc5a6869e7031b6870042f3cc6826ed9faa980a6" +checksum = "42ddcf4680d8d867e1e375116203846acb088483fa2070244f90589f458bbb31" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -1401,19 +1424,19 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro-crate" -version = "1.3.1" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" +checksum = "97dc5fea232fc28d2f597b37c4876b348a40e33f3b02cc975c8d006d78d94b1a" dependencies = [ - "once_cell", + "toml_datetime", "toml_edit", ] [[package]] name = "proc-macro2" -version = "1.0.69" +version = "1.0.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" +checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" dependencies = [ "unicode-ident", ] @@ -1498,7 +1521,7 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "reqwest" version = "0.11.22" -source = "git+https://github.com/bitfl0wer/reqwest.git?branch=wasm-headers#4ab344a7a074ee2cebc3b0c1a9bee6f0337b8f1c" +source = "git+https://github.com/bitfl0wer/reqwest.git?branch=wasm-headers#858197c528f074f00397f7e2675d3eb15cc10a75" dependencies = [ "base64 0.21.5", "bytes", @@ -1559,23 +1582,23 @@ dependencies = [ [[package]] name = "ring" -version = "0.17.5" +version = "0.17.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb0205304757e5d899b9c2e448b867ffd03ae7f988002e47cd24954391394d0b" +checksum = "688c63d65483050968b2a8937f7995f443e27041a0f7700aa59b0822aedebb74" dependencies = [ "cc", "getrandom", "libc", "spin 0.9.8", "untrusted 0.9.0", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] name = "rsa" -version = "0.9.3" +version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86ef35bf3e7fe15a53c4ab08a998e42271eab13eb0db224126bc7bc4c4bad96d" +checksum = "5d0e5124fcb30e76a7e79bfee683a2746db83784b86289f6251b54b7950a0dfc" dependencies = [ "const-oid", "digest", @@ -1608,25 +1631,25 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.23" +version = "0.38.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffb93593068e9babdad10e4fce47dc9b3ac25315a72a59766ffd9e9a71996a04" +checksum = "72e572a5e8ca657d7366229cdde4bd14c4eb5499a9573d4d366fe1b599daa316" dependencies = [ "bitflags 2.4.1", "errno", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] name = "rustls" -version = "0.21.8" +version = "0.21.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "446e14c5cda4f3f30fe71863c34ec70f5ac79d6087097ad0bb433e1be5edf04c" +checksum = "f9d5a6813c0759e4609cd494e8e725babae6a2ca7b62a5536a13daaec6fcb7ba" dependencies = [ "log", - "ring 0.17.5", + "ring 0.17.7", "rustls-webpki", "sct", ] @@ -1658,15 +1681,15 @@ version = "0.101.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" dependencies = [ - "ring 0.17.5", + "ring 0.17.7", "untrusted 0.9.0", ] [[package]] name = "ryu" -version = "1.0.15" +version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" +checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" [[package]] name = "safina-timer" @@ -1683,7 +1706,7 @@ version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88" dependencies = [ - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1704,7 +1727,7 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" dependencies = [ - "ring 0.17.5", + "ring 0.17.7", "untrusted 0.9.0", ] @@ -1745,18 +1768,18 @@ checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" [[package]] name = "serde" -version = "1.0.192" +version = "1.0.193" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bca2a08484b285dcb282d0f67b26cadc0df8b19f8c12502c13d966bf9482f001" +checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" dependencies = [ "serde_derive", ] [[package]] name = "serde-aux" -version = "4.2.0" +version = "4.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3dfe1b7eb6f9dcf011bd6fad169cdeaae75eda0d61b1a99a3f015b41b0cae39" +checksum = "184eba62ebddb71658697c8b08822edee89970bf318c5362189f0de27f85b498" dependencies = [ "chrono", "serde", @@ -1765,9 +1788,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.192" +version = "1.0.193" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1" +checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" dependencies = [ "proc-macro2", "quote", @@ -1913,7 +1936,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1933,9 +1956,9 @@ dependencies = [ [[package]] name = "spki" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d1e996ef02c474957d681f1b05213dfb0abab947b446a62d37770b23500184a" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" dependencies = [ "base64ct", "der", @@ -1943,9 +1966,9 @@ dependencies = [ [[package]] name = "sqlformat" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b7b278788e7be4d0d29c0f39497a0eef3fba6bbc8e70d8bf7fde46edeaa9e85" +checksum = "ce81b7bd7c4493975347ef60d8c7e8b742d4694f4c49f93e0a12ea263938176c" dependencies = [ "itertools", "nom", @@ -1954,9 +1977,9 @@ dependencies = [ [[package]] name = "sqlx" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e50c216e3624ec8e7ecd14c6a6a6370aad6ee5d8cfc3ab30b5162eeeef2ed33" +checksum = "dba03c279da73694ef99763320dea58b51095dfe87d001b1d4b5fe78ba8763cf" dependencies = [ "sqlx-core", "sqlx-macros", @@ -1967,9 +1990,9 @@ dependencies = [ [[package]] name = "sqlx-core" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d6753e460c998bbd4cd8c6f0ed9a64346fcca0723d6e75e52fdc351c5d2169d" +checksum = "d84b0a3c3739e220d94b3239fd69fb1f74bc36e16643423bd99de3b43c21bfbd" dependencies = [ "ahash", "atoi", @@ -2010,9 +2033,9 @@ dependencies = [ [[package]] name = "sqlx-macros" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a793bb3ba331ec8359c1853bd39eed32cdd7baaf22c35ccf5c92a7e8d1189ec" +checksum = "89961c00dc4d7dffb7aee214964b065072bff69e36ddb9e2c107541f75e4f2a5" dependencies = [ "proc-macro2", "quote", @@ -2023,10 +2046,11 @@ dependencies = [ [[package]] name = "sqlx-macros-core" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a4ee1e104e00dedb6aa5ffdd1343107b0a4702e862a84320ee7cc74782d96fc" +checksum = "d0bd4519486723648186a08785143599760f7cc81c52334a55d6a83ea1e20841" dependencies = [ + "atomic-write-file", "dotenvy", "either", "heck", @@ -2049,9 +2073,9 @@ dependencies = [ [[package]] name = "sqlx-mysql" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "864b869fdf56263f4c95c45483191ea0af340f9f3e3e7b4d57a61c7c87a970db" +checksum = "e37195395df71fd068f6e2082247891bc11e3289624bbc776a0cdfa1ca7f1ea4" dependencies = [ "atoi", "base64 0.21.5", @@ -2092,9 +2116,9 @@ dependencies = [ [[package]] name = "sqlx-postgres" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb7ae0e6a97fb3ba33b23ac2671a5ce6e3cabe003f451abd5a56e7951d975624" +checksum = "d6ac0ac3b7ccd10cc96c7ab29791a7dd236bd94021f31eec7ba3d46a74aa1c24" dependencies = [ "atoi", "base64 0.21.5", @@ -2133,9 +2157,9 @@ dependencies = [ [[package]] name = "sqlx-sqlite" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d59dc83cf45d89c555a577694534fcd1b55c545a816c816ce51f20bbe56a4f3f" +checksum = "210976b7d948c7ba9fced8ca835b11cbb2d677c59c79de41ac0d397e14547490" dependencies = [ "atoi", "chrono", @@ -2152,6 +2176,7 @@ dependencies = [ "sqlx-core", "tracing", "url", + "urlencoding", ] [[package]] @@ -2230,7 +2255,7 @@ dependencies = [ "fastrand", "redox_syscall", "rustix", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -2299,9 +2324,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.34.0" +version = "1.35.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0c014766411e834f7af5b8f4cf46257aab4036ca95e9d2c144a10f59ad6f5b9" +checksum = "841d45b238a16291a4e1584e61820b8ae57d696cc5015c459c229ccc6990cc1c" dependencies = [ "backtrace", "bytes", @@ -2311,7 +2336,7 @@ dependencies = [ "pin-project-lite", "socket2 0.5.5", "tokio-macros", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -2387,15 +2412,15 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.6.5" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" +checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" [[package]] name = "toml_edit" -version = "0.19.15" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" +checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338" dependencies = [ "indexmap 2.1.0", "toml_datetime", @@ -2442,9 +2467,9 @@ dependencies = [ [[package]] name = "try-lock" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] name = "tungstenite" @@ -2492,9 +2517,9 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.13" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" +checksum = "6f2528f27a9eb2b21e69c95319b30bd0efd85d09c379741b0f78ea1d86be2416" [[package]] name = "unicode-ident" @@ -2537,15 +2562,21 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] name = "url" -version = "2.4.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" dependencies = [ "form_urlencoded", "idna", "percent-encoding", ] +[[package]] +name = "urlencoding" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" + [[package]] name = "utf-8" version = "0.7.6" @@ -2581,9 +2612,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.88" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7daec296f25a1bae309c0cd5c29c4b260e510e6d813c286b19eaadf409d40fce" +checksum = "0ed0d4f68a3015cc185aff4db9506a015f4b96f95303897bfa23f846db54064e" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -2591,9 +2622,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.88" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e397f4664c0e4e428e8313a469aaa58310d302159845980fd23b0f22a847f217" +checksum = "1b56f625e64f3a1084ded111c4d5f477df9f8c92df113852fa5a374dbda78826" dependencies = [ "bumpalo", "log", @@ -2606,9 +2637,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.38" +version = "0.4.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9afec9963e3d0994cac82455b2b3502b81a7f40f9a0d32181f7528d9f4b43e02" +checksum = "ac36a15a220124ac510204aec1c3e5db8a22ab06fd6706d881dc6149f8ed9a12" dependencies = [ "cfg-if", "js-sys", @@ -2618,9 +2649,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.88" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5961017b3b08ad5f3fe39f1e79877f8ee7c23c5e5fd5eb80de95abc41f1f16b2" +checksum = "0162dbf37223cd2afce98f3d0785506dcb8d266223983e4b5b525859e6e182b2" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2628,9 +2659,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.88" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5353b8dab669f5e10f5bd76df26a9360c748f054f862ff5f3f8aae0c7fb3907" +checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" dependencies = [ "proc-macro2", "quote", @@ -2641,15 +2672,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.88" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d046c5d029ba91a1ed14da14dca44b68bf2f124cfbaf741c54151fdb3e0750b" +checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f" [[package]] name = "wasm-bindgen-test" -version = "0.3.38" +version = "0.3.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6433b7c56db97397842c46b67e11873eda263170afeb3a2dc74a7cb370fee0d" +checksum = "2cf9242c0d27999b831eae4767b2a146feb0b27d332d553e605864acd2afd403" dependencies = [ "console_error_panic_hook", "js-sys", @@ -2661,9 +2692,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-test-macro" -version = "0.3.38" +version = "0.3.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "493fcbab756bb764fa37e6bee8cec2dd709eb4273d06d0c282a5e74275ded735" +checksum = "794645f5408c9a039fd09f4d113cdfb2e7eba5ff1956b07bcf701cf4b394fe89" dependencies = [ "proc-macro2", "quote", @@ -2672,9 +2703,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.65" +version = "0.3.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5db499c5f66323272151db0e666cd34f78617522fb0c1604d31a27c50c206a85" +checksum = "50c24a44ec86bb68fbecd1b3efed7e85ea5621b39b35ef2766b66cd984f8010f" dependencies = [ "js-sys", "wasm-bindgen", @@ -2686,6 +2717,12 @@ version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22fc3756b8a9133049b26c7f61ab35416c130e8c09b660f5b3958b446f52cc50" +[[package]] +name = "wildmatch" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee583bdc5ff1cf9db20e9db5bb3ff4c3089a8f6b8b31aff265c9aba85812db86" + [[package]] name = "winapi" version = "0.3.9" @@ -2714,7 +2751,7 @@ version = "0.51.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64" dependencies = [ - "windows-targets", + "windows-targets 0.48.5", ] [[package]] @@ -2723,7 +2760,16 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "windows-targets", + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.0", ] [[package]] @@ -2732,13 +2778,28 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" +dependencies = [ + "windows_aarch64_gnullvm 0.52.0", + "windows_aarch64_msvc 0.52.0", + "windows_i686_gnu 0.52.0", + "windows_i686_msvc 0.52.0", + "windows_x86_64_gnu 0.52.0", + "windows_x86_64_gnullvm 0.52.0", + "windows_x86_64_msvc 0.52.0", ] [[package]] @@ -2747,36 +2808,72 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" + [[package]] name = "windows_aarch64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" + [[package]] name = "windows_i686_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +[[package]] +name = "windows_i686_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" + [[package]] name = "windows_i686_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" +[[package]] +name = "windows_i686_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" + [[package]] name = "windows_x86_64_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" + [[package]] name = "windows_x86_64_gnullvm" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" + [[package]] name = "windows_x86_64_msvc" version = "0.48.5" @@ -2784,10 +2881,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] -name = "winnow" -version = "0.5.19" +name = "windows_x86_64_msvc" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "829846f3e3db426d4cee4510841b71a8e58aa2a76b1132579487ae430ccd9c7b" +checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" + +[[package]] +name = "winnow" +version = "0.5.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b67b5f0a4e7a27a64c651977932b9dc5667ca7fc31ac44b03ed37a0cf42fdfff" dependencies = [ "memchr", ] @@ -2799,7 +2902,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" dependencies = [ "cfg-if", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -2823,18 +2926,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.7.25" +version = "0.7.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cd369a67c0edfef15010f980c3cbe45d7f651deac2cd67ce097cd801de16557" +checksum = "306dca4455518f1f31635ec308b6b3e4eb1b11758cefafc782827d0aa7acb5c7" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.25" +version = "0.7.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2f140bda219a26ccc0cdb03dba58af72590c53b22642577d88a927bc5c87d6b" +checksum = "be912bf68235a88fbefd1b73415cb218405958d1655b2ece9035a19920bdf6ba" dependencies = [ "proc-macro2", "quote", @@ -2843,6 +2946,6 @@ dependencies = [ [[package]] name = "zeroize" -version = "1.6.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" +checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" From ce6f09b6575420d293f6ea953d95bf86be627b85 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 10 Dec 2023 18:40:03 +0100 Subject: [PATCH 35/35] Update documentation and examples --- README.md | 2 +- src/instance.rs | 2 +- src/lib.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0f295ae..c02da77 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ async fn main() { "wss://example.com/".to_string(), "https://example.com/cdn".to_string(), ); - let instance = Instance::new(bundle, true) + let instance = Instance::new(bundle) .await .expect("Failed to connect to the Spacebar server"); // You can create as many instances of `Instance` as you want, but each `Instance` should likely be unique. diff --git a/src/instance.rs b/src/instance.rs index cd9eb76..f151ced 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -72,7 +72,7 @@ impl PartialEq for LimitsInformation { } impl Instance { - /// Creates a new [`Instance`] from the [relevant instance urls](UrlBundle), where `limited` is whether Chorus will track and enforce rate limits for this instance. + /// Creates a new [`Instance`] from the [relevant instance urls](UrlBundle). To create an Instance from one singular url, use [`Instance::from_root_url()`]. pub async fn new(urls: UrlBundle) -> ChorusResult { let is_limited: Option = Instance::is_limited(&urls.api).await?; let limit_information; diff --git a/src/lib.rs b/src/lib.rs index 80374fb..0bddc3a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,7 +19,7 @@ async fn main() { "wss://example.com/".to_string(), "https://example.com/cdn".to_string(), ); - let instance = Instance::new(bundle, true) + let instance = Instance::new(bundle) .await .expect("Failed to connect to the Spacebar server"); // You can create as many instances of `Instance` as you want, but each `Instance` should likely be unique.