From 01471342b0f540a6421e47dbdb32704fada44558 Mon Sep 17 00:00:00 2001 From: Katalina Okano Date: Sun, 27 Nov 2022 18:18:41 -0500 Subject: [PATCH] refactor api --- Cargo.lock | 1343 +++++------------ .../codegen/src/templates/translators.rs.tera | 20 +- services/api/Cargo.toml | 12 +- services/api/src/classes.rs | 39 + services/api/src/cors.rs | 22 - services/api/src/graphql/mod.rs | 123 -- services/api/src/graphql/types.rs | 361 ----- services/api/src/health.rs | 74 + services/api/src/html/404.html | 22 + services/api/src/main.rs | 163 +- services/api/src/query.rs | 24 + services/api/src/redispool.rs | 5 - services/api/src/util.rs | 17 + services/api/src/vehicles.rs | 76 + services/api/src/world.rs | 112 ++ services/websocket/Cargo.toml | 3 +- services/websocket/src/main.rs | 21 +- services/websocket/src/translators.rs | 31 +- 18 files changed, 873 insertions(+), 1595 deletions(-) create mode 100644 services/api/src/classes.rs delete mode 100644 services/api/src/cors.rs delete mode 100644 services/api/src/graphql/mod.rs delete mode 100644 services/api/src/graphql/types.rs create mode 100644 services/api/src/health.rs create mode 100644 services/api/src/html/404.html create mode 100644 services/api/src/query.rs delete mode 100644 services/api/src/redispool.rs create mode 100644 services/api/src/util.rs create mode 100644 services/api/src/vehicles.rs create mode 100644 services/api/src/world.rs diff --git a/Cargo.lock b/Cargo.lock index 611c3c7..d1031ec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,38 +3,13 @@ version = 3 [[package]] -name = "aead" -version = "0.5.1" +name = "Inflector" +version = "0.11.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c192eb8f11fc081b0fe4259ba5af04217d4e0faddd02417310a927911abd7c8" +checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" dependencies = [ - "crypto-common", - "generic-array", -] - -[[package]] -name = "aes" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "433cfd6710c9986c576a25ca913c39d66a6474107b406f34f91d4a8923395241" -dependencies = [ - "cfg-if", - "cipher", - "cpufeatures", -] - -[[package]] -name = "aes-gcm" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82e1366e0c69c9f927b1fa5ce2c7bf9eafc8f9268c0b9800729e8b267612447c" -dependencies = [ - "aead", - "aes", - "cipher", - "ctr", - "ghash", - "subtle", + "lazy_static", + "regex", ] [[package]] @@ -59,20 +34,112 @@ dependencies = [ name = "api" version = "0.1.0" dependencies = [ - "juniper", - "juniper_rocket", + "async-graphql", + "async-graphql-axum", + "axum 0.6.0", + "lazy_static", + "redis", + "serde", + "serde_json", + "tokio", + "tower-http", +] + +[[package]] +name = "ascii_utils" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71938f30533e4d95a6d17aa530939da3842c2ab6f4f84b9dae68447e4129f74a" + +[[package]] +name = "async-graphql" +version = "4.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9ed522678d412d77effe47b3c82314ac36952a35e6e852093dd48287c421f80" +dependencies = [ + "async-graphql-derive", + "async-graphql-parser", + "async-graphql-value", + "async-stream", + "async-trait", + "base64", + "bytes", + "chrono", + "fast_chemail", + "fnv", + "futures-util", + "http", + "indexmap", + "mime", + "multer", + "num-traits", "once_cell", - "rocket", - "rocket_db_pools", + "pin-project-lite", + "regex", + "serde", + "serde_json", + "serde_urlencoded", + "static_assertions", + "tempfile", + "thiserror", +] + +[[package]] +name = "async-graphql-axum" +version = "4.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c91ac174c05670edffb720bc376b9d4c274c3d127ac08ed3d38144c9415502cd" +dependencies = [ + "async-graphql", + "async-trait", + "axum 0.5.17", + "bytes", + "futures-util", + "http-body", + "serde_json", + "tokio-util", + "tower-service", +] + +[[package]] +name = "async-graphql-derive" +version = "4.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c121a894495d7d3fc3d4e15e0a9843e422e4d1d9e3c514d8062a1c94b35b005d" +dependencies = [ + "Inflector", + "async-graphql-parser", + "darling", + "proc-macro-crate", + "proc-macro2", + "quote", + "syn", + "thiserror", +] + +[[package]] +name = "async-graphql-parser" +version = "4.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b6c386f398145c6180206c1869c2279f5a3d45db5be4e0266148c6ac5c6ad68" +dependencies = [ + "async-graphql-value", + "pest", "serde", "serde_json", ] [[package]] -name = "ascii" -version = "0.9.3" +name = "async-graphql-value" +version = "4.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eab1c04a571841102f5345a8fc0f6bb3d31c315dec879b5c6e42e40ce7ffa34e" +checksum = "7a941b499fead4a3fb5392cabf42446566d18c86313f69f2deab69560394d65f" +dependencies = [ + "bytes", + "indexmap", + "serde", + "serde_json", +] [[package]] name = "async-stream" @@ -106,44 +173,119 @@ dependencies = [ "syn", ] -[[package]] -name = "atomic" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b88d82667eca772c4aa12f0f1348b3ae643424c8876448f3f7bd5787032e234c" -dependencies = [ - "autocfg", -] - -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi", - "libc", - "winapi", -] - [[package]] name = "autocfg" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "axum" +version = "0.5.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acee9fd5073ab6b045a275b3e709c163dd36c90685219cb21804a147b58dba43" +dependencies = [ + "async-trait", + "axum-core 0.2.9", + "base64", + "bitflags", + "bytes", + "futures-util", + "headers", + "http", + "http-body", + "hyper", + "itoa", + "matchit 0.5.0", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "serde", + "serde_json", + "serde_urlencoded", + "sha-1", + "sync_wrapper", + "tokio", + "tokio-tungstenite", + "tower", + "tower-http", + "tower-layer", + "tower-service", +] + +[[package]] +name = "axum" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "744864363a200a5e724a7e61bc8c11b6628cf2e3ec519c8a1a48e609a8156b40" +dependencies = [ + "async-trait", + "axum-core 0.3.0", + "bitflags", + "bytes", + "futures-util", + "http", + "http-body", + "hyper", + "itoa", + "matchit 0.6.0", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "rustversion", + "serde", + "serde_json", + "serde_path_to_error", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tower", + "tower-http", + "tower-layer", + "tower-service", +] + +[[package]] +name = "axum-core" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37e5939e02c56fecd5c017c37df4238c0a839fa76b7f97acdd7efb804fd181cc" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http", + "http-body", + "mime", + "tower-layer", + "tower-service", +] + +[[package]] +name = "axum-core" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79b8558f5a0581152dc94dcd289132a1d377494bdeafcd41869b3258e3e2ad92" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http", + "http-body", + "mime", + "rustversion", + "tower-layer", + "tower-service", +] + [[package]] name = "base64" version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" -[[package]] -name = "binascii" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "383d29d513d8764dcdc42ea295d979eb99c3c9f00607b3692cf68a431f7dca72" - [[package]] name = "bitflags" version = "1.3.2" @@ -159,23 +301,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bson" -version = "1.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de0aa578035b938855a710ba58d43cfb4d435f3619f99236fb35922a574d6cb1" -dependencies = [ - "base64", - "chrono", - "hex", - "lazy_static", - "linked-hash-map", - "rand 0.7.3", - "serde", - "serde_json", - "uuid", -] - [[package]] name = "bstr" version = "0.2.17" @@ -202,6 +327,9 @@ name = "bytes" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db" +dependencies = [ + "serde", +] [[package]] name = "cc" @@ -222,24 +350,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f" dependencies = [ "iana-time-zone", - "js-sys", "num-integer", "num-traits", - "time 0.1.44", - "wasm-bindgen", "winapi", ] -[[package]] -name = "cipher" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1873270f8f7942c191139cb8a40fd228da6c3fd2fc376d7e92d47aa14aeb59e" -dependencies = [ - "crypto-common", - "inout", -] - [[package]] name = "codegen" version = "0.1.0" @@ -264,19 +379,6 @@ dependencies = [ "unicode-width", ] -[[package]] -name = "combine" -version = "3.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da3da6baa321ec19e1cc41d31bf599f00c783d0517095cdaf0332e3fe8d20680" -dependencies = [ - "ascii", - "byteorder", - "either", - "memchr", - "unreachable", -] - [[package]] name = "combine" version = "4.6.6" @@ -291,24 +393,6 @@ dependencies = [ "tokio-util", ] -[[package]] -name = "cookie" -version = "0.16.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "344adc371239ef32293cb1c4fe519592fcf21206c79c02854320afcdf3ab4917" -dependencies = [ - "aes-gcm", - "base64", - "hkdf", - "hmac", - "percent-encoding", - "rand 0.8.5", - "sha2", - "subtle", - "time 0.3.17", - "version_check", -] - [[package]] name = "core-foundation" version = "0.9.3" @@ -350,19 +434,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" dependencies = [ "generic-array", - "rand_core 0.6.4", "typenum", ] -[[package]] -name = "ctr" -version = "0.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835" -dependencies = [ - "cipher", -] - [[package]] name = "cxx" version = "1.0.82" @@ -408,77 +482,36 @@ dependencies = [ ] [[package]] -name = "deadpool" -version = "0.9.5" +name = "darling" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "421fe0f90f2ab22016f32a9881be5134fdd71c65298917084b0c7477cbc3856e" +checksum = "b0dd3cd20dc6b5a876612a6e5accfe7f3dd883db6d07acfbf14c128f61550dfa" dependencies = [ - "async-trait", - "deadpool-runtime", - "num_cpus", - "retain_mut", - "tokio", + "darling_core", + "darling_macro", ] [[package]] -name = "deadpool-redis" -version = "0.10.2" +name = "darling_core" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a62ebf187bc30bfc1a14bed4073912b988551d111208fe800b27c32df282481" -dependencies = [ - "deadpool", - "redis 0.21.6", -] - -[[package]] -name = "deadpool-runtime" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eaa37046cc0f6c3cc6090fbdbf73ef0b8ef4cfcc37f6befc0020f63e8cf121e1" -dependencies = [ - "tokio", -] - -[[package]] -name = "derive_utils" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "532b4c15dccee12c7044f1fcad956e98410860b22231e44a3b827464797ca7bf" +checksum = "a784d2ccaf7c98501746bf0be29b2022ba41fd62a2e622af997a03e9f972859f" dependencies = [ + "fnv", + "ident_case", "proc-macro2", "quote", + "strsim", "syn", ] [[package]] -name = "devise" -version = "0.3.1" +name = "darling_macro" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50c7580b072f1c8476148f16e0a0d5dedddab787da98d86c5082c5e9ed8ab595" +checksum = "7618812407e9402654622dd402b0a89dff9ba93badd6540781526117b92aab7e" dependencies = [ - "devise_codegen", - "devise_core", -] - -[[package]] -name = "devise_codegen" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "123c73e7a6e51b05c75fe1a1b2f4e241399ea5740ed810b0e3e6cacd9db5e7b2" -dependencies = [ - "devise_core", - "quote", -] - -[[package]] -name = "devise_core" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "841ef46f4787d9097405cac4e70fb8644fc037b526e8c14054247c0263c400d0" -dependencies = [ - "bitflags", - "proc-macro2", - "proc-macro2-diagnostics", + "darling_core", "quote", "syn", ] @@ -491,15 +524,8 @@ checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" dependencies = [ "block-buffer", "crypto-common", - "subtle", ] -[[package]] -name = "either" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" - [[package]] name = "encoding_rs" version = "0.8.31" @@ -509,6 +535,15 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "fast_chemail" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "495a39d30d624c2caabe6312bfead73e7717692b44e0b32df168c275a2e8e9e4" +dependencies = [ + "ascii_utils", +] + [[package]] name = "fastrand" version = "1.8.0" @@ -518,20 +553,6 @@ dependencies = [ "instant", ] -[[package]] -name = "figment" -version = "0.10.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e56602b469b2201400dec66a66aec5a9b8761ee97cd1b8c96ab2483fcc16cc9" -dependencies = [ - "atomic", - "pear", - "serde", - "toml", - "uncased", - "version_check", -] - [[package]] name = "fnv" version = "1.0.7" @@ -593,17 +614,6 @@ version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04909a7a7e4633ae6c4a9ab280aeb86da1236243a77b694a49eacd659a4bd3ac" -[[package]] -name = "futures-enum" -version = "0.1.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3422d14de7903a52e9dbc10ae05a7e14445ec61890100e098754e120b2bd7b1e" -dependencies = [ - "derive_utils", - "quote", - "syn", -] - [[package]] name = "futures-executor" version = "0.3.25" @@ -662,19 +672,6 @@ dependencies = [ "slab", ] -[[package]] -name = "generator" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc184cace1cea8335047a471cc1da80f18acf8a76f3bab2028d499e328948ec7" -dependencies = [ - "cc", - "libc", - "log", - "rustversion", - "windows", -] - [[package]] name = "generic-array" version = "0.14.6" @@ -685,17 +682,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "getrandom" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" -dependencies = [ - "cfg-if", - "libc", - "wasi 0.9.0+wasi-snapshot-preview1", -] - [[package]] name = "getrandom" version = "0.2.8" @@ -704,25 +690,9 @@ checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" dependencies = [ "cfg-if", "libc", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", ] -[[package]] -name = "ghash" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d930750de5717d2dd0b8c0d42c076c0e884c81a73e6cab859bbd2339c71e3e40" -dependencies = [ - "opaque-debug", - "polyval", -] - -[[package]] -name = "glob" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" - [[package]] name = "globset" version = "0.4.9" @@ -747,16 +717,6 @@ dependencies = [ "walkdir", ] -[[package]] -name = "graphql-parser" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1abd4ce5247dfc04a03ccde70f87a048458c9356c7e41d21ad8c407b3dde6f2" -dependencies = [ - "combine 3.8.1", - "thiserror", -] - [[package]] name = "h2" version = "0.3.15" @@ -782,6 +742,31 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +[[package]] +name = "headers" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3e372db8e5c0d213e0cd0b9be18be2aca3d44cf2fe30a9d46a65581cd454584" +dependencies = [ + "base64", + "bitflags", + "bytes", + "headers-core", + "http", + "httpdate", + "mime", + "sha1", +] + +[[package]] +name = "headers-core" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7f66481bfee273957b1f20485a4ff3362987f85b2c236580d81b4eb7a326429" +dependencies = [ + "http", +] + [[package]] name = "hermit-abi" version = "0.1.19" @@ -791,30 +776,6 @@ dependencies = [ "libc", ] -[[package]] -name = "hex" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" - -[[package]] -name = "hkdf" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "791a029f6b9fc27657f6f188ec6e5e43f6911f6f878e0dc5501396e09809d437" -dependencies = [ - "hmac", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "http" version = "0.2.8" @@ -837,6 +798,12 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "http-range-header" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bfe8eed0a9285ef776bb792479ea3834e8b94e13d615c2f66d03dd50a435a29" + [[package]] name = "httparse" version = "1.8.0" @@ -910,6 +877,12 @@ dependencies = [ "cxx-build", ] +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "idna" version = "0.3.0" @@ -949,21 +922,6 @@ dependencies = [ "serde", ] -[[package]] -name = "inlinable_string" -version = "0.1.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8fae54786f62fb2918dcfae3d568594e50eb9b5c25bf04371af6fe7516452fb" - -[[package]] -name = "inout" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" -dependencies = [ - "generic-array", -] - [[package]] name = "instant" version = "0.1.12" @@ -994,52 +952,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "juniper" -version = "0.15.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f478f229a8ab52ff242f3250c8b3b8fe0a59b5b934f9706b7bdbc980991a7b6" -dependencies = [ - "async-trait", - "bson", - "chrono", - "fnv", - "futures", - "futures-enum", - "graphql-parser", - "indexmap", - "juniper_codegen", - "serde", - "smartstring", - "static_assertions", - "url", - "uuid", -] - -[[package]] -name = "juniper_codegen" -version = "0.15.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aee97671061ad50301ba077d054d295e01d31a1868fbd07902db651f987e71db" -dependencies = [ - "proc-macro-error", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "juniper_rocket" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a431e6f03bc31bd74498a837e87ddf635deef3c1a2026e59680dec2552c84c28" -dependencies = [ - "futures", - "juniper", - "rocket", - "serde_json", -] - [[package]] name = "lazy_static" version = "1.4.0" @@ -1061,12 +973,6 @@ dependencies = [ "cc", ] -[[package]] -name = "linked-hash-map" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" - [[package]] name = "lock_api" version = "0.4.9" @@ -1087,28 +993,16 @@ dependencies = [ ] [[package]] -name = "loom" -version = "0.5.6" +name = "matchit" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff50ecb28bb86013e935fb6683ab1f6d3a20016f123c76fd4c27470076ac30f5" -dependencies = [ - "cfg-if", - "generator", - "scoped-tls", - "serde", - "serde_json", - "tracing", - "tracing-subscriber", -] +checksum = "73cbba799671b762df5a175adf59ce145165747bb891505c43d09aefbbf38beb" [[package]] -name = "matchers" -version = "0.1.0" +name = "matchit" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" -dependencies = [ - "regex-automata", -] +checksum = "3dfc802da7b1cf80aefffa0c7b2f77247c8b32206cc83c270b61264f5b360a80" [[package]] name = "memchr" @@ -1130,7 +1024,7 @@ checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de" dependencies = [ "libc", "log", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", "windows-sys 0.42.0", ] @@ -1149,8 +1043,6 @@ dependencies = [ "memchr", "mime", "spin", - "tokio", - "tokio-util", "version_check", ] @@ -1172,16 +1064,6 @@ dependencies = [ "tempfile", ] -[[package]] -name = "nu-ansi-term" -version = "0.46.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" -dependencies = [ - "overload", - "winapi", -] - [[package]] name = "num-integer" version = "0.1.45" @@ -1217,12 +1099,6 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" -[[package]] -name = "opaque-debug" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" - [[package]] name = "openssl" version = "0.10.42" @@ -1268,12 +1144,6 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "overload" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" - [[package]] name = "parking_lot" version = "0.12.1" @@ -1297,29 +1167,6 @@ dependencies = [ "windows-sys 0.42.0", ] -[[package]] -name = "pear" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15e44241c5e4c868e3eaa78b7c1848cadd6344ed4f54d029832d32b415a58702" -dependencies = [ - "inlinable_string", - "pear_codegen", - "yansi", -] - -[[package]] -name = "pear_codegen" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82a5ca643c2303ecb740d506539deba189e16f2754040a42901cd8105d0282d0" -dependencies = [ - "proc-macro2", - "proc-macro2-diagnostics", - "quote", - "syn", -] - [[package]] name = "percent-encoding" version = "2.2.0" @@ -1370,6 +1217,26 @@ dependencies = [ "sha1", ] +[[package]] +name = "pin-project" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad29a609b6bcd67fee905812e544992d216af9d755757c05ed2d0e15a74c6ecc" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "pin-project-lite" version = "0.2.9" @@ -1388,18 +1255,6 @@ version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" -[[package]] -name = "polyval" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ef234e08c11dfcb2e56f79fd70f6f2eb7f025c0ce2333e82f4f0518ecad30c6" -dependencies = [ - "cfg-if", - "cpufeatures", - "opaque-debug", - "universal-hash", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -1407,27 +1262,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] -name = "proc-macro-error" -version = "1.0.4" +name = "proc-macro-crate" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +checksum = "eda0fc3b0fb7c975631757e14d9049da17374063edb6ebbcbc54d880d4fe94e9" dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check", + "once_cell", + "thiserror", + "toml", ] [[package]] @@ -1439,19 +1281,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "proc-macro2-diagnostics" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bf29726d67464d49fa6224a1d07936a8c08bb3fba727c7493f6cf1616fdaada" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "version_check", - "yansi", -] - [[package]] name = "quote" version = "1.0.21" @@ -1472,19 +1301,6 @@ dependencies = [ "scheduled-thread-pool", ] -[[package]] -name = "rand" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" -dependencies = [ - "getrandom 0.1.16", - "libc", - "rand_chacha 0.2.2", - "rand_core 0.5.1", - "rand_hc", -] - [[package]] name = "rand" version = "0.8.5" @@ -1492,18 +1308,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", - "rand_chacha 0.3.1", - "rand_core 0.6.4", -] - -[[package]] -name = "rand_chacha" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" -dependencies = [ - "ppv-lite86", - "rand_core 0.5.1", + "rand_chacha", + "rand_core", ] [[package]] @@ -1513,16 +1319,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core 0.6.4", -] - -[[package]] -name = "rand_core" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" -dependencies = [ - "getrandom 0.1.16", + "rand_core", ] [[package]] @@ -1531,35 +1328,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom 0.2.8", -] - -[[package]] -name = "rand_hc" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" -dependencies = [ - "rand_core 0.5.1", -] - -[[package]] -name = "redis" -version = "0.21.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "571c252c68d09a2ad3e49edd14e9ee48932f3e0f27b06b4ea4c9b2a706d31103" -dependencies = [ - "async-trait", - "bytes", - "combine 4.6.6", - "futures-util", - "itoa", - "percent-encoding", - "pin-project-lite", - "ryu", - "tokio", - "tokio-util", - "url", + "getrandom", ] [[package]] @@ -1568,24 +1337,21 @@ version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "513b3649f1a111c17954296e4a3b9eecb108b766c803e2b99f179ebe27005985" dependencies = [ - "combine 4.6.6", + "async-trait", + "bytes", + "combine", + "futures-util", "itoa", "percent-encoding", + "pin-project-lite", "r2d2", "ryu", "sha1_smol", + "tokio", + "tokio-util", "url", ] -[[package]] -name = "redis_ts" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52c56cb76c7c8a0f2624cd8d2fec425080637dc0e43b850eee1fd6116577c3be" -dependencies = [ - "redis 0.22.1", -] - [[package]] name = "redox_syscall" version = "0.2.16" @@ -1595,26 +1361,6 @@ dependencies = [ "bitflags", ] -[[package]] -name = "ref-cast" -version = "1.0.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53b15debb4f9d60d767cd8ca9ef7abb2452922f3214671ff052defc7f3502c44" -dependencies = [ - "ref-cast-impl", -] - -[[package]] -name = "ref-cast-impl" -version = "1.0.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abfa8511e9e94fd3de6585a3d3cd00e01ed556dc9814829280af0e8dc72a8f36" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "regex" version = "1.7.0" @@ -1626,15 +1372,6 @@ dependencies = [ "regex-syntax", ] -[[package]] -name = "regex-automata" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" -dependencies = [ - "regex-syntax", -] - [[package]] name = "regex-syntax" version = "0.6.28" @@ -1687,117 +1424,6 @@ dependencies = [ "winreg", ] -[[package]] -name = "retain_mut" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4389f1d5789befaf6029ebd9f7dac4af7f7e3d61b69d4f30e2ac02b57e7712b0" - -[[package]] -name = "rocket" -version = "0.5.0-rc.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98ead083fce4a405feb349cf09abdf64471c6077f14e0ce59364aa90d4b99317" -dependencies = [ - "async-stream", - "async-trait", - "atomic", - "atty", - "binascii", - "bytes", - "either", - "figment", - "futures", - "indexmap", - "log", - "memchr", - "multer", - "num_cpus", - "parking_lot", - "pin-project-lite", - "rand 0.8.5", - "ref-cast", - "rocket_codegen", - "rocket_http", - "serde", - "serde_json", - "state", - "tempfile", - "time 0.3.17", - "tokio", - "tokio-stream", - "tokio-util", - "ubyte", - "version_check", - "yansi", -] - -[[package]] -name = "rocket_codegen" -version = "0.5.0-rc.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6aeb6bb9c61e9cd2c00d70ea267bf36f76a4cc615e5908b349c2f9d93999b47" -dependencies = [ - "devise", - "glob", - "indexmap", - "proc-macro2", - "quote", - "rocket_http", - "syn", - "unicode-xid", -] - -[[package]] -name = "rocket_db_pools" -version = "0.1.0-rc.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bc154f4f4985a136e2d59c336474a56da02103993f5e637e3a5424971ee4eff" -dependencies = [ - "deadpool", - "deadpool-redis", - "rocket", - "rocket_db_pools_codegen", - "version_check", -] - -[[package]] -name = "rocket_db_pools_codegen" -version = "0.1.0-rc.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0aa8f9b37bb1d4827aa5cca400d74e91d30f4352713cb65d6e7427bafe21336c" -dependencies = [ - "devise", - "quote", -] - -[[package]] -name = "rocket_http" -version = "0.5.0-rc.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ded65d127954de3c12471630bf4b81a2792f065984461e65b91d0fdaafc17a2" -dependencies = [ - "cookie", - "either", - "futures", - "http", - "hyper", - "indexmap", - "log", - "memchr", - "pear", - "percent-encoding", - "pin-project-lite", - "ref-cast", - "serde", - "smallvec", - "stable-pattern", - "state", - "time 0.3.17", - "tokio", - "uncased", -] - [[package]] name = "rustversion" version = "1.0.9" @@ -1838,12 +1464,6 @@ dependencies = [ "parking_lot", ] -[[package]] -name = "scoped-tls" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" - [[package]] name = "scopeguard" version = "1.1.0" @@ -1905,12 +1525,20 @@ version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "020ff22c755c2ed3f8cf162dbb41a7268d934702f3ed3631656ea597e08fc3db" dependencies = [ - "indexmap", "itoa", "ryu", "serde", ] +[[package]] +name = "serde_path_to_error" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "184c643044780f7ceb59104cef98a5a6f12cb2288a7bc701ab93a362b49fd47d" +dependencies = [ + "serde", +] + [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -1951,26 +1579,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012" -[[package]] -name = "sha2" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "sharded-slab" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" -dependencies = [ - "lazy_static", -] - [[package]] name = "signal-hook-registry" version = "1.4.0" @@ -1995,15 +1603,6 @@ version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" -[[package]] -name = "smartstring" -version = "0.2.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e714dff2b33f2321fdcd475b71cec79781a692d846f37f415fb395a1d2bcd48e" -dependencies = [ - "static_assertions", -] - [[package]] name = "socket2" version = "0.4.7" @@ -2020,24 +1619,6 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f6002a767bff9e83f8eeecf883ecb8011875a21ae8da43bffb817a57e78cc09" -[[package]] -name = "stable-pattern" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4564168c00635f88eaed410d5efa8131afa8d8699a612c80c455a0ba05c21045" -dependencies = [ - "memchr", -] - -[[package]] -name = "state" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbe866e1e51e8260c9eed836a042a5e7f6726bb2b411dffeaa712e19c388f23b" -dependencies = [ - "loom", -] - [[package]] name = "static_assertions" version = "1.1.0" @@ -2045,10 +1626,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] -name = "subtle" -version = "2.4.1" +name = "strsim" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" @@ -2061,12 +1642,18 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "sync_wrapper" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20518fe4a4c9acf048008599e464deb21beeae3d3578418951a189c235a7a9a8" + [[package]] name = "tasks" version = "0.1.0" dependencies = [ "once_cell", - "redis 0.22.1", + "redis", ] [[package]] @@ -2137,44 +1724,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "time" -version = "0.1.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" -dependencies = [ - "libc", - "wasi 0.10.0+wasi-snapshot-preview1", - "winapi", -] - -[[package]] -name = "time" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a561bf4617eebd33bca6434b988f39ed798e527f51a1e797d0ee4f61c0a38376" -dependencies = [ - "itoa", - "serde", - "time-core", - "time-macros", -] - -[[package]] -name = "time-core" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd" - -[[package]] -name = "time-macros" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d967f99f534ca7e495c575c62638eebc2898a8c84c119b89e250477bc4ba16b2" -dependencies = [ - "time-core", -] - [[package]] name = "tinyvec" version = "1.6.0" @@ -2231,17 +1780,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-stream" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d660770404473ccd7bc9f8b28494a811bc18542b915c0855c51e8f419d5223ce" -dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", -] - [[package]] name = "tokio-tungstenite" version = "0.17.2" @@ -2264,6 +1802,7 @@ checksum = "0bb2e075f03b3d66d8d8785356224ba688d2906a371015e225beeb65ca92c740" dependencies = [ "bytes", "futures-core", + "futures-io", "futures-sink", "pin-project-lite", "tokio", @@ -2279,6 +1818,47 @@ dependencies = [ "serde", ] +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite", + "tokio", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-http" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c530c8675c1dbf98facee631536fa116b5fb6382d7dd6dc1b118d970eafe3ba" +dependencies = [ + "bitflags", + "bytes", + "futures-core", + "futures-util", + "http", + "http-body", + "http-range-header", + "pin-project-lite", + "tower", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" + [[package]] name = "tower-service" version = "0.3.2" @@ -2292,22 +1872,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" dependencies = [ "cfg-if", + "log", "pin-project-lite", - "tracing-attributes", "tracing-core", ] -[[package]] -name = "tracing-attributes" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "tracing-core" version = "0.1.30" @@ -2315,36 +1884,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a" dependencies = [ "once_cell", - "valuable", -] - -[[package]] -name = "tracing-log" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922" -dependencies = [ - "lazy_static", - "log", - "tracing-core", -] - -[[package]] -name = "tracing-subscriber" -version = "0.3.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6176eae26dd70d0c919749377897b54a9276bd7061339665dd68777926b5a70" -dependencies = [ - "matchers", - "nu-ansi-term", - "once_cell", - "regex", - "sharded-slab", - "smallvec", - "thread_local", - "tracing", - "tracing-core", - "tracing-log", ] [[package]] @@ -2366,7 +1905,7 @@ dependencies = [ "httparse", "log", "native-tls", - "rand 0.8.5", + "rand", "sha-1", "thiserror", "url", @@ -2379,31 +1918,12 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" -[[package]] -name = "ubyte" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c81f0dae7d286ad0d9366d7679a77934cfc3cf3a8d67e82669794412b2368fe6" -dependencies = [ - "serde", -] - [[package]] name = "ucd-trie" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81" -[[package]] -name = "uncased" -version = "0.9.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09b01702b0fd0b3fadcf98e098780badda8742d4f4a7676615cad90e8ac73622" -dependencies = [ - "serde", - "version_check", -] - [[package]] name = "unic-char-property" version = "0.9.0" @@ -2481,31 +2001,6 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" -[[package]] -name = "unicode-xid" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" - -[[package]] -name = "universal-hash" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d3160b73c9a19f7e2939a2fdad446c57c1bbbbf4d919d3213ff1267a580d8b5" -dependencies = [ - "crypto-common", - "subtle", -] - -[[package]] -name = "unreachable" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" -dependencies = [ - "void", -] - [[package]] name = "url" version = "2.3.1" @@ -2523,18 +2018,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "uuid" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" - -[[package]] -name = "valuable" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" - [[package]] name = "vcpkg" version = "0.2.15" @@ -2547,12 +2030,6 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" -[[package]] -name = "void" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" - [[package]] name = "walkdir" version = "2.3.2" @@ -2574,18 +2051,6 @@ dependencies = [ "try-lock", ] -[[package]] -name = "wasi" -version = "0.9.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" - -[[package]] -name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -2674,9 +2139,8 @@ version = "0.1.0" dependencies = [ "futures", "futures-util", - "once_cell", - "redis 0.22.1", - "redis_ts", + "lazy_static", + "redis", "serde", "serde_json", "tokio", @@ -2715,19 +2179,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows" -version = "0.32.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbedf6db9096bc2364adce0ae0aa636dcd89f3c3f2cd67947062aaf0ca2a10ec" -dependencies = [ - "windows_aarch64_msvc 0.32.0", - "windows_i686_gnu 0.32.0", - "windows_i686_msvc 0.32.0", - "windows_x86_64_gnu 0.32.0", - "windows_x86_64_msvc 0.32.0", -] - [[package]] name = "windows-sys" version = "0.36.1" @@ -2762,12 +2213,6 @@ version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" -[[package]] -name = "windows_aarch64_msvc" -version = "0.32.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8e92753b1c443191654ec532f14c199742964a061be25d77d7a96f09db20bf5" - [[package]] name = "windows_aarch64_msvc" version = "0.36.1" @@ -2780,12 +2225,6 @@ version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" -[[package]] -name = "windows_i686_gnu" -version = "0.32.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a711c68811799e017b6038e0922cb27a5e2f43a2ddb609fe0b6f3eeda9de615" - [[package]] name = "windows_i686_gnu" version = "0.36.1" @@ -2798,12 +2237,6 @@ version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" -[[package]] -name = "windows_i686_msvc" -version = "0.32.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "146c11bb1a02615db74680b32a68e2d61f553cc24c4eb5b4ca10311740e44172" - [[package]] name = "windows_i686_msvc" version = "0.36.1" @@ -2816,12 +2249,6 @@ version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" -[[package]] -name = "windows_x86_64_gnu" -version = "0.32.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c912b12f7454c6620635bbff3450962753834be2a594819bd5e945af18ec64bc" - [[package]] name = "windows_x86_64_gnu" version = "0.36.1" @@ -2840,12 +2267,6 @@ version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" -[[package]] -name = "windows_x86_64_msvc" -version = "0.32.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "504a2476202769977a040c6364301a3f65d0cc9e3fb08600b2bda150a0488316" - [[package]] name = "windows_x86_64_msvc" version = "0.36.1" @@ -2866,9 +2287,3 @@ checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" dependencies = [ "winapi", ] - -[[package]] -name = "yansi" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" diff --git a/hack/codegen/src/templates/translators.rs.tera b/hack/codegen/src/templates/translators.rs.tera index 9fb44b6..a336dde 100644 --- a/hack/codegen/src/templates/translators.rs.tera +++ b/hack/codegen/src/templates/translators.rs.tera @@ -1,13 +1,17 @@ // GENERATED CODE -- Do not edit. Run `cargo run --bin codegen` to regenerate. -use once_cell::sync::Lazy; +use lazy_static::lazy_static; use std::collections::HashMap; -static VEHICLE_TO_NAME: Lazy> = Lazy::new(|| { - HashMap::from([ +lazy_static! { + static ref VEHICLE_TO_NAME: HashMap<&'static str, &'static str> = HashMap::from([ {% for vehicle in vehicles %}("{{ vehicle.vehicle_id }}", "{{ vehicle.name.en }}"),{% endfor %} - ]) -}); + ]); + + static ref LOADOUT_TO_CLASS: HashMap<&'static str, &'static str> = HashMap::from([ + {% for class in classes %}("{{ class.loadout_id }}", "{{ class.code_name }}"),{% endfor %} + ]); +} pub fn vehicle_to_name(vehicle_id: &str) -> String { match VEHICLE_TO_NAME.get(&vehicle_id) { @@ -16,12 +20,6 @@ pub fn vehicle_to_name(vehicle_id: &str) -> String { } } -static LOADOUT_TO_CLASS: Lazy> = Lazy::new(|| { - HashMap::from([ - {% for class in classes %}("{{ class.loadout_id }}", "{{ class.code_name }}"),{% endfor %} - ]) -}); - pub fn loadout_to_class(loadout_id: &str) -> String { match LOADOUT_TO_CLASS.get(&loadout_id) { Some(name) => name.to_string(), diff --git a/services/api/Cargo.toml b/services/api/Cargo.toml index 5677323..aeb562e 100644 --- a/services/api/Cargo.toml +++ b/services/api/Cargo.toml @@ -6,10 +6,12 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -rocket = { version = "0.5.0-rc.2", features = ["json"] } -rocket_db_pools = { version = "0.1.0-rc.2", features = [ "deadpool_redis" ] } +redis = { version = "0.22.1", features = ["aio", "r2d2", "tokio-comp"] } serde_json = "1.0.88" serde = "1.0.147" -juniper = "0.15.10" -juniper_rocket = "0.8.2" -once_cell = "1.16.0" \ No newline at end of file +async-graphql = { version = "4.0.16", features = ["apollo_tracing"] } +async-graphql-axum = "4.0.16" +axum = "0.6.0" +tokio = { version = "1.22.0", features = ["full"] } +tower-http = { version = "0.3.4", features = ["cors"] } +lazy_static = "1.4.0" \ No newline at end of file diff --git a/services/api/src/classes.rs b/services/api/src/classes.rs new file mode 100644 index 0000000..eded390 --- /dev/null +++ b/services/api/src/classes.rs @@ -0,0 +1,39 @@ +use crate::util::zcount; +use async_graphql::{Context, Object}; +use redis::aio::MultiplexedConnection; + +pub struct Classes { + world_id: String, +} + +impl Classes { + pub fn new(world_id: String) -> Self { + Self { world_id } + } + async fn by_class<'ctx>(&self, ctx: &Context<'ctx>, class_name: &str) -> u32 { + let con = ctx.data::().unwrap().to_owned(); + zcount(con, format!("c:{}/{}", self.world_id, class_name)).await + } +} + +#[Object] +impl Classes { + async fn infiltrator<'ctx>(&self, ctx: &Context<'ctx>) -> u32 { + self.by_class(ctx, "infiltrator").await + } + async fn light_assault<'ctx>(&self, ctx: &Context<'ctx>) -> u32 { + self.by_class(ctx, "light_assault").await + } + async fn combat_medic<'ctx>(&self, ctx: &Context<'ctx>) -> u32 { + self.by_class(ctx, "combat_medic").await + } + async fn engineer<'ctx>(&self, ctx: &Context<'ctx>) -> u32 { + self.by_class(ctx, "engineer").await + } + async fn heavy_assault<'ctx>(&self, ctx: &Context<'ctx>) -> u32 { + self.by_class(ctx, "heavy_assault").await + } + async fn max<'ctx>(&self, ctx: &Context<'ctx>) -> u32 { + self.by_class(ctx, "max").await + } +} diff --git a/services/api/src/cors.rs b/services/api/src/cors.rs deleted file mode 100644 index 9367656..0000000 --- a/services/api/src/cors.rs +++ /dev/null @@ -1,22 +0,0 @@ -use rocket::fairing::{Fairing, Info, Kind}; -use rocket::http::Header; -use rocket::{Request, Response}; - -pub struct CORS; - -#[rocket::async_trait] -impl Fairing for CORS { - fn info(&self) -> Info { - Info { - name: "Add CORS headers to responses", - kind: Kind::Response, - } - } - - async fn on_response<'r>(&self, _request: &'r Request<'_>, response: &mut Response<'r>) { - response.set_header(Header::new("Access-Control-Allow-Origin", "*")); - response.set_header(Header::new("Access-Control-Allow-Methods", "GET, POST")); - response.set_header(Header::new("Access-Control-Allow-Headers", "*")); - response.set_header(Header::new("Access-Control-Allow-Credentials", "false")); - } -} diff --git a/services/api/src/graphql/mod.rs b/services/api/src/graphql/mod.rs deleted file mode 100644 index b068b30..0000000 --- a/services/api/src/graphql/mod.rs +++ /dev/null @@ -1,123 +0,0 @@ -use crate::redispool::RedisPool; - -use self::types::{Health, World}; -use juniper::{graphql_object, FieldResult}; -use rocket::response::content::RawHtml; - -pub mod types; - -pub struct Query; - -#[graphql_object(context = Context)] -impl Query { - fn world(id: String) -> FieldResult { - Ok(World { - world_id: id.clone(), - }) - } - - fn allWorlds() -> FieldResult> { - Ok(vec![ - World { - world_id: "1".to_string(), - }, - World { - world_id: "10".to_string(), - }, - World { - world_id: "13".to_string(), - }, - World { - world_id: "17".to_string(), - }, - World { - world_id: "19".to_string(), - }, - World { - world_id: "40".to_string(), - }, - World { - world_id: "1000".to_string(), - }, - World { - world_id: "2000".to_string(), - }, - ]) - } - - fn worldByName(name: String) -> FieldResult { - let id = match name.to_lowercase().as_str() { - "connery" => "1", - "miller" => "10", - "cobalt" => "13", - "emerald" => "17", - "jaeger" => "19", - "soltech" => "40", - "genudine" => "1000", - "ceres" => "2000", - _ => "-1", - }; - - Ok(World { - world_id: id.to_string(), - }) - } - - fn health() -> FieldResult { - Ok(Health {}) - } -} - -pub struct Context { - con: RedisPool, -} - -impl juniper::Context for Context {} - -#[get("/graphiql")] -pub fn graphiql() -> RawHtml { - juniper_rocket::graphiql_source("/graphql", None) -} - -#[get("/")] -pub fn playground() -> RawHtml { - juniper_rocket::playground_source("/graphql", None) -} - -#[get("/playground")] -pub fn playground2() -> RawHtml { - juniper_rocket::playground_source("/graphql", None) -} - -#[post("/", data = "")] -pub async fn post_graphql( - query: juniper_rocket::GraphQLRequest, - schema: &rocket::State, - con: &RedisPool, -) -> juniper_rocket::GraphQLResponse { - query.execute(&*schema, &Context { con: con.clone() }).await -} - -#[get("/?")] -pub async fn get_graphql( - query: juniper_rocket::GraphQLRequest, - schema: &rocket::State, - con: &RedisPool, -) -> juniper_rocket::GraphQLResponse { - query.execute(&*schema, &Context { con: con.clone() }).await -} - -pub type Schema = juniper::RootNode< - 'static, - Query, - juniper::EmptyMutation, - juniper::EmptySubscription, ->; - -pub fn schema() -> Schema { - Schema::new( - Query, - juniper::EmptyMutation::::new(), - juniper::EmptySubscription::::new(), - ) -} diff --git a/services/api/src/graphql/types.rs b/services/api/src/graphql/types.rs deleted file mode 100644 index dfe85b3..0000000 --- a/services/api/src/graphql/types.rs +++ /dev/null @@ -1,361 +0,0 @@ -use juniper::graphql_object; -use once_cell::sync::Lazy; -use rocket_db_pools::deadpool_redis::redis::cmd; -use std::{ - collections::HashMap, - ops::Sub, - time::{Duration, SystemTime}, -}; - -static WORLD_ID_TO_NAME: Lazy> = Lazy::new(|| { - HashMap::from([ - ("1", "Connery"), - ("10", "Miller"), - ("13", "Cobalt"), - ("17", "Emerald"), - ("19", "Jaeger"), - ("40", "SolTech"), - ("1000", "Genudine"), - ("2000", "Ceres"), - ]) -}); - -#[derive(Clone, Debug)] -pub struct World { - pub world_id: String, -} - -#[graphql_object(context = super::Context)] -impl World { - pub fn id(&self) -> juniper::ID { - juniper::ID::from(self.world_id.clone()) - } - pub fn name(&self) -> String { - WORLD_ID_TO_NAME - .get(&self.world_id.to_string().as_str()) - .unwrap_or(&"Unknown") - .to_string() - } - - pub async fn population(&self, context: &mut super::Context) -> i32 { - let mut con = (*context).con.get().await.unwrap(); - let id = self.world_id.to_string(); - - let filter_timestamp = SystemTime::now() - .sub(Duration::from_secs(60 * 15)) - .duration_since(SystemTime::UNIX_EPOCH) - .unwrap() - .as_secs(); - - let pop: u32 = cmd("ZCOUNT") - .arg(format!("wp:{}", id)) - .arg(filter_timestamp) - .arg("+inf") - .query_async(&mut con) - .await - .unwrap(); - - pop as i32 - } - - pub async fn faction_population(&self) -> FactionPopulation { - FactionPopulation { - world_id: juniper::ID::from(self.world_id.clone()), - } - } - - pub async fn vehicles(&self) -> Vehicles { - Vehicles { - world_id: juniper::ID::from(self.world_id.clone()), - } - } - - pub async fn classes(&self) -> Classes { - Classes { - world_id: juniper::ID::from(self.world_id.clone()), - } - } -} - -pub struct FactionPopulation { - world_id: juniper::ID, -} - -impl FactionPopulation { - async fn by_faction(&self, context: &super::Context, world_id: String, faction: i32) -> i32 { - let mut con = (*context).con.get().await.unwrap(); - - let filter_timestamp = SystemTime::now() - .sub(Duration::from_secs(60 * 15)) - .duration_since(SystemTime::UNIX_EPOCH) - .unwrap() - .as_secs(); - - cmd("ZCOUNT") - .arg(format!("wp:{}/{}", world_id, faction)) - .arg(filter_timestamp) - .arg("+inf") - .query_async(&mut con) - .await - .unwrap() - } -} - -#[graphql_object(context = super::Context)] -#[graphql(description = "The population of each faction on a world")] -impl FactionPopulation { - async fn vs(&self, context: &super::Context) -> i32 { - self.by_faction(context, self.world_id.to_string(), 1).await - } - async fn nc(&self, context: &super::Context) -> i32 { - self.by_faction(context, self.world_id.to_string(), 2).await - } - async fn tr(&self, context: &super::Context) -> i32 { - self.by_faction(context, self.world_id.to_string(), 3).await - } - async fn ns(&self, context: &super::Context) -> i32 { - self.by_faction(context, self.world_id.to_string(), 4).await - } -} - -pub struct Vehicles { - world_id: juniper::ID, -} - -impl Vehicles { - async fn get_vehicle( - &self, - context: &super::Context, - world_id: String, - vehicle_name: &str, - ) -> i32 { - let mut con = (*context).con.get().await.unwrap(); - - let filter_timestamp = SystemTime::now() - .sub(Duration::from_secs(60 * 15)) - .duration_since(SystemTime::UNIX_EPOCH) - .unwrap() - .as_secs(); - - cmd("ZCOUNT") - .arg(format!("v:{}/{}", world_id, vehicle_name)) - .arg(filter_timestamp) - .arg("+inf") - .query_async(&mut con) - .await - .unwrap() - } -} - -#[graphql_object(context = super::Context)] -#[graphql(description = "The count of active vehicles on a world")] -impl Vehicles { - // Transporters - async fn flash(&self, context: &super::Context) -> i32 { - self.get_vehicle(context, self.world_id.to_string(), "flash") - .await - } - async fn sunderer(&self, context: &super::Context) -> i32 { - self.get_vehicle(context, self.world_id.to_string(), "sunderer") - .await - } - async fn ant(&self, context: &super::Context) -> i32 { - self.get_vehicle(context, self.world_id.to_string(), "ant") - .await - } - async fn harasser(&self, context: &super::Context) -> i32 { - self.get_vehicle(context, self.world_id.to_string(), "harasser") - .await - } - async fn javelin(&self, context: &super::Context) -> i32 { - self.get_vehicle(context, self.world_id.to_string(), "javelin") - .await - } - - // Tanks - async fn lightning(&self, context: &super::Context) -> i32 { - self.get_vehicle(context, self.world_id.to_string(), "lightning") - .await - } - async fn prowler(&self, context: &super::Context) -> i32 { - self.get_vehicle(context, self.world_id.to_string(), "prowler") - .await - } - async fn vanguard(&self, context: &super::Context) -> i32 { - self.get_vehicle(context, self.world_id.to_string(), "vanguard") - .await - } - async fn magrider(&self, context: &super::Context) -> i32 { - self.get_vehicle(context, self.world_id.to_string(), "magrider") - .await - } - async fn chimera(&self, context: &super::Context) -> i32 { - self.get_vehicle(context, self.world_id.to_string(), "chimera") - .await - } - - // Air - async fn mosquito(&self, context: &super::Context) -> i32 { - self.get_vehicle(context, self.world_id.to_string(), "mosquito") - .await - } - async fn liberator(&self, context: &super::Context) -> i32 { - self.get_vehicle(context, self.world_id.to_string(), "liberator") - .await - } - async fn galaxy(&self, context: &super::Context) -> i32 { - self.get_vehicle(context, self.world_id.to_string(), "galaxy") - .await - } - async fn valkyrie(&self, context: &super::Context) -> i32 { - self.get_vehicle(context, self.world_id.to_string(), "valkyrie") - .await - } - async fn reaver(&self, context: &super::Context) -> i32 { - self.get_vehicle(context, self.world_id.to_string(), "reaver") - .await - } - async fn scythe(&self, context: &super::Context) -> i32 { - self.get_vehicle(context, self.world_id.to_string(), "scythe") - .await - } - async fn dervish(&self, context: &super::Context) -> i32 { - self.get_vehicle(context, self.world_id.to_string(), "dervish") - .await - } -} - -pub struct Classes { - pub world_id: juniper::ID, -} - -impl Classes { - async fn get_class(&self, context: &super::Context, world_id: String, class_name: &str) -> i32 { - let mut con = (*context).con.get().await.unwrap(); - - let filter_timestamp = SystemTime::now() - .sub(Duration::from_secs(60 * 15)) - .duration_since(SystemTime::UNIX_EPOCH) - .unwrap() - .as_secs(); - - cmd("ZCOUNT") - .arg(format!("c:{}/{}", world_id, class_name)) - .arg(filter_timestamp) - .arg("+inf") - .query_async(&mut con) - .await - .unwrap() - } -} - -#[graphql_object(context = super::Context)] -#[graphql(description = "The count of active classes on a world")] -impl Classes { - async fn infiltrator(&self, context: &super::Context) -> i32 { - self.get_class(context, self.world_id.to_string(), "infiltrator") - .await - } - async fn light_assault(&self, context: &super::Context) -> i32 { - self.get_class(context, self.world_id.to_string(), "light_assault") - .await - } - async fn combat_medic(&self, context: &super::Context) -> i32 { - self.get_class(context, self.world_id.to_string(), "combat_medic") - .await - } - async fn engineer(&self, context: &super::Context) -> i32 { - self.get_class(context, self.world_id.to_string(), "engineer") - .await - } - async fn heavy_assault(&self, context: &super::Context) -> i32 { - self.get_class(context, self.world_id.to_string(), "heavy_assault") - .await - } - async fn max(&self, context: &super::Context) -> i32 { - self.get_class(context, self.world_id.to_string(), "max") - .await - } -} - -#[derive(juniper::GraphQLEnum)] -enum WebsocketState { - #[graphql( - description = "Using Nanite Systems manifold. This is the best possible running state." - )] - Primary, - - #[graphql( - description = "Using backup Daybreak Games manifold. This means the primary socket hasn't recieved events for at least 60 seconds." - )] - Backup, - - #[graphql(description = "Both event processors are down. This is bad.")] - Down, -} - -#[derive(juniper::GraphQLEnum)] -enum UpDown { - #[graphql(description = "Checks have passed.")] - Up, - - #[graphql(description = "Checks have failed. This is bad.")] - Down, -} - -pub struct Health {} - -impl Health { - async fn get_heartbeat(context: &super::Context, pair: &str) -> WebsocketState { - let mut con = (*context).con.get().await.unwrap(); - - let res: Result = cmd("GET") - .arg(format!("heartbeat:{}:primary", pair)) - .query_async(&mut *con) - .await; - match res { - Ok(_) => WebsocketState::Primary, - Err(_) => { - let res: Result = cmd("GET") - .arg(format!("heartbeat:{}:backup", pair)) - .query_async(&mut con) - .await; - match res { - Ok(_) => WebsocketState::Backup, - Err(_) => WebsocketState::Down, - } - } - } - } -} - -#[graphql_object(context = super::Context)] -#[graphql(description = "Saerro's self-checks. Down is universally bad.")] -impl Health { - #[graphql(description = "Checks PC event processors for its running state.")] - async fn pc(context: &super::Context) -> WebsocketState { - Health::get_heartbeat(context, "pc").await - } - - #[graphql(description = "Checks PS4 US event processors for its running state.")] - async fn ps4us(context: &super::Context) -> WebsocketState { - Health::get_heartbeat(context, "ps4us").await - } - - #[graphql(description = "Checks PS4 EU event processors for its running state.")] - async fn ps4eu(context: &super::Context) -> WebsocketState { - Health::get_heartbeat(context, "ps4eu").await - } - - #[graphql(description = "Is our datastore working?")] - async fn redis(context: &super::Context) -> UpDown { - let mut con = (*context).con.get().await.unwrap(); - - let res: Result = cmd("PING").query_async(&mut con).await; - - match res { - Ok(_) => UpDown::Up, - Err(_) => UpDown::Down, - } - } -} diff --git a/services/api/src/health.rs b/services/api/src/health.rs new file mode 100644 index 0000000..718447f --- /dev/null +++ b/services/api/src/health.rs @@ -0,0 +1,74 @@ +use async_graphql::{Enum, Object}; +use axum::{http::StatusCode, response::IntoResponse, Extension, Json}; +use redis::pipe; + +pub async fn get_health( + Extension(mut redis): Extension, +) -> impl IntoResponse { + let (ping, pc, ps4us, ps4eu): (String, bool, bool, bool) = pipe() + .cmd("PING") + .get("heartbeat:pc") + .get("heartbeat:ps4us") + .get("heartbeat:ps4eu") + .query_async(&mut redis) + .await + .unwrap_or_default(); + + if ping != "PONG" { + return ( + StatusCode::SERVICE_UNAVAILABLE, + Json(json!({ + "status": "error", + "message": "Redis is not responding", + })), + ); + } + + ( + StatusCode::OK, + Json(json!({ + "status": if ping == "PONG" && pc && ps4us && ps4eu { "ok" } else { "degraded" }, + "redis": ping == "PONG", + "pc": if pc { "primary" } else { "backup/down" }, + "ps4us": if ps4us { "primary" } else { "backup/down" }, + "ps4eu": if ps4eu { "primary" } else { "backup/down" }, + })), + ) +} + +#[derive(Enum, Copy, Clone, Eq, PartialEq)] +enum UpDown { + Up, + Down, +} + +#[derive(Enum, Copy, Clone, Eq, PartialEq)] +enum WebsocketState { + Primary, + Backup, + Down, +} + +pub struct Health {} + +#[Object] +impl Health { + async fn redis(&self) -> UpDown { + UpDown::Up + } + + #[graphql(name = "pc")] + async fn pc(&self) -> WebsocketState { + WebsocketState::Primary + } + + #[graphql(name = "ps4us")] + async fn ps4us(&self) -> WebsocketState { + WebsocketState::Primary + } + + #[graphql(name = "ps4eu")] + async fn ps4eu(&self) -> WebsocketState { + WebsocketState::Primary + } +} diff --git a/services/api/src/html/404.html b/services/api/src/html/404.html new file mode 100644 index 0000000..3e1f179 --- /dev/null +++ b/services/api/src/html/404.html @@ -0,0 +1,22 @@ + +404 - Saerro Listening Post + + + +

404 Not Found

+

+ [home] [graphql playground] +

diff --git a/services/api/src/main.rs b/services/api/src/main.rs index b18452c..fc1d7fd 100644 --- a/services/api/src/main.rs +++ b/services/api/src/main.rs @@ -1,91 +1,102 @@ -pub mod cors; -pub mod graphql; -pub mod redispool; +mod classes; +mod health; +mod query; +mod util; +mod vehicles; +mod world; -use redispool::RedisPool; -use rocket::fairing::AdHoc; -use rocket::response::content::RawHtml; -use rocket::response::status; -use rocket::{error, Build, Rocket}; -use rocket_db_pools::deadpool_redis::redis::{cmd, pipe}; -use rocket_db_pools::{Connection, Database}; +use async_graphql::{ + extensions::ApolloTracing, + http::{playground_source, GraphQLPlaygroundConfig}, + EmptyMutation, EmptySubscription, Request, Response, Schema, +}; +use axum::{ + extract::Query, + http::Method, + response::{Html, IntoResponse, Redirect}, + routing::{get, post}, + Extension, Json, Router, +}; +use std::net::SocketAddr; +use tower_http::cors::{Any, CorsLayer}; -#[macro_use] -extern crate rocket; #[macro_use] extern crate serde_json; -#[get("/")] -async fn index() -> RawHtml { - RawHtml(include_str!("html/index.html").to_string()) +async fn index() -> Html<&'static str> { + Html(include_str!("html/index.html")) } -#[get("/health")] -async fn health( - mut con: Connection, -) -> Result> { - let (ping, pc, ps4us, ps4eu): (String, bool, bool, bool) = pipe() - .cmd("PING") - .get("heartbeat:pc") - .get("heartbeat:ps4us") - .get("heartbeat:ps4eu") - .query_async(&mut *con) - .await - .unwrap_or_default(); +async fn handle_404() -> Html<&'static str> { + Html(include_str!("html/404.html")) +} - if ping != "PONG" { - return Err(status::Custom( - rocket::http::Status::ServiceUnavailable, - json!({ - "status": "error", - "message": "Redis is not responding", - }), - )); +async fn graphql_handler_post( + Extension(schema): Extension>, + Json(query): Json, +) -> Json { + Json(schema.execute(query).await) +} + +async fn graphql_handler_get( + Extension(schema): Extension>, + query: Query, +) -> axum::response::Response { + match query.operation_name { + Some(_) => Json(schema.execute(query.0).await).into_response(), + None => Redirect::to("/graphql/playground").into_response(), } - - Ok(json!({ - "status": if ping == "PONG" && pc && ps4us && ps4eu { "ok" } else { "degraded" }, - "redis": ping == "PONG", - "pc": if pc { "primary" } else { "backup/down" }, - "ps4us": if ps4us { "primary" } else { "backup/down" }, - "ps4eu": if ps4eu { "primary" } else { "backup/down" }, - })) +} +async fn graphql_playground() -> impl IntoResponse { + Html(playground_source(GraphQLPlaygroundConfig::new("/graphql"))) } -#[launch] -fn rocket() -> Rocket { - let figment = rocket::Config::figment().merge(( - "databases.redis.url", - format!( - "redis://{}:{}", - std::env::var("REDIS_HOST").unwrap_or("localhost".to_string()), - std::env::var("REDIS_PORT").unwrap_or("6379".to_string()), - ), - )); +#[tokio::main] +async fn main() { + let redis_url = format!( + "redis://{}:{}", + std::env::var("REDIS_HOST").unwrap_or("localhost".to_string()), + std::env::var("REDIS_PORT").unwrap_or("6379".to_string()), + ); - rocket::build() - .configure(figment) - .attach(cors::CORS) - .attach(RedisPool::init()) - .attach(AdHoc::on_ignite("Redis Check", |rocket| async move { - if let Some(pool) = RedisPool::fetch(&rocket) { - let mut con = pool.get().await.unwrap(); - let _: () = cmd("PING").query_async(&mut con).await.unwrap(); - } else { - error!("Redis connection failed"); - } - rocket - })) - .manage(graphql::schema()) - .mount("/", routes![index, health,]) - .mount( + let redis = redis::Client::open(redis_url) + .unwrap() + .get_multiplexed_tokio_connection() + .await + .unwrap(); + + let schema = Schema::build(query::Query, EmptyMutation, EmptySubscription) + .data(redis.clone()) + .extension(ApolloTracing) + .finish(); + + let app = Router::new() + .route("/", get(index)) + .route("/health", get(health::get_health)) + .route( "/graphql", - routes![ - graphql::graphiql, - graphql::playground, - graphql::playground2, - graphql::get_graphql, - graphql::post_graphql - ], + post(graphql_handler_post).get(graphql_handler_get), ) + .route("/graphql/playground", get(graphql_playground)) + .fallback(handle_404) + .layer(Extension(redis)) + .layer(Extension(schema)) + .layer(CorsLayer::new().allow_origin(Any).allow_methods([ + Method::GET, + Method::POST, + Method::OPTIONS, + ])); + + let port: u16 = std::env::var("PORT") + .unwrap_or("8000".to_string()) + .parse() + .unwrap(); + let addr = SocketAddr::from(([127, 0, 0, 1], port)); + + println!("Listening on http://{}", addr); + + axum::Server::bind(&addr) + .serve(app.into_make_service()) + .await + .unwrap(); } diff --git a/services/api/src/query.rs b/services/api/src/query.rs new file mode 100644 index 0000000..acb362f --- /dev/null +++ b/services/api/src/query.rs @@ -0,0 +1,24 @@ +use crate::health::Health; +use crate::world::World; +use async_graphql::Object; + +pub struct Query; + +#[Object] +impl Query { + async fn world(&self, id: String) -> World { + World { id: id.clone() } + } + + async fn world_by_name(&self, name: String) -> World { + World::from_name(name) + } + + async fn all_worlds(&self) -> Vec { + World::all_worlds() + } + + async fn health(&self) -> Health { + Health {} + } +} diff --git a/services/api/src/redispool.rs b/services/api/src/redispool.rs deleted file mode 100644 index f2de592..0000000 --- a/services/api/src/redispool.rs +++ /dev/null @@ -1,5 +0,0 @@ -use rocket_db_pools::{deadpool_redis, Database}; - -#[derive(Database, Clone)] -#[database("redis")] -pub struct RedisPool(deadpool_redis::Pool); diff --git a/services/api/src/util.rs b/services/api/src/util.rs new file mode 100644 index 0000000..6de5114 --- /dev/null +++ b/services/api/src/util.rs @@ -0,0 +1,17 @@ +use redis::{aio::MultiplexedConnection, AsyncCommands, FromRedisValue}; +use std::{ + ops::Sub, + time::{Duration, SystemTime}, +}; + +pub async fn zcount(mut con: MultiplexedConnection, key: String) -> RV { + let filter_timestamp = SystemTime::now() + .sub(Duration::from_secs(60 * 15)) + .duration_since(SystemTime::UNIX_EPOCH) + .unwrap() + .as_secs(); + + con.zcount::(key, filter_timestamp, "+inf") + .await + .unwrap() +} diff --git a/services/api/src/vehicles.rs b/services/api/src/vehicles.rs new file mode 100644 index 0000000..c2097f7 --- /dev/null +++ b/services/api/src/vehicles.rs @@ -0,0 +1,76 @@ +use crate::util::zcount; +use async_graphql::{Context, Object}; +use redis::aio::MultiplexedConnection; + +pub struct Vehicles { + world_id: String, +} + +impl Vehicles { + pub fn new(world_id: String) -> Self { + Self { world_id } + } + async fn by_vehicle<'ctx>(&self, ctx: &Context<'ctx>, vehicle_name: &str) -> u32 { + let con = ctx.data::().unwrap().to_owned(); + zcount(con, format!("v:{}/{}", self.world_id, vehicle_name)).await + } +} + +#[Object] +impl Vehicles { + async fn flash<'ctx>(&self, ctx: &Context<'ctx>) -> u32 { + self.by_vehicle(ctx, "flash").await + } + async fn sunderer<'ctx>(&self, ctx: &Context<'ctx>) -> u32 { + self.by_vehicle(ctx, "sunderer").await + } + async fn ant<'ctx>(&self, ctx: &Context<'ctx>) -> u32 { + self.by_vehicle(ctx, "ant").await + } + async fn harasser<'ctx>(&self, ctx: &Context<'ctx>) -> u32 { + self.by_vehicle(ctx, "harasser").await + } + async fn javelin<'ctx>(&self, ctx: &Context<'ctx>) -> u32 { + self.by_vehicle(ctx, "javelin").await + } + + // Tanks + async fn lightning<'ctx>(&self, ctx: &Context<'ctx>) -> u32 { + self.by_vehicle(ctx, "lightning").await + } + async fn prowler<'ctx>(&self, ctx: &Context<'ctx>) -> u32 { + self.by_vehicle(ctx, "prowler").await + } + async fn vanguard<'ctx>(&self, ctx: &Context<'ctx>) -> u32 { + self.by_vehicle(ctx, "vanguard").await + } + async fn magrider<'ctx>(&self, ctx: &Context<'ctx>) -> u32 { + self.by_vehicle(ctx, "magrider").await + } + async fn chimera<'ctx>(&self, ctx: &Context<'ctx>) -> u32 { + self.by_vehicle(ctx, "chimera").await + } + + // Air + async fn mosquito<'ctx>(&self, ctx: &Context<'ctx>) -> u32 { + self.by_vehicle(ctx, "mosquito").await + } + async fn liberator<'ctx>(&self, ctx: &Context<'ctx>) -> u32 { + self.by_vehicle(ctx, "liberator").await + } + async fn galaxy<'ctx>(&self, ctx: &Context<'ctx>) -> u32 { + self.by_vehicle(ctx, "galaxy").await + } + async fn valkyrie<'ctx>(&self, ctx: &Context<'ctx>) -> u32 { + self.by_vehicle(ctx, "valkyrie").await + } + async fn reaver<'ctx>(&self, ctx: &Context<'ctx>) -> u32 { + self.by_vehicle(ctx, "reaver").await + } + async fn scythe<'ctx>(&self, ctx: &Context<'ctx>) -> u32 { + self.by_vehicle(ctx, "scythe").await + } + async fn dervish<'ctx>(&self, ctx: &Context<'ctx>) -> u32 { + self.by_vehicle(ctx, "dervish").await + } +} diff --git a/services/api/src/world.rs b/services/api/src/world.rs new file mode 100644 index 0000000..4881911 --- /dev/null +++ b/services/api/src/world.rs @@ -0,0 +1,112 @@ +use crate::{classes::Classes, util::zcount, vehicles::Vehicles}; +use async_graphql::{Context, Object}; +use lazy_static::lazy_static; +use redis::aio::MultiplexedConnection; +use std::collections::HashMap; + +lazy_static! { + static ref WORLD_NAME_TO_ID: HashMap<&'static str, &'static str> = HashMap::from([ + ("connery", "1"), + ("miller", "10"), + ("cobalt", "13"), + ("emerald", "17"), + ("jaeger", "19"), + ("soltech", "40"), + ("genudine", "1000"), + ("ceres", "2000"), + ]); + static ref WORLD_ID_TO_NAME: HashMap<&'static str, &'static str> = HashMap::from([ + ("1", "Connery"), + ("10", "Miller"), + ("13", "Cobalt"), + ("17", "Emerald"), + ("19", "Jaeger"), + ("40", "SolTech"), + ("1000", "Genudine"), + ("2000", "Ceres"), + ]); +} + +pub struct World { + pub id: String, +} + +impl World { + pub fn from_name(name: String) -> World { + let id = WORLD_NAME_TO_ID + .get(name.to_lowercase().as_str()) + .unwrap_or(&"-1"); + + World { id: id.to_string() } + } + + pub fn all_worlds() -> Vec { + WORLD_ID_TO_NAME + .keys() + .map(|id| World { id: id.to_string() }) + .collect() + } +} + +#[Object] +impl World { + async fn id(&self) -> &str { + &self.id + } + + async fn name(&self) -> String { + WORLD_ID_TO_NAME + .get(self.id.as_str()) + .unwrap_or(&"Unknown") + .to_string() + } + + async fn population<'ctx>(&self, ctx: &Context<'ctx>) -> u32 { + let con = ctx.data::().unwrap().to_owned(); + zcount(con, format!("wp:{}", self.id)).await + } + + async fn faction_population(&self) -> FactionPopulation { + FactionPopulation { + world_id: self.id.clone(), + } + } + + async fn vehicles(&self) -> Vehicles { + Vehicles::new(self.id.clone()) + } + + async fn classes(&self) -> Classes { + Classes::new(self.id.clone()) + } +} + +struct FactionPopulation { + world_id: String, +} + +impl FactionPopulation { + async fn by_faction<'ctx>(&self, ctx: &Context<'ctx>, faction: u8) -> u32 { + let con = ctx.data::().unwrap().to_owned(); + zcount(con, format!("wp:{}/{}", self.world_id, faction)).await + } +} + +#[Object] +impl FactionPopulation { + async fn vs<'ctx>(&self, ctx: &Context<'ctx>) -> u32 { + self.by_faction(ctx, 1).await + } + + async fn nc<'ctx>(&self, ctx: &Context<'ctx>) -> u32 { + self.by_faction(ctx, 2).await + } + + async fn tr<'ctx>(&self, ctx: &Context<'ctx>) -> u32 { + self.by_faction(ctx, 3).await + } + + async fn ns<'ctx>(&self, ctx: &Context<'ctx>) -> u32 { + self.by_faction(ctx, 4).await + } +} diff --git a/services/websocket/Cargo.toml b/services/websocket/Cargo.toml index f49af35..558d5aa 100644 --- a/services/websocket/Cargo.toml +++ b/services/websocket/Cargo.toml @@ -7,8 +7,7 @@ edition = "2021" [dependencies] redis = { version = "0.22.1", default_features = false, features = ["r2d2"] } -redis_ts = "0.4.2" -once_cell = "1.16.0" +lazy_static = "1.4.0" tokio-tungstenite = { version = "0.17.2", features=["native-tls"] } serde_json = "1.0.88" serde = { version = "1.0.147", features = ["derive"] } diff --git a/services/websocket/src/main.rs b/services/websocket/src/main.rs index 1677293..5addee1 100644 --- a/services/websocket/src/main.rs +++ b/services/websocket/src/main.rs @@ -1,6 +1,6 @@ use futures::{pin_mut, FutureExt}; use futures_util::StreamExt; -use once_cell::sync::Lazy; +use lazy_static::lazy_static; use redis::Commands; use serde::Deserialize; use serde_json::json; @@ -9,14 +9,17 @@ use tokio_tungstenite::{connect_async, tungstenite::Message}; mod translators; -pub static REDIS_CLIENT: Lazy = Lazy::new(|| { - redis::Client::open(std::env::var("REDIS_ADDR").unwrap_or("redis://localhost:6379".to_string())) - .unwrap() -}); - -static PAIR: Lazy = Lazy::new(|| env::var("PAIR").unwrap_or_default()); -static ROLE: Lazy = Lazy::new(|| env::var("ROLE").unwrap_or("primary".to_string())); -static WS_ADDR: Lazy = Lazy::new(|| env::var("WS_ADDR").unwrap_or_default()); +lazy_static! { + static ref REDIS_CLIENT: redis::Client = redis::Client::open(format!( + "redis://{}:{}", + std::env::var("REDIS_HOST").unwrap_or("localhost".to_string()), + std::env::var("REDIS_PORT").unwrap_or("6379".to_string()), + )) + .unwrap(); + static ref PAIR: String = env::var("PAIR").unwrap_or_default(); + static ref ROLE: String = env::var("ROLE").unwrap_or("primary".to_string()); + static ref WS_ADDR: String = env::var("WS_ADDR").unwrap_or_default(); +} async fn send_init(tx: futures::channel::mpsc::UnboundedSender) { let worlds_raw = env::var("WORLDS").unwrap_or_default(); diff --git a/services/websocket/src/translators.rs b/services/websocket/src/translators.rs index b77bc0f..9d35799 100644 --- a/services/websocket/src/translators.rs +++ b/services/websocket/src/translators.rs @@ -1,10 +1,10 @@ // GENERATED CODE -- Do not edit. Run `cargo run --bin codegen` to regenerate. -use once_cell::sync::Lazy; +use lazy_static::lazy_static; use std::collections::HashMap; -static VEHICLE_TO_NAME: Lazy> = Lazy::new(|| { - HashMap::from([ +lazy_static! { + static ref VEHICLE_TO_NAME: HashMap<&'static str, &'static str> = HashMap::from([ ("1", "flash"), ("2", "sunderer"), ("3", "lightning"), @@ -48,18 +48,8 @@ static VEHICLE_TO_NAME: Lazy> = Lazy::new(|| { ("2136", "dervish"), ("2137", "chimera"), ("2142", "corsair"), - ]) -}); - -pub fn vehicle_to_name(vehicle_id: &str) -> String { - match VEHICLE_TO_NAME.get(&vehicle_id) { - Some(name) => name.to_string(), - None => "unknown".to_string(), - } -} - -static LOADOUT_TO_CLASS: Lazy> = Lazy::new(|| { - HashMap::from([ + ]); + static ref LOADOUT_TO_CLASS: HashMap<&'static str, &'static str> = HashMap::from([ ("1", "infiltrator"), ("3", "light_assault"), ("4", "combat_medic"), @@ -84,8 +74,15 @@ static LOADOUT_TO_CLASS: Lazy> = Lazy::new(|| { ("31", "engineer"), ("32", "heavy_assault"), ("45", "max"), - ]) -}); + ]); +} + +pub fn vehicle_to_name(vehicle_id: &str) -> String { + match VEHICLE_TO_NAME.get(&vehicle_id) { + Some(name) => name.to_string(), + None => "unknown".to_string(), + } +} pub fn loadout_to_class(loadout_id: &str) -> String { match LOADOUT_TO_CLASS.get(&loadout_id) {