diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml
index a6abe43..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"
- - 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"
+ # 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:
diff --git a/Cargo.lock b/Cargo.lock
index 9e5c578..17b54fe 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"
@@ -189,7 +199,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chorus"
-version = "0.12.0"
+version = "0.13.0"
dependencies = [
"async-trait",
"base64 0.21.5",
@@ -252,7 +262,7 @@ dependencies = [
"num-traits",
"serde",
"wasm-bindgen",
- "windows-targets",
+ "windows-targets 0.48.5",
]
[[package]]
@@ -273,9 +283,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",
@@ -283,9 +293,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"
@@ -400,9 +410,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",
@@ -462,12 +472,12 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "errno"
-version = "0.3.7"
+version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f258a7194e7f7c2a7837a8913aeab7fd8c383457034fa20ce4dd3dcb813e8eb8"
+checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245"
dependencies = [
"libc",
- "windows-sys",
+ "windows-sys 0.52.0",
]
[[package]]
@@ -478,7 +488,7 @@ checksum = "136d1b5283a1ab77bd9257427ffd09d8667ced0570b6f938942bc7568ed5b943"
dependencies = [
"cfg-if",
"home",
- "windows-sys",
+ "windows-sys 0.48.0",
]
[[package]]
@@ -533,9 +543,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",
]
@@ -665,9 +675,9 @@ 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"
@@ -696,9 +706,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",
@@ -710,7 +720,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]]
@@ -782,7 +792,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]]
@@ -809,9 +819,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",
@@ -898,9 +908,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",
@@ -924,7 +934,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f"
dependencies = [
"equivalent",
- "hashbrown 0.14.2",
+ "hashbrown 0.14.3",
"serde",
]
@@ -945,24 +955,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",
]
@@ -992,9 +1002,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"
@@ -1004,9 +1014,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",
@@ -1015,9 +1025,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"
@@ -1090,13 +1100,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]]
@@ -1224,15 +1234,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",
@@ -1262,9 +1272,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",
@@ -1292,7 +1302,7 @@ dependencies = [
"libc",
"redox_syscall",
"smallvec",
- "windows-targets",
+ "windows-targets 0.48.5",
]
[[package]]
@@ -1321,9 +1331,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"
@@ -1461,18 +1471,19 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "proc-macro-crate"
-version = "2.0.0"
+version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7e8366a6159044a37876a2b9817124296703c586a5c92e2c53751fa06d8d43e8"
+checksum = "97dc5fea232fc28d2f597b37c4876b348a40e33f3b02cc975c8d006d78d94b1a"
dependencies = [
+ "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",
]
@@ -1618,23 +1629,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.4"
+version = "0.9.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6a3211b01eea83d80687da9eef70e39d65144a3894866a5153a2723e425a157f"
+checksum = "5d0e5124fcb30e76a7e79bfee683a2746db83784b86289f6251b54b7950a0dfc"
dependencies = [
"const-oid",
"digest",
@@ -1667,25 +1678,25 @@ dependencies = [
[[package]]
name = "rustix"
-version = "0.38.25"
+version = "0.38.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "dc99bc2d4f1fed22595588a013687477aedf3cdcfb26558c559edb67b4d9b22e"
+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.9"
+version = "0.21.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "629648aced5775d558af50b2b4c7b02983a04b312126d45eeead26e7caa498b9"
+checksum = "f9d5a6813c0759e4609cd494e8e725babae6a2ca7b62a5536a13daaec6fcb7ba"
dependencies = [
"log",
- "ring 0.17.5",
+ "ring 0.17.7",
"rustls-webpki",
"sct",
]
@@ -1717,15 +1728,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"
@@ -1742,7 +1753,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]]
@@ -1763,7 +1774,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",
]
@@ -1813,9 +1824,9 @@ dependencies = [
[[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",
@@ -1972,7 +1983,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9"
dependencies = [
"libc",
- "windows-sys",
+ "windows-sys 0.48.0",
]
[[package]]
@@ -1992,9 +2003,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",
@@ -2002,9 +2013,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",
@@ -2013,9 +2024,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",
@@ -2026,9 +2037,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",
@@ -2069,9 +2080,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",
@@ -2082,10 +2093,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",
@@ -2108,9 +2120,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",
@@ -2151,9 +2163,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",
@@ -2192,9 +2204,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",
@@ -2211,6 +2223,7 @@ dependencies = [
"sqlx-core",
"tracing",
"url",
+ "urlencoding",
]
[[package]]
@@ -2289,7 +2302,7 @@ dependencies = [
"fastrand",
"redox_syscall",
"rustix",
- "windows-sys",
+ "windows-sys 0.48.0",
]
[[package]]
@@ -2358,9 +2371,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",
@@ -2370,7 +2383,7 @@ dependencies = [
"pin-project-lite",
"socket2 0.5.5",
"tokio-macros",
- "windows-sys",
+ "windows-sys 0.48.0",
]
[[package]]
@@ -2446,15 +2459,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.20.7"
+version = "0.20.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "70f427fce4d84c72b5b732388bf4a9f4531b53f74e2887e3ecb2481f68f66d81"
+checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338"
dependencies = [
"indexmap 2.1.0",
"toml_datetime",
@@ -2501,9 +2514,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"
@@ -2551,9 +2564,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"
@@ -2596,15 +2609,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"
@@ -2640,9 +2659,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",
@@ -2650,9 +2669,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",
@@ -2665,9 +2684,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",
@@ -2677,9 +2696,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",
@@ -2687,9 +2706,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",
@@ -2700,15 +2719,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",
@@ -2720,9 +2739,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",
@@ -2731,9 +2750,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",
@@ -2779,7 +2798,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]]
@@ -2788,7 +2807,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]]
@@ -2797,13 +2825,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]]
@@ -2812,36 +2855,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"
@@ -2849,10 +2928,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",
]
@@ -2864,7 +2949,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1"
dependencies = [
"cfg-if",
- "windows-sys",
+ "windows-sys 0.48.0",
]
[[package]]
@@ -2888,18 +2973,18 @@ dependencies = [
[[package]]
name = "zerocopy"
-version = "0.7.26"
+version = "0.7.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e97e415490559a91254a2979b4829267a57d2fcd741a98eee8b722fb57289aa0"
+checksum = "306dca4455518f1f31635ec308b6b3e4eb1b11758cefafc782827d0aa7acb5c7"
dependencies = [
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
-version = "0.7.26"
+version = "0.7.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "dd7e48ccf166952882ca8bd778a43502c64f33bf94c12ebe2a7f08e5a0f6689f"
+checksum = "be912bf68235a88fbefd1b73415cb218405958d1655b2ece9035a19920bdf6ba"
dependencies = [
"proc-macro2",
"quote",
diff --git a/Cargo.toml b/Cargo.toml
index da7c127..2498e7b 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 89d849f..c02da77 100644
--- a/README.md
+++ b/README.md
@@ -3,25 +3,24 @@
[![Discord]][Discord-invite]
[![Build][build-shield]][build-url]
[![Coverage][coverage-shield]][coverage-url]
-[![Contributors][contributors-shield]][contributors-url]
-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.13.0"
```
### Establishing a Connection
@@ -60,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/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 b06eade..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 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/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();
diff --git a/src/errors.rs b/src/errors.rs
index 07bd5b3..15c5b44 100644
--- a/src/errors.rs
+++ b/src/errors.rs
@@ -44,6 +44,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
diff --git a/src/instance.rs b/src/instance.rs
index 4ce4338..f151ced 100644
--- a/src/instance.rs
+++ b/src/instance.rs
@@ -12,44 +12,85 @@ 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)]
+#[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 {
- 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 {
+ /// 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;
+
+ 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 {
@@ -61,12 +102,39 @@ 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 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_url(root_url: &str) -> ChorusResult {
+ let urls = UrlBundle::from_root_url(root_url).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),
+ }
+ }
}
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
@@ -93,6 +161,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()
diff --git a/src/lib.rs b/src/lib.rs
index 47bbaab..0bddc3a 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:
+
+```rs
+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)
+ .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:
+
+```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.
+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"
)]
@@ -14,11 +101,23 @@
clippy::new_without_default,
clippy::useless_conversion
)]
+#![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");
+use errors::ChorusResult;
+use serde::{Deserialize, Serialize};
+use types::types::domains_configuration::WellKnownResponse;
use url::{ParseError, Url};
+use crate::errors::ChorusError;
+
#[cfg(feature = "client")]
pub mod api;
pub mod errors;
@@ -32,7 +131,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
@@ -80,7 +179,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();
@@ -89,6 +188,63 @@ impl UrlBundle {
}
url_string
}
+
+ /// 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`
+ /// - 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_url(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", parsed)).await
+ {
+ return Ok(response_slash_api);
+ }
+ if let Ok(response_api) =
+ UrlBundle::from_api_url(&format!("{}/policies/instance/domains", parsed)).await
+ {
+ Ok(response_api)
+ } else {
+ 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() } )
+ }
+ }
+ }
+
+ async fn from_api_url(url: &str) -> ChorusResult {
+ 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(),
+ })
+ }
+ }
}
#[cfg(test)]
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()
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/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/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;
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,
}
}
}
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/guild.rs b/src/types/entities/guild.rs
index eb04322..1fe235b 100644
--- a/src/types/entities/guild.rs
+++ b/src/types/entities/guild.rs
@@ -346,6 +346,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
@@ -356,6 +357,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
@@ -367,6 +369,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
@@ -380,6 +383,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
@@ -390,6 +394,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
@@ -402,6 +407,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
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/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)
diff --git a/tests/auth.rs b/tests/auth.rs
index 086c8ba..130bfb6 100644
--- a/tests/auth.rs
+++ b/tests/auth.rs
@@ -1,5 +1,4 @@
-use chorus::types::RegisterSchema;
-// PRETTYFYME: Move common wasm setup to common.rs
+use chorus::types::{LoginSchema, RegisterSchema};
#[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::*;
#[cfg(target_arch = "wasm32")]
@@ -10,13 +9,91 @@ 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;
+}
+
+#[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;
}
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/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(),
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")]
diff --git a/tests/urlbundle.rs b/tests/urlbundle.rs
new file mode 100644
index 0000000..790229b
--- /dev/null
+++ b/tests/urlbundle.rs
@@ -0,0 +1,26 @@
+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")]
+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_url(url.as_str()).await.unwrap();
+ let url = url::Url::parse("http://localhost:3001/api/").unwrap();
+ UrlBundle::from_root_url(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();
+}