From 2e3f5bbe48b6c2e8d35d762eec67ffccb0b27068 Mon Sep 17 00:00:00 2001 From: Sandipsinh Rathod Date: Wed, 11 Sep 2024 13:38:20 -0400 Subject: [PATCH 01/21] init --- Cargo.lock | 678 ++++++++- Cargo.toml | 2 +- projects/ssddOnTop/Cargo.toml | 33 + projects/ssddOnTop/schema/schema.graphql | 40 + projects/ssddOnTop/src/blueprint/blueprint.rs | 102 ++ projects/ssddOnTop/src/blueprint/mod.rs | 5 + projects/ssddOnTop/src/blueprint/model.rs | 61 + .../ssddOnTop/src/blueprint/wrapping_type.rs | 175 +++ projects/ssddOnTop/src/config/config.rs | 95 ++ projects/ssddOnTop/src/config/kv.rs | 7 + projects/ssddOnTop/src/config/mod.rs | 7 + projects/ssddOnTop/src/config/reader.rs | 34 + projects/ssddOnTop/src/directive.rs | 77 ++ projects/ssddOnTop/src/from_doc.rs | 282 ++++ projects/ssddOnTop/src/hasher.rs | 17 + projects/ssddOnTop/src/helpers/headers.rs | 63 + projects/ssddOnTop/src/helpers/mod.rs | 1 + projects/ssddOnTop/src/http/mod.rs | 2 + projects/ssddOnTop/src/http/req_template.rs | 44 + projects/ssddOnTop/src/ir/discriminator.rs | 1232 +++++++++++++++++ projects/ssddOnTop/src/ir/mod.rs | 5 + projects/ssddOnTop/src/ir/model.rs | 57 + projects/ssddOnTop/src/json/borrow.rs | 125 ++ projects/ssddOnTop/src/json/graphql.rs | 145 ++ projects/ssddOnTop/src/json/json_like.rs | 194 +++ projects/ssddOnTop/src/json/json_like_list.rs | 28 + projects/ssddOnTop/src/json/mod.rs | 56 + projects/ssddOnTop/src/json/serde.rs | 119 ++ projects/ssddOnTop/src/lib.rs | 16 + projects/ssddOnTop/src/main.rs | 11 + projects/ssddOnTop/src/mustache/eval.rs | 274 ++++ projects/ssddOnTop/src/mustache/mod.rs | 3 + projects/ssddOnTop/src/mustache/model.rs | 68 + projects/ssddOnTop/src/mustache/parse.rs | 273 ++++ projects/ssddOnTop/src/path.rs | 523 +++++++ projects/ssddOnTop/src/value/mod.rs | 3 + projects/ssddOnTop/src/value/value.rs | 19 + 37 files changed, 4867 insertions(+), 9 deletions(-) create mode 100644 projects/ssddOnTop/Cargo.toml create mode 100644 projects/ssddOnTop/schema/schema.graphql create mode 100644 projects/ssddOnTop/src/blueprint/blueprint.rs create mode 100644 projects/ssddOnTop/src/blueprint/mod.rs create mode 100644 projects/ssddOnTop/src/blueprint/model.rs create mode 100644 projects/ssddOnTop/src/blueprint/wrapping_type.rs create mode 100644 projects/ssddOnTop/src/config/config.rs create mode 100644 projects/ssddOnTop/src/config/kv.rs create mode 100644 projects/ssddOnTop/src/config/mod.rs create mode 100644 projects/ssddOnTop/src/config/reader.rs create mode 100644 projects/ssddOnTop/src/directive.rs create mode 100644 projects/ssddOnTop/src/from_doc.rs create mode 100644 projects/ssddOnTop/src/hasher.rs create mode 100644 projects/ssddOnTop/src/helpers/headers.rs create mode 100644 projects/ssddOnTop/src/helpers/mod.rs create mode 100644 projects/ssddOnTop/src/http/mod.rs create mode 100644 projects/ssddOnTop/src/http/req_template.rs create mode 100644 projects/ssddOnTop/src/ir/discriminator.rs create mode 100644 projects/ssddOnTop/src/ir/mod.rs create mode 100644 projects/ssddOnTop/src/ir/model.rs create mode 100644 projects/ssddOnTop/src/json/borrow.rs create mode 100644 projects/ssddOnTop/src/json/graphql.rs create mode 100644 projects/ssddOnTop/src/json/json_like.rs create mode 100644 projects/ssddOnTop/src/json/json_like_list.rs create mode 100644 projects/ssddOnTop/src/json/mod.rs create mode 100644 projects/ssddOnTop/src/json/serde.rs create mode 100644 projects/ssddOnTop/src/lib.rs create mode 100644 projects/ssddOnTop/src/main.rs create mode 100644 projects/ssddOnTop/src/mustache/eval.rs create mode 100644 projects/ssddOnTop/src/mustache/mod.rs create mode 100644 projects/ssddOnTop/src/mustache/model.rs create mode 100644 projects/ssddOnTop/src/mustache/parse.rs create mode 100644 projects/ssddOnTop/src/path.rs create mode 100644 projects/ssddOnTop/src/value/mod.rs create mode 100644 projects/ssddOnTop/src/value/value.rs diff --git a/Cargo.lock b/Cargo.lock index 7b17549..84f1131 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,16 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "Inflector" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" +dependencies = [ + "lazy_static", + "regex", +] + [[package]] name = "addr2line" version = "0.22.0" @@ -92,9 +102,112 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.86" +version = "1.0.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10f00e1f6e58a40e807377c75c6a7f97bf9044fab57816f2414e6f5f4499d7b8" + +[[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 = "7.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d37c3e9ba322eb00e9e5e997d58f08e8b6de037325b9367ac59bca8e3cd46af" +dependencies = [ + "async-graphql-derive", + "async-graphql-parser", + "async-graphql-value", + "async-stream", + "async-trait", + "base64", + "bytes", + "fast_chemail", + "fnv", + "futures-timer", + "futures-util", + "handlebars", + "http", + "indexmap", + "mime", + "multer", + "num-traits", + "once_cell", + "pin-project-lite", + "regex", + "serde", + "serde_json", + "serde_urlencoded", + "static_assertions_next", + "tempfile", + "thiserror", +] + +[[package]] +name = "async-graphql-derive" +version = "7.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1141703c11c6ad4fa9b3b0e1e476dea01dbd18a44db00f949b804afaab2f344" +dependencies = [ + "Inflector", + "async-graphql-parser", + "darling", + "proc-macro-crate", + "proc-macro2", + "quote", + "strum", + "syn", + "thiserror", +] + +[[package]] +name = "async-graphql-parser" +version = "7.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f66edcce4c38c18f7eb181fdf561c3d3aa2d644ce7358fc7a928c00a4ffef17" +dependencies = [ + "async-graphql-value", + "pest", + "serde", + "serde_json", +] + +[[package]] +name = "async-graphql-value" +version = "7.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0206011cad065420c27988f17dd7fe201a0e056b20c262209b7bffcd6fa176" +dependencies = [ + "bytes", + "indexmap", + "serde", + "serde_json", +] + +[[package]] +name = "async-stream" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd56dd203fef61ac097dd65721a419ddccb106b2d2b70ba60a6b529f03961a51" +dependencies = [ + "async-stream-impl", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-stream-impl" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" +checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] name = "async-trait" @@ -201,6 +314,15 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + [[package]] name = "bumpalo" version = "3.16.0" @@ -218,6 +340,9 @@ name = "bytes" version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" +dependencies = [ + "serde", +] [[package]] name = "cc" @@ -316,6 +441,21 @@ dependencies = [ "winapi", ] +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + +[[package]] +name = "convert_case" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" +dependencies = [ + "unicode-segmentation", +] + [[package]] name = "core-foundation" version = "0.9.4" @@ -332,12 +472,66 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +[[package]] +name = "cpufeatures" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" +dependencies = [ + "libc", +] + [[package]] name = "crossbeam-utils" version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "darling" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" +dependencies = [ + "darling_core", + "quote", + "syn", +] + [[package]] name = "dashmap" version = "5.5.3" @@ -351,6 +545,48 @@ dependencies = [ "parking_lot_core", ] +[[package]] +name = "derive-getters" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74ef43543e701c01ad77d3a5922755c6a1d71b22d942cb8042be4994b380caff" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "convert_case 0.4.0", + "proc-macro2", + "quote", + "rustc_version", + "syn", +] + +[[package]] +name = "derive_setters" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e8ef033054e131169b8f0f9a7af8f5533a9436fadf3c500ed547f730f07090d" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "diff" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" + [[package]] name = "diff_logger" version = "0.1.0" @@ -362,6 +598,16 @@ dependencies = [ "serde_json", ] +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + [[package]] name = "easy_retry" version = "0.1.0" @@ -372,6 +618,12 @@ dependencies = [ "tokio", ] +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + [[package]] name = "encoding_rs" version = "0.8.34" @@ -381,6 +633,27 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "env_filter" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f2c92ceda6ceec50f43169f9ee8424fe2db276791afde7b2cd8bc084cb376ab" +dependencies = [ + "log", +] + +[[package]] +name = "env_logger" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13fa619b91fb2381732789fc5de83b45675e882f66623b7d8cb4f643017018d" +dependencies = [ + "anstream", + "anstyle", + "env_filter", + "log", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -397,6 +670,15 @@ dependencies = [ "windows-sys 0.52.0", ] +[[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 = "2.1.1" @@ -538,6 +820,25 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + [[package]] name = "getrandom" version = "0.2.15" @@ -611,6 +912,20 @@ dependencies = [ "tracing-subscriber", ] +[[package]] +name = "handlebars" +version = "5.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d08485b96a0e6393e9e4d1b8d48cf74ad6c063cd905eb33f42c1ce3f0377539b" +dependencies = [ + "log", + "pest", + "pest_derive", + "serde", + "serde_json", + "thiserror", +] + [[package]] name = "hashbrown" version = "0.14.5" @@ -731,9 +1046,9 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.7" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cde7055719c54e36e95e8719f95883f22072a48ede39db7fc17a4e1d5281e9b9" +checksum = "da62f120a8a37763efb0cf8fdf264b884c7b8b9ac8660b900c8661030c00e6ba" dependencies = [ "bytes", "futures-channel", @@ -772,6 +1087,12 @@ dependencies = [ "cc", ] +[[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.5.0" @@ -782,6 +1103,12 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "indenter" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" + [[package]] name = "indexmap" version = "2.5.0" @@ -790,6 +1117,7 @@ checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" dependencies = [ "equivalent", "hashbrown", + "serde", ] [[package]] @@ -804,6 +1132,15 @@ version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" +[[package]] +name = "itertools" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.11" @@ -880,6 +1217,12 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "miniz_oxide" version = "0.7.4" @@ -928,6 +1271,23 @@ dependencies = [ "serde_json", ] +[[package]] +name = "multer" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83e87776546dc87511aa5ee218730c92b666d7264ab6ed41f9d215af9cd5224b" +dependencies = [ + "bytes", + "encoding_rs", + "futures-util", + "http", + "httparse", + "memchr", + "mime", + "spin", + "version_check", +] + [[package]] name = "native-tls" version = "0.2.12" @@ -962,6 +1322,16 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b93853da6d84c2e3c7d730d6473e8817692dd89be387eb01b94d7f108ecb5b8c" +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + [[package]] name = "nonempty" version = "0.7.0" @@ -993,6 +1363,16 @@ dependencies = [ "autocfg", ] +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + [[package]] name = "object" version = "0.36.4" @@ -1087,6 +1467,51 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" +[[package]] +name = "pest" +version = "2.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c73c26c01b8c87956cea613c907c9d6ecffd8d18a2a5908e5de0adfaa185cea" +dependencies = [ + "memchr", + "thiserror", + "ucd-trie", +] + +[[package]] +name = "pest_derive" +version = "2.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "664d22978e2815783adbdd2c588b455b1bd625299ce36b2a99881ac9627e6d8d" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2d5487022d5d33f4c30d91c22afa240ce2a644e87fe08caad974d4eab6badbe" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pest_meta" +version = "2.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0091754bbd0ea592c4deb3a122ce8ecbb0753b738aa82bc055fcc2eccc8d8174" +dependencies = [ + "once_cell", + "pest", + "sha2", +] + [[package]] name = "pin-project" version = "1.1.5" @@ -1140,6 +1565,25 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "pretty_assertions" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af7cee1a6c8a5b9208b3cb1061f10c0cb689087b3d8ce85fb9d2dd7a29b6ba66" +dependencies = [ + "diff", + "yansi", +] + +[[package]] +name = "proc-macro-crate" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecf48c7ca261d60b74ab1a7b20da18bede46776b2e55535cb958eb595c5fa7b" +dependencies = [ + "toml_edit", +] + [[package]] name = "proc-macro2" version = "1.0.86" @@ -1149,6 +1593,49 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "prost" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b2ecbe40f08db5c006b5764a2645f7f3f141ce756412ac9e1dd6087e6d32995" +dependencies = [ + "bytes", + "prost-derive", +] + +[[package]] +name = "prost-derive" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acf0c195eebb4af52c752bec4f52f645da98b6e92077a04110c7f349477ae5ac" +dependencies = [ + "anyhow", + "itertools", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "prost-reflect" +version = "0.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b7535b02f0e5efe3e1dbfcb428be152226ed0c66cad9541f2274c8ba8d4cd40" +dependencies = [ + "once_cell", + "prost", + "prost-types", +] + +[[package]] +name = "prost-types" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60caa6738c7369b940c3d49246a8d1749323674c65cb13010134f5c9bad5b519" +dependencies = [ + "prost", +] + [[package]] name = "quanta" version = "0.12.3" @@ -1329,6 +1816,15 @@ version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + [[package]] name = "rustix" version = "0.38.35" @@ -1432,20 +1928,26 @@ dependencies = [ "libc", ] +[[package]] +name = "semver" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" + [[package]] name = "serde" -version = "1.0.209" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.209" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", @@ -1465,6 +1967,16 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_json_borrow" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "176a77dea19cf9b2cfe7f9e31966112ef8282a709af7c0a0fb28fc6347c7ba78" +dependencies = [ + "serde", + "serde_json", +] + [[package]] name = "serde_path_to_error" version = "0.1.16" @@ -1487,6 +1999,17 @@ dependencies = [ "serde", ] +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + [[package]] name = "sharded-slab" version = "0.1.7" @@ -1551,12 +2074,73 @@ dependencies = [ "lock_api", ] +[[package]] +name = "ssddOnTop" +version = "0.1.0" +dependencies = [ + "anyhow", + "async-graphql", + "async-graphql-value", + "bytes", + "convert_case 0.6.0", + "derive-getters", + "derive_more", + "derive_setters", + "fxhash", + "http-body-util", + "hyper", + "hyper-util", + "indenter", + "indexmap", + "nom", + "num_cpus", + "pretty_assertions", + "prost-reflect", + "reqwest", + "serde", + "serde_json", + "serde_json_borrow", + "serde_path_to_error", + "test-log", + "tokio", + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "static_assertions_next" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7beae5182595e9a8b683fa98c4317f956c9a2dec3b9716990d20023cc60c766" + [[package]] name = "strsim" version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" +[[package]] +name = "strum" +version = "0.26.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn", +] + [[package]] name = "subtle" version = "2.6.1" @@ -1623,6 +2207,28 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "test-log" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dffced63c2b5c7be278154d76b479f9f9920ed34e7574201407f0b14e2bbb93" +dependencies = [ + "env_logger", + "test-log-macros", + "tracing-subscriber", +] + +[[package]] +name = "test-log-macros" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5999e24eaa32083191ba4e425deb75cdf25efefabe5aaccb7446dd0d4122a3f5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "thiserror" version = "1.0.63" @@ -1731,6 +2337,23 @@ dependencies = [ "tokio", ] +[[package]] +name = "toml_datetime" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" + +[[package]] +name = "toml_edit" +version = "0.22.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" +dependencies = [ + "indexmap", + "toml_datetime", + "winnow", +] + [[package]] name = "tower" version = "0.4.13" @@ -1843,6 +2466,18 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "ucd-trie" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" + [[package]] name = "unicode-bidi" version = "0.3.15" @@ -1864,6 +2499,12 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "unicode-segmentation" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" + [[package]] name = "untrusted" version = "0.9.0" @@ -1899,6 +2540,12 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + [[package]] name = "want" version = "0.3.1" @@ -2200,6 +2847,21 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "winnow" +version = "0.6.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" +dependencies = [ + "memchr", +] + +[[package]] +name = "yansi" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" + [[package]] name = "zerocopy" version = "0.7.35" diff --git a/Cargo.toml b/Cargo.toml index 233bca0..f178220 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,4 +18,4 @@ tracing = "0.1.40" tracing-subscriber = "0.3.18" [workspace] -members = ["mock-api"] +members = ["mock-api", "projects/ssddOnTop"] diff --git a/projects/ssddOnTop/Cargo.toml b/projects/ssddOnTop/Cargo.toml new file mode 100644 index 0000000..fb8594d --- /dev/null +++ b/projects/ssddOnTop/Cargo.toml @@ -0,0 +1,33 @@ +[package] +name = "ssddOnTop" +version = "0.1.0" +edition = "2021" + +[dependencies] +tokio = {version = "1.40.0", features = ["full"]} +tracing = "0.1.40" +hyper = "1.4.1" +hyper-util = {version = "0.1.8", features = ["tokio"]} +http-body-util = "0.1.2" +bytes = "1.7.1" +anyhow = "1.0.87" +async-graphql = {version = "7.0.9", features = ["dynamic-schema"]} +serde_json = "1.0.127" +serde = { version = "1.0.210", features = ["derive"] } +async-graphql-value = "7.0.9" +serde_path_to_error = "0.1.16" +tracing-subscriber = "0.3.18" +num_cpus = "1.16.0" +reqwest = "0.12.7" +nom = "7.1.3" +pretty_assertions = "1.4.0" +serde_json_borrow = "0.6.0" +derive-getters = "0.5.0" +indexmap = "2.5.0" +derive_more = "0.99.18" +indenter = "0.3.3" +derive_setters = "0.1.6" +test-log = "0.2.16" +convert_case = "0.6.0" +prost-reflect = "0.14.2" +fxhash = "0.2.1" diff --git a/projects/ssddOnTop/schema/schema.graphql b/projects/ssddOnTop/schema/schema.graphql new file mode 100644 index 0000000..7c6b866 --- /dev/null +++ b/projects/ssddOnTop/schema/schema.graphql @@ -0,0 +1,40 @@ +schema +@server(port: 8000) +@upstream(baseURL: "http://localhost:3000") { + query: Query +} + +type Query { + posts: [Post] @http(path: "/posts") + post(id: Int!): Post @http(path: "/posts/{{.args.id}}") + users: [User] @http(path: "/users") + user(id: Int!): User @http(path: "/users/{{.args.id}}") +} + +type Post { + id: Int + userId: Int! + title: String + body: String + user: User @http(path: "/users/{{.value.userId}}") +} + +type User { + id: Int + name: String + username: String + email: String + address: Address + phone: String + website: String +} + +type Address { + zipcode: String + geo: Geo +} + +type Geo { + lat: Float + lng: Float +} diff --git a/projects/ssddOnTop/src/blueprint/blueprint.rs b/projects/ssddOnTop/src/blueprint/blueprint.rs new file mode 100644 index 0000000..cee5b7d --- /dev/null +++ b/projects/ssddOnTop/src/blueprint/blueprint.rs @@ -0,0 +1,102 @@ +use crate::blueprint::model::{Arg, ArgId, Field, FieldId, FieldName, TypeName}; +use crate::config::Config; +use std::collections::HashMap; + + +#[derive(Debug, Eq, Hash, PartialEq)] +pub struct FieldHash { + pub name: FieldName, + pub id: TypeName, +} + +#[derive(Debug)] +pub struct Blueprint { + pub fields: HashMap, + pub server: Server, + pub upstream: Upstream, +} + +#[derive(Debug)] +pub struct Server { + pub port: u16, +} +#[derive(Debug)] +pub struct Upstream { + pub base_url: Option, +} + +impl TryFrom<&Config> for Blueprint { + type Error = anyhow::Error; + + fn try_from(config: &Config) -> Result { + let qry = config.schema.query.as_ref().ok_or(anyhow::anyhow!("Query not found"))?; + let fields = fields_to_map(qry, config); + let server = Server { + port: config.server.port, + }; + let upstream = Upstream { + base_url: config.upstream.base_url.clone(), + }; + Ok(Blueprint { + fields, + server, + upstream, + }) + } +} + +fn fields_to_map(qry: &str, config: &Config) -> HashMap { + let mut fields = HashMap::new(); + populate_nested_field(config, qry, &mut fields); + fields +} + +fn populate_nested_field( + config: &Config, + ty_name: &str, + field_map: &mut HashMap, +) { + // I don't have additional check for scalars as of now.. + // This should work fine + if let Some(ty) = config.types.get(ty_name) { + for (field_name, field) in ty.fields.iter() { + let field_name = FieldName(field_name.clone()); + populate_nested_field(config, field.ty_of.name(), field_map); + let mut arg_id = 0; + let field = Field { + id: FieldId::new(0), + name: field_name.clone(), + type_of: field.ty_of.clone(), + args: field.args.iter().map(|(arg_name, arg)| { + let arg = Arg { + id: ArgId::new(arg_id), + name: arg_name.clone(), + type_of: arg.type_of.clone(), + }; + arg_id += 1; + + arg + }).collect(), + }; + + field_map.insert(FieldHash { + name: field_name, + id: TypeName(ty_name.to_string()), + }, field); + } + } +} + +#[cfg(test)] +mod test { + use crate::config::ConfigReader; + + #[test] + fn test() { + let reader = ConfigReader::init(); + let root = env!("CARGO_MANIFEST_DIR"); + let config = reader.read(format!("{}/schema/schema.graphql",root)).unwrap(); + let blueprint = crate::blueprint::Blueprint::try_from(&config).unwrap(); + println!("{:#?}", blueprint); + } +} \ No newline at end of file diff --git a/projects/ssddOnTop/src/blueprint/mod.rs b/projects/ssddOnTop/src/blueprint/mod.rs new file mode 100644 index 0000000..3b0a863 --- /dev/null +++ b/projects/ssddOnTop/src/blueprint/mod.rs @@ -0,0 +1,5 @@ +pub mod wrapping_type; +mod blueprint; +mod model; + +pub use blueprint::*; \ No newline at end of file diff --git a/projects/ssddOnTop/src/blueprint/model.rs b/projects/ssddOnTop/src/blueprint/model.rs new file mode 100644 index 0000000..76e7cb7 --- /dev/null +++ b/projects/ssddOnTop/src/blueprint/model.rs @@ -0,0 +1,61 @@ +use std::fmt::{Debug, Formatter}; + +#[derive(Clone, Debug, Eq, Hash, PartialEq)] +pub struct FieldName(pub String); + +#[derive(Clone, Debug, Eq, Hash, PartialEq)] +pub struct TypeName(pub String); + +#[derive(Clone)] +pub struct ArgId(usize); + +impl Debug for ArgId { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.0) + } +} + +impl ArgId { + pub fn new(id: usize) -> Self { + ArgId(id) + } +} + +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct FieldId(usize); + +impl Debug for FieldId { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.0) + } +} + +impl FieldId { + pub fn new(id: usize) -> Self { + FieldId(id) + } + pub fn as_usize(&self) -> usize { + self.0 + } +} + +#[derive(Clone, Debug)] +pub struct Arg { + pub id: ArgId, + pub name: String, + pub type_of: crate::blueprint::wrapping_type::Type, +} + +#[derive(Clone, Debug)] +pub struct Nested(Vec); +#[derive(Clone, Debug)] +pub struct Flat(FieldId); + +#[derive(Clone, Debug)] +pub struct Field { + pub id: FieldId, + pub name: FieldName, + pub type_of: crate::blueprint::wrapping_type::Type, + // pub ir: Option, + pub args: Vec, +} \ No newline at end of file diff --git a/projects/ssddOnTop/src/blueprint/wrapping_type.rs b/projects/ssddOnTop/src/blueprint/wrapping_type.rs new file mode 100644 index 0000000..fa693b5 --- /dev/null +++ b/projects/ssddOnTop/src/blueprint/wrapping_type.rs @@ -0,0 +1,175 @@ +use std::fmt::Formatter; +use std::ops::Deref; + +use async_graphql::parser::types as async_graphql_types; +use async_graphql::Name; +use serde::{Deserialize, Serialize}; + +use crate::is_default; + +/// Type to represent GraphQL type usage with modifiers +/// [spec](https://spec.graphql.org/October2021/#sec-Wrapping-Types) +#[derive(Clone, Serialize, Deserialize, PartialEq, Eq)] +#[serde(untagged)] +pub enum Type { + Named { + /// Name of the type + name: String, + /// Flag to indicate the type is required. + #[serde(rename = "required", default, skip_serializing_if = "is_default")] + non_null: bool, + }, + List { + /// Type is a list + #[serde(rename = "list")] + of_type: Box, + /// Flag to indicate the type is required. + #[serde(rename = "required", default, skip_serializing_if = "is_default")] + non_null: bool, + }, +} + +impl std::fmt::Debug for Type { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + match self { + Type::Named { name, non_null } => { + if *non_null { + write!(f, "{}!", name) + } else { + write!(f, "{}", name) + } + } + Type::List { of_type, non_null } => { + if *non_null { + write!(f, "[{:?}]!", of_type) + } else { + write!(f, "[{:?}]", of_type) + } + } + } + } +} + +impl Default for Type { + fn default() -> Self { + Type::Named { name: "JSON".to_string(), non_null: false } + } +} + +impl Type { + /// gets the name of the type + pub fn name(&self) -> &String { + match self { + Type::Named { name, .. } => name, + Type::List { of_type, .. } => of_type.name(), + } + } + + /// checks if the type is nullable + pub fn is_nullable(&self) -> bool { + !match self { + Type::Named { non_null, .. } => *non_null, + Type::List { non_null, .. } => *non_null, + } + } + /// checks if the type is a list + pub fn is_list(&self) -> bool { + matches!(self, Type::List { .. }) + } + + /// convert this type into NonNull type + pub fn into_required(self) -> Self { + match self { + Type::Named { name, .. } => Self::Named { name, non_null: true }, + Type::List { of_type, .. } => Self::List { of_type, non_null: true }, + } + } + + /// convert this into nullable type + pub fn into_nullable(self) -> Self { + match self { + Type::Named { name, .. } => Self::Named { name, non_null: false }, + Type::List { of_type, .. } => Self::List { of_type, non_null: false }, + } + } + + /// create a nullable list type from this type + pub fn into_list(self) -> Self { + Type::List { of_type: Box::new(self), non_null: false } + } + + /// convert this type from list to non-list for any level of nesting + pub fn into_single(self) -> Self { + match self { + Type::Named { .. } => self, + Type::List { of_type, .. } => of_type.into_single(), + } + } + + /// replace the name of the underlying type + pub fn with_name(self, name: String) -> Self { + match self { + Type::Named { non_null, .. } => Type::Named { name, non_null }, + Type::List { of_type, non_null } => { + Type::List { of_type: Box::new(of_type.with_name(name)), non_null } + } + } + } +} + +impl From<&async_graphql_types::Type> for Type { + fn from(value: &async_graphql_types::Type) -> Self { + let non_null = !value.nullable; + + match &value.base { + async_graphql_types::BaseType::Named(name) => { + Self::Named { name: name.to_string(), non_null } + } + async_graphql_types::BaseType::List(type_) => { + Self::List { of_type: Box::new(type_.as_ref().into()), non_null } + } + } + } +} + +impl From<&Type> for async_graphql_types::Type { + fn from(value: &Type) -> Self { + let nullable = value.is_nullable(); + + let base = match value { + Type::Named { name, .. } => async_graphql_types::BaseType::Named(Name::new(name)), + Type::List { of_type, .. } => async_graphql_types::BaseType::List(Box::new( + async_graphql_types::Type::from(of_type.deref()), + )), + }; + + async_graphql_types::Type { base, nullable } + } +} + +impl From<&Type> for async_graphql::dynamic::TypeRef { + fn from(value: &Type) -> Self { + let nullable = value.is_nullable(); + + let base = match value { + Type::Named { name, .. } => { + async_graphql::dynamic::TypeRef::Named(name.to_owned().into()) + } + Type::List { of_type, .. } => async_graphql::dynamic::TypeRef::List(Box::new( + async_graphql::dynamic::TypeRef::from(of_type.deref()), + )), + }; + + if nullable { + base + } else { + async_graphql::dynamic::TypeRef::NonNull(Box::new(base)) + } + } +} + +impl From for Type { + fn from(value: String) -> Self { + Self::Named { name: value, non_null: false } + } +} diff --git a/projects/ssddOnTop/src/config/config.rs b/projects/ssddOnTop/src/config/config.rs new file mode 100644 index 0000000..c8aaacc --- /dev/null +++ b/projects/ssddOnTop/src/config/config.rs @@ -0,0 +1,95 @@ +use crate::blueprint::wrapping_type; +use crate::is_default; +use serde::{Deserialize, Serialize}; +use std::collections::BTreeMap; +use std::num::NonZeroU64; +use derive_setters::Setters; + +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct Config { + pub types: BTreeMap, + pub upstream: Upstream, + pub server: Server, + pub schema: RootSchema, +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct RootSchema { + pub query: Option, + #[serde(default, skip_serializing_if = "is_default")] + pub mutation: Option, + #[serde(default, skip_serializing_if = "is_default")] + pub subscription: Option, +} + + +#[derive(Serialize, Deserialize,Clone, Debug)] +pub struct Server { + #[serde(default, skip_serializing_if = "is_default")] + pub port: u16, +} + +impl Default for Server { + fn default() -> Self { + Server { + port: 8000, + } + } +} + +#[derive(Serialize, Deserialize,Clone, Debug, Default)] +pub struct Upstream { + #[serde(rename = "baseURL", default, skip_serializing_if = "is_default")] + pub base_url: Option, +} + +// TODO: rename +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Default)] +pub struct Type1 { + pub fields: BTreeMap, + pub cache: Option, +} + +impl Type1 { + pub fn fields(mut self, fields: Vec<(&str, Field)>) -> Self { + let mut graphql_fields = BTreeMap::new(); + for (name, field) in fields { + graphql_fields.insert(name.to_string(), field); + } + self.fields = graphql_fields; + self + } + + pub fn scalar(&self) -> bool { + self.fields.is_empty() + } +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] +pub struct Cache { + pub max_age: NonZeroU64, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Default)] +pub struct Field { + pub ty_of: wrapping_type::Type, + pub resolver: Option, + pub args: BTreeMap, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] +pub struct Arg { + pub type_of: wrapping_type::Type, + pub default_value: Option, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] +pub struct Http { + pub path: String, +} + + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] +pub enum Resolver { + Http(Http), +} diff --git a/projects/ssddOnTop/src/config/kv.rs b/projects/ssddOnTop/src/config/kv.rs new file mode 100644 index 0000000..2045635 --- /dev/null +++ b/projects/ssddOnTop/src/config/kv.rs @@ -0,0 +1,7 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize, Clone, Debug, Default, Eq, PartialEq)] +pub struct KeyValue { + pub key: String, + pub value: String, +} \ No newline at end of file diff --git a/projects/ssddOnTop/src/config/mod.rs b/projects/ssddOnTop/src/config/mod.rs new file mode 100644 index 0000000..3aeaacb --- /dev/null +++ b/projects/ssddOnTop/src/config/mod.rs @@ -0,0 +1,7 @@ +mod config; +mod reader; +mod kv; + +pub use config::*; +pub use reader::*; +pub use kv::*; \ No newline at end of file diff --git a/projects/ssddOnTop/src/config/reader.rs b/projects/ssddOnTop/src/config/reader.rs new file mode 100644 index 0000000..4af7cd1 --- /dev/null +++ b/projects/ssddOnTop/src/config/reader.rs @@ -0,0 +1,34 @@ +// Just a reader.. nothing special here + +use crate::config::Config; +use std::path::Path; + +pub struct ConfigReader { + +} + +impl ConfigReader { + pub fn init() -> Self { + Self { + + } + } + pub fn read>(&self, path: T) -> anyhow::Result { + let sdl = std::fs::read_to_string(path)?; + let doc = async_graphql::parser::parse_schema(sdl)?; + Ok(crate::from_doc::from_doc(doc)?) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_read() { + let root = env!("CARGO_MANIFEST_DIR"); + let reader = ConfigReader::init(); + let config = reader.read(format!("{}/schema/schema.graphql",root)).unwrap(); + assert_eq!(config.types.len(), 5); + } +} \ No newline at end of file diff --git a/projects/ssddOnTop/src/directive.rs b/projects/ssddOnTop/src/directive.rs new file mode 100644 index 0000000..2252908 --- /dev/null +++ b/projects/ssddOnTop/src/directive.rs @@ -0,0 +1,77 @@ +use anyhow::Result; +use async_graphql::parser::types::ConstDirective; +use async_graphql::{Name, Pos, Positioned}; +use serde::{Deserialize, Serialize}; +use serde_json::{Map, Value}; +use serde_path_to_error::deserialize; + +fn pos(a: A) -> Positioned { + Positioned::new(a, Pos::default()) +} + +pub trait DirectiveCodec: Sized { + fn directive_name() -> String; + fn from_directive(directive: &ConstDirective) -> Result; + fn to_directive(&self) -> ConstDirective; + fn trace_name() -> String { + format!("@{}", Self::directive_name()) + } + fn from_directives<'a>( + directives: impl Iterator>, + ) -> Result> { + for directive in directives { + if directive.node.name.node == Self::directive_name() { + return Self::from_directive(&directive.node).map(Some); + } + } + Ok(None) + } +} +fn lower_case_first_letter(s: &str) -> String { + if s.len() <= 2 { + s.to_lowercase() + } else if let Some(first_char) = s.chars().next() { + first_char.to_string().to_lowercase() + &s[first_char.len_utf8()..] + } else { + s.to_string() + } +} + +impl<'a, A: Deserialize<'a> + Serialize + 'a> DirectiveCodec for A { + fn directive_name() -> String { + lower_case_first_letter( + std::any::type_name::() + .split("::") + .last() + .unwrap_or_default(), + ) + } + + fn from_directive(directive: &ConstDirective) -> Result { + let mut map = Map::new(); + for (k,v) in directive.arguments.iter() { + let (k,v) = serde_json::to_value(&v.node).map(|v| (k.node.as_str().to_string(), v))?; + map.insert(k,v); + + } + + Ok(deserialize(Value::Object(map))?) + } + + fn to_directive(&self) -> ConstDirective { + let name = Self::directive_name(); + let value = serde_json::to_value(self).unwrap(); + let default_map = &Map::new(); + let map = value.as_object().unwrap_or(default_map); + + let mut arguments = Vec::new(); + for (k, v) in map { + arguments.push(( + pos(Name::new(k.clone())), + pos(serde_json::from_value(v.to_owned()).unwrap()), + )); + } + + ConstDirective { name: pos(Name::new(name)), arguments } + } +} diff --git a/projects/ssddOnTop/src/from_doc.rs b/projects/ssddOnTop/src/from_doc.rs new file mode 100644 index 0000000..d34dac8 --- /dev/null +++ b/projects/ssddOnTop/src/from_doc.rs @@ -0,0 +1,282 @@ +use crate::config::{Arg, Cache, Config, Field, Resolver, RootSchema, Server, Type1, Upstream}; +use crate::directive::DirectiveCodec; +use anyhow::Result; +use async_graphql::parser::types::{ConstDirective, FieldDefinition, InputObjectType, InputValueDefinition, InterfaceType, ObjectType, SchemaDefinition, ServiceDocument, Type, TypeDefinition, TypeKind, TypeSystemDefinition}; +use async_graphql::{Name, Positioned}; +use std::collections::BTreeMap; + +const DEFAULT_SCHEMA_DEFINITION: &SchemaDefinition = &SchemaDefinition { + extend: false, + directives: Vec::new(), + query: None, + mutation: None, + subscription: None, +}; + +pub fn from_doc(doc: ServiceDocument) -> Result { + let type_definitions: Vec<_> = doc + .definitions + .iter() + .filter_map(|def| match def { + TypeSystemDefinition::Type(td) => Some(td), + _ => None, + }) + .collect(); + + let types = to_types(&type_definitions)?; + let sd = schema_definition(&doc)?; + let server = server(sd)?; + let upstream = upstream(sd)?; + let schema = schema_definition(&doc).map(to_root_schema)?; + + + Ok(Config { + types, + upstream, + server, + schema, + }) +} +fn to_root_schema(schema_definition: &SchemaDefinition) -> RootSchema { + let query = schema_definition.query.as_ref().map(pos_name_to_string); + let mutation = schema_definition.mutation.as_ref().map(pos_name_to_string); + let subscription = schema_definition + .subscription + .as_ref() + .map(pos_name_to_string); + + RootSchema { query, mutation, subscription } +} +fn upstream(schema_definition: &SchemaDefinition) -> Result { + process_schema_directives( + schema_definition, + Upstream::directive_name().as_str(), + ) +} + + +fn schema_definition(doc: &ServiceDocument) -> Result<&SchemaDefinition> { + doc.definitions + .iter() + .find_map(|def| match def { + TypeSystemDefinition::Schema(schema_definition) => Some(&schema_definition.node), + _ => None, + }) + .map_or_else(|| Ok(DEFAULT_SCHEMA_DEFINITION), Ok) +} + +fn server(schema_definition: &SchemaDefinition) -> Result { + process_schema_directives(schema_definition, Server::directive_name().as_str()) +} + +fn process_schema_directives( + schema_definition: &SchemaDefinition, + directive_name: &str, +) -> Result { + let mut res = Ok(T::default()); + for directive in schema_definition.directives.iter() { + if directive.node.name.node.as_ref() == directive_name { + res = T::from_directive(&directive.node); + } + } + res +} + + +fn pos_name_to_string(pos: &Positioned) -> String { + pos.node.to_string() +} + +fn to_types( + type_definitions: &Vec<&Positioned>, +) -> Result> { + let mut map = BTreeMap::new(); + for type_definition in type_definitions.iter() { + let type_name = pos_name_to_string(&type_definition.node.name); + let ty = match type_definition.node.kind.clone() { + TypeKind::Object(object_type) => to_object_type( + &object_type, + &type_definition.node.directives, + ), + TypeKind::Interface(interface_type) => to_object_type( + &interface_type, + &type_definition.node.directives, + ), + TypeKind::InputObject(input_object_type) => to_input_object( + input_object_type, + ), + _ => Err(anyhow::anyhow!("Unsupported type kind: {:?}", type_definition.node.kind)), + }?; + + map.insert(type_name, ty); + } + + Ok(map) +} + +fn to_input_object( + input_object_type: InputObjectType, +) -> Result { + let fields = to_input_object_fields(&input_object_type.fields)?; + Ok( + Type1 { fields, ..Default::default() } + ) +} + +fn to_input_object_fields( + input_object_fields: &Vec>, +) -> Result> { + to_fields_inner(input_object_fields, to_input_object_field) +} + +fn to_input_object_field(field_definition: &InputValueDefinition) -> Result { + to_common_field( + field_definition, + BTreeMap::new(), + ) +} + +fn to_object_type( + object: &T, + directives: &[Positioned], +) -> Result +where + T: ObjectLike, +{ + let fields = object.fields(); + + let cache= Cache::from_directives(directives.iter())?; + let fields = to_fields(fields)?; + Ok( + Type1 { fields, cache } + ) +} + +fn to_fields( + fields: &Vec>, +) -> Result> { + to_fields_inner(fields, to_field) +} + +fn to_fields_inner( + fields: &Vec>, + transform: F, +) -> Result> +where + F: Fn(&T) -> Result, + T: HasName, +{ + let mut map = BTreeMap::new(); + for field in fields.iter() { + let field_name = pos_name_to_string(field.node.name()); + let (name, field) = transform(&field.node).map(|field| (field_name, field))?; + map.insert(name, field); + } + + Ok(map) +} + +fn to_field(field_definition: &FieldDefinition) -> Result { + to_common_field(field_definition, to_args(field_definition)) +} + +fn to_common_field( + field: &F, + args: BTreeMap, +) -> Result +where + F: FieldLike + HasName, +{ + let type_of = field.type_of(); + let directives = field.directives(); + + let resolver = Resolver::from_directives(directives.iter())?; + Ok( + Field { + ty_of: type_of.into(), + args, + resolver, + } + ) +} + +fn to_args(field_definition: &FieldDefinition) -> BTreeMap { + let mut args = BTreeMap::new(); + + for arg in field_definition.arguments.iter() { + let arg_name = pos_name_to_string(&arg.node.name); + let arg_val = to_arg(&arg.node); + args.insert(arg_name, arg_val); + } + + args +} + + +fn to_arg(input_value_definition: &InputValueDefinition) -> Arg { + let type_of = &input_value_definition.ty.node; + + let default_value = if let Some(pos) = input_value_definition.default_value.as_ref() { + let value = &pos.node; + serde_json::to_value(value).ok() + } else { + None + }; + Arg { type_of: type_of.into(), default_value } +} + + +trait HasName { + fn name(&self) -> &Positioned; +} +impl HasName for FieldDefinition { + fn name(&self) -> &Positioned { + &self.name + } +} +impl HasName for InputValueDefinition { + fn name(&self) -> &Positioned { + &self.name + } +} + +trait FieldLike { + fn type_of(&self) -> &Type; + fn description(&self) -> &Option>; + fn directives(&self) -> &[Positioned]; +} +impl FieldLike for FieldDefinition { + fn type_of(&self) -> &Type { + &self.ty.node + } + fn description(&self) -> &Option> { + &self.description + } + fn directives(&self) -> &[Positioned] { + &self.directives + } +} +impl FieldLike for InputValueDefinition { + fn type_of(&self) -> &Type { + &self.ty.node + } + fn description(&self) -> &Option> { + &self.description + } + fn directives(&self) -> &[Positioned] { + &self.directives + } +} +trait ObjectLike { + fn fields(&self) -> &Vec>; +} +impl ObjectLike for ObjectType { + fn fields(&self) -> &Vec> { + &self.fields + } +} +impl ObjectLike for InterfaceType { + fn fields(&self) -> &Vec> { + &self.fields + } +} diff --git a/projects/ssddOnTop/src/hasher.rs b/projects/ssddOnTop/src/hasher.rs new file mode 100644 index 0000000..ab4bfa0 --- /dev/null +++ b/projects/ssddOnTop/src/hasher.rs @@ -0,0 +1,17 @@ +use std::hash::Hasher; +use fxhash::FxHasher; + +#[derive(Default)] +pub struct MyHasher { + hasher: FxHasher, +} + +impl Hasher for MyHasher { + fn finish(&self) -> u64 { + self.hasher.finish() + } + + fn write(&mut self, bytes: &[u8]) { + self.hasher.write(bytes) + } +} diff --git a/projects/ssddOnTop/src/helpers/headers.rs b/projects/ssddOnTop/src/helpers/headers.rs new file mode 100644 index 0000000..3940c87 --- /dev/null +++ b/projects/ssddOnTop/src/helpers/headers.rs @@ -0,0 +1,63 @@ +use reqwest::header::HeaderName; +use anyhow::Result; +use crate::config::KeyValue; +use crate::mustache::model::Mustache; + +pub type MustacheHeaders = Vec<(HeaderName, Mustache)>; + + +pub fn to_mustache_headers(headers: &[KeyValue]) -> Result { + let mut ans = vec![]; + for key_value in headers { + let name = HeaderName::from_bytes(key_value.key.as_bytes())?; + let value = Mustache::parse(key_value.value.as_str()); + let header = (name, value); + ans.push(header); + } + Ok(ans) +} + +#[cfg(test)] +mod tests { + use anyhow::Result; + use hyper::header::HeaderName; + use crate::config::KeyValue; + use super::to_mustache_headers; + use crate::mustache::model::Mustache; + + #[test] + fn valid_headers() -> Result<()> { + let input: Vec = serde_json::from_str( + r#"[{"key": "a", "value": "str"}, {"key": "b", "value": "123"}]"#, + )?; + + let headers = to_mustache_headers(&input)?; + + assert_eq!( + headers, + vec![ + (HeaderName::from_bytes(b"a")?, Mustache::parse("str")), + (HeaderName::from_bytes(b"b")?, Mustache::parse("123")) + ] + ); + + Ok(()) + } + + #[test] + fn not_valid_due_to_utf8() { + let input: Vec = + serde_json::from_str(r#"[{"key": "😅", "value": "str"}, {"key": "b", "value": "🦀"}]"#) + .unwrap(); + let error = to_mustache_headers(&input).unwrap_err(); + + // HeaderValue should be parsed just fine despite non-visible ascii symbols + // range see https://github.com/hyperium/http/issues/519 + assert_eq!( + error.to_string(), + r"Validation Error +• invalid HTTP header name [😅] +" + ); + } +} diff --git a/projects/ssddOnTop/src/helpers/mod.rs b/projects/ssddOnTop/src/helpers/mod.rs new file mode 100644 index 0000000..a97581c --- /dev/null +++ b/projects/ssddOnTop/src/helpers/mod.rs @@ -0,0 +1 @@ +pub mod headers; \ No newline at end of file diff --git a/projects/ssddOnTop/src/http/mod.rs b/projects/ssddOnTop/src/http/mod.rs new file mode 100644 index 0000000..3739ead --- /dev/null +++ b/projects/ssddOnTop/src/http/mod.rs @@ -0,0 +1,2 @@ +mod req_template; +pub use req_template::*; \ No newline at end of file diff --git a/projects/ssddOnTop/src/http/req_template.rs b/projects/ssddOnTop/src/http/req_template.rs new file mode 100644 index 0000000..575a18a --- /dev/null +++ b/projects/ssddOnTop/src/http/req_template.rs @@ -0,0 +1,44 @@ +use std::hash::{Hash, Hasher}; +use crate::hasher::MyHasher; +use crate::helpers::headers::MustacheHeaders; +use crate::ir::IoId; +use crate::mustache::model::Mustache; + +#[derive(Debug, Clone)] +pub struct RequestTemplate { + pub root_url: Mustache, + pub query: Vec, + pub method: reqwest::Method, + pub headers: MustacheHeaders, +} + +#[derive(Debug, Clone)] +pub struct Query { + pub key: String, + pub value: Mustache, + pub skip_empty: bool, +} + +/*impl RequestTemplate { + pub fn cache_key(&self, ctx: &EvalContext) -> IoId { + let mut hasher = MyHasher::default(); + let state = &mut hasher; + + self.method.hash(state); + + for (name, mustache) in self.headers.iter() { + name.hash(state); + mustache.render(ctx).hash(state); + } + + for (name, value) in ctx.headers().iter() { + name.hash(state); + value.hash(state); + } + + let url = self.create_url(ctx).unwrap(); + url.hash(state); + + IoId::new(hasher.finish()) + } +}*/ \ No newline at end of file diff --git a/projects/ssddOnTop/src/ir/discriminator.rs b/projects/ssddOnTop/src/ir/discriminator.rs new file mode 100644 index 0000000..c9c47c2 --- /dev/null +++ b/projects/ssddOnTop/src/ir/discriminator.rs @@ -0,0 +1,1232 @@ +use std::collections::HashSet; +use std::fmt::Write; + +use anyhow::{anyhow, bail, Result}; +use async_graphql::Value; +use derive_more::{BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Not}; +use indenter::indented; +use indexmap::IndexMap; + +use crate::config::Type1; +use crate::json::{JsonLike, JsonObjectLike}; + +pub trait TypedValue<'a> { + type Error; + + fn get_type_name(&'a self) -> Option<&'a str>; + fn set_type_name(&'a mut self, type_name: String) -> Result<(), Self::Error>; +} + +const TYPENAME_FIELD: &str = "__typename"; + +impl<'json, T> TypedValue<'json> for T +where + T: JsonLike<'json>, +{ + type Error = anyhow::Error; + + fn get_type_name(&'json self) -> Option<&'json str> { + self.as_object() + .and_then(|obj| obj.get_key(TYPENAME_FIELD)) + .and_then(|val| val.as_str()) + } + + fn set_type_name(&'json mut self, type_name: String) -> Result<(), Self::Error> { + if let Some(obj) = self.as_object_mut() { + obj.insert_key(TYPENAME_FIELD, T::string(type_name.into())); + + Ok(()) + } else { + bail!("Expected object") + } + } +} + +/// Resolver for type member of a union. +/// Based on type definitions and the provided value, it can +/// resolve the type of the value. +/// +/// ## Resolution algorithm +/// +/// The resolution algorithm is based on the following points: +/// - The common set of fields is the set of all fields that are defined in the +/// type members of the union. +/// - If the resolved value is a list, then the resolution should be run for +/// every entry in the list as a separate value. +/// - If a field from the common set is present in the resolved value, then the +/// result type is one of the types that have this field. +/// - If a field from the common set is required in some types and this field is +/// not present in the resolved value, then the result type is not one of +/// those types. +/// - By repeating the checks from above for every field in the common set, we +/// will end up with a smaller set of possible types and, more likely, with +/// only a single possible type. + +#[derive(Clone)] +pub struct Discriminator { + /// List of all types that are members of the Union. + types: Vec, + /// Set of all fields that are part of types with + /// the [FieldInfo] about their relations to types. + fields_info: IndexMap, +} + +impl std::fmt::Debug for Discriminator { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str("Discriminator {\n")?; + f.write_str("types: ")?; + f.write_fmt(format_args!("{:?}\n", &self.types))?; + f.write_str("fields_info:\n")?; + + { + let f = &mut indented(f); + for (field_name, field_info) in &self.fields_info { + f.write_fmt(format_args!("{field_name}:\n"))?; + field_info.display_types(&mut indented(f), &self.types)?; + } + } + + f.write_str("}\n")?; + + Ok(()) + } +} + +/// Represents the relations between a field and a type: +/// - `presented_in` - the field is part of the type definition, regardless of +/// nullability. +/// - `required_in` - the field is part of the type and is non-nullable. +#[derive(Default, Debug, Clone)] +struct FieldInfo { + presented_in: Repr, + required_in: Repr, +} + +impl FieldInfo { + /// Displays the [Repr] data inside FieldInfo as type names instead of the + /// raw underlying representation. + fn display_types(&self, f: &mut dyn Write, types: &[String]) -> std::fmt::Result { + f.write_str("presented_in: ")?; + f.write_fmt(format_args!( + "{:?}\n", + self.presented_in.covered_types(types) + ))?; + f.write_str("required_in: ")?; + f.write_fmt(format_args!( + "{:?}\n", + self.required_in.covered_types(types) + ))?; + + Ok(()) + } +} + +impl Discriminator { + pub fn new(union_name: &str, union_types: &[(&str, &Type1)]) -> Result { + if union_types.len() > usize::BITS as usize { + return Err( + anyhow::anyhow!( + "Union {union_name} defines more than {} types that is not supported", + usize::BITS + ) + ); + } + + let mut types = Vec::with_capacity(union_types.len()); + let mut fields_info: IndexMap = IndexMap::new(); + + // TODO: do we need to check also added_fields? + for (i, (type_name, type_)) in union_types.iter().enumerate() { + types.push(type_name.to_string()); + for (field_name, field) in type_.fields.iter() { + let info = fields_info.entry(field_name.to_string()).or_default(); + + let repr = Repr::from_type_index(i); + + // Add information for this field indicating that it is present in this type. + info.presented_in |= repr; + + // And information if it is required in this type. + if !field.ty_of.is_nullable() { + info.required_in |= repr; + } + } + } + + // Validation to ensure no two types have the same set of fields. + { + let mut duplicates = IndexMap::new(); + + for (_, type_) in union_types.iter() { + let mut repr = Repr::all_covered(union_types.len()); + for field_name in type_.fields.keys() { + if let Some(info) = fields_info.get(field_name.as_str()) { + repr &= info.presented_in; + } + } + + if repr.is_covering_multiple_types() { + let types = repr.covered_types(&types); + + // If every field in this type is also present in some other type, + // check if the other types have the same number of fields. + let same_types: Vec<_> = types + .into_iter() + .filter(|type_name| { + let other_type = union_types.iter().find(|(name, _)| name == type_name); + + if let Some((_, other_type)) = other_type { + other_type.fields.len() == type_.fields.len() + } else { + false + } + }) + .collect(); + + // One type is already the current type itself. + if same_types.len() > 1 { + duplicates.insert(same_types[0], same_types); + } + } + } + + if !duplicates.is_empty() { + return Err(anyhow!("Union have equal types")); + } + } + + // Strip fields that are not valuable for the discriminator. + let fields_info = { + let mut seen_required_in: HashSet = HashSet::new(); + + fields_info + .into_iter() + .filter(|(_, field_info)| { + let drop = + // If a field is present in all types, it does not help in determining the type of the value. + field_info + .presented_in + .is_covering_all_types(union_types.len()) + // If multiple fields are required in the same set of types, we can keep only one of these fields. + || (!field_info.required_in.is_empty() && seen_required_in.contains(&field_info.required_in)); + + seen_required_in.insert(field_info.required_in); + + !drop + }) + .collect() + }; + + let discriminator = Self { fields_info, types }; + + tracing::debug!( + "Generated discriminator for union type '{union_name}':\n{discriminator:?}", + ); + + Ok(discriminator) + } + + pub fn resolve_type(&self, value: &Value) -> Result<&str> { + let Value::Object(obj) = value else { + bail!("Value expected to be object"); + }; + + let mut possible_types = Repr::all_covered(self.types.len()); + + for (field, info) in &self.fields_info { + if obj.contains_key(field.as_str()) { + possible_types &= info.presented_in; + } else { + possible_types &= !info.required_in; + } + + if possible_types.is_empty() { + // No possible types. Something is wrong with the resolved value. + bail!("Failed to find corresponding type for value") + } + + if !possible_types.is_covering_multiple_types() { + // We've got only one possible type, so return it, + // even though the value could be completely wrong if we check other fields. + // We want to cover positive cases and do it as soon as possible, + // and the wrong value will likely be incorrect to use later anyway. + return Ok(possible_types.first_covered_type(&self.types)); + } + } + + // We have multiple possible types. Return the first one + // that is defined earlier in the config. + Ok(possible_types.first_covered_type(&self.types)) + } +} + +/// Representation for a set of types if some condition is met. +/// The condition is represented as a bit inside the `usize` number, +/// where the bit position from the right in the binary representation of +/// `usize` is the index of the type in the set. If the value of the bit is +/// 1, then the condition is met. +#[derive( + Copy, + Clone, + Default, + PartialEq, + Eq, + Hash, + BitAnd, + BitOr, + BitXor, + BitAndAssign, + BitOrAssign, + BitXorAssign, + Not, +)] +struct Repr(usize); + +impl std::fmt::Debug for Repr { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_fmt(format_args!("{:0b}", self.0)) + } +} + +impl Repr { + /// Create a new Repr where the condition is met for every type. + fn all_covered(len: usize) -> Self { + Self((1 << len) - 1) + } + + /// Create a new Repr where the condition is met + /// for the type with the given index. + fn from_type_index(index: usize) -> Self { + Self(1 << index) + } + + /// Search for the first type in the list for which the condition is met. + fn first_covered_type<'types>(&self, types: &'types [String]) -> &'types str { + &types[self.0.trailing_zeros() as usize] + } + + /// Returns a list of all types for which the condition is met. + fn covered_types<'types>(&self, types: &'types [String]) -> Vec<&'types str> { + let mut x = *self; + let mut result = Vec::new(); + + while x.0 != 0 { + result.push(x.first_covered_type(types)); + + x.0 = x.0 & (x.0 - 1); + } + + result + } + + /// Check if the condition is not met for any type. + fn is_empty(&self) -> bool { + self.0 == 0 + } + + /// Check if the condition is met for every type. + fn is_covering_all_types(&self, len: usize) -> bool { + self.0.trailing_ones() == len as u32 + } + + /// Check if the condition is met for more than one type. + fn is_covering_multiple_types(&self) -> bool { + !self.0.is_power_of_two() + } +} + +#[cfg(test)] +mod tests { + use async_graphql::Value; + use serde_json::json; + use test_log::test; + use crate::blueprint::wrapping_type::Type; + use crate::config::Field; + use super::*; + + #[test] + fn test_single_distinct_field_optional() { + let foo = Type1::default().fields(vec![("foo", Field::default())]); + let bar = Type1::default().fields(vec![("bar", Field::default())]); + let types = vec![("Foo", &foo), ("Bar", &bar)]; + + let discriminator = Discriminator::new("Test", &types).unwrap(); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({ "foo": "test" })).unwrap()) + .unwrap(), + "Foo" + ); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({ "bar": "test" })).unwrap()) + .unwrap(), + "Bar" + ); + + // ambiguous cases + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({ "foo": "test", "bar": "test" })).unwrap()) + .unwrap(), + "Foo" + ); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({})).unwrap()) + .unwrap(), + "Foo" + ); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({ "unknown": { "foo": "bar" }})).unwrap()) + .unwrap(), + "Foo" + ); + } + + #[test] + fn test_single_distinct_field_required() { + let foo = Type1::default().fields(vec![( + "foo", + Field { ty_of: Type::default().into_required(), ..Field::default() }, + )]); + let bar = Type1::default().fields(vec![( + "bar", + Field { ty_of: Type::default().into_required(), ..Field::default() }, + )]); + let types = vec![("Foo", &foo), ("Bar", &bar)]; + + let discriminator = Discriminator::new("Test", &types).unwrap(); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({ "foo": "test" })).unwrap()) + .unwrap(), + "Foo" + ); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({ "bar": "test" })).unwrap()) + .unwrap(), + "Bar" + ); + + // ambiguous cases + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({ "foo": "test", "bar": "test" })).unwrap()) + .unwrap(), + "Foo" + ); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({})).unwrap()) + .unwrap(), + "Bar" + ); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({ "unknown": { "foo": "bar" }})).unwrap()) + .unwrap(), + "Bar" + ); + } + + #[test] + fn test_multiple_distinct_field_required() { + let a = Type1::default().fields(vec![ + ( + "a", + Field { ty_of: Type::default().into_required(), ..Field::default() }, + ), + ( + "ab", + Field { ty_of: Type::default().into_required(), ..Field::default() }, + ), + ( + "abab", + Field { ty_of: Type::default().into_required(), ..Field::default() }, + ), + ]); + let b = Type1::default().fields(vec![ + ( + "b", + Field { ty_of: Type::default().into_required(), ..Field::default() }, + ), + ( + "ab", + Field { ty_of: Type::default().into_required(), ..Field::default() }, + ), + ( + "abab", + Field { ty_of: Type::default().into_required(), ..Field::default() }, + ), + ( + "ac", + Field { ty_of: Type::default().into_required(), ..Field::default() }, + ), + ]); + let c = Type1::default().fields(vec![ + ( + "c", + Field { ty_of: Type::default().into_required(), ..Field::default() }, + ), + ( + "ac", + Field { ty_of: Type::default().into_required(), ..Field::default() }, + ), + ]); + let types = vec![("A", &a), ("B", &b), ("C", &c)]; + + let discriminator = Discriminator::new("Test", &types).unwrap(); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({ "a": 1, "ab": 1, "abab": 1 })).unwrap()) + .unwrap(), + "A" + ); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({ "b": 1, "ab": 1, "abab": 1 })).unwrap()) + .unwrap(), + "B" + ); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({ "c": 1, "ac": 1 })).unwrap()) + .unwrap(), + "C" + ); + + // ambiguous cases + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({ "a": 1, "b": 1, "c": 1 })).unwrap()) + .unwrap(), + "A" + ); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({})).unwrap()) + .unwrap(), + "C" + ); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({ "unknown": { "foo": "bar" }})).unwrap()) + .unwrap(), + "C" + ); + } + + #[test] + fn test_single_distinct_field_optional_and_shared_fields() { + let foo = Type1::default().fields(vec![ + ("a", Field::default()), + ("b", Field::default()), + ("foo", Field::default()), + ]); + let bar = Type1::default().fields(vec![ + ("a", Field::default()), + ("b", Field::default()), + ("bar", Field::default()), + ]); + let types = vec![("Foo", &foo), ("Bar", &bar)]; + + let discriminator = Discriminator::new("Test", &types).unwrap(); + + assert_eq!( + discriminator + .resolve_type( + &Value::from_json(json!({ "a": 123, "b": true, "foo": "test" })).unwrap() + ) + .unwrap(), + "Foo" + ); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({ "bar": "test" })).unwrap()) + .unwrap(), + "Bar" + ); + + // ambiguous cases + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({ "foo": "test", "bar": "test" })).unwrap()) + .unwrap(), + "Foo" + ); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({})).unwrap()) + .unwrap(), + "Foo" + ); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({ "unknown": { "foo": "bar" }})).unwrap()) + .unwrap(), + "Foo" + ); + + // ambiguous cases + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({ "foo": "test", "bar": "test" })).unwrap()) + .unwrap(), + "Foo" + ); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({})).unwrap()) + .unwrap(), + "Foo" + ); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({ "unknown": { "foo": "bar" }})).unwrap()) + .unwrap(), + "Foo" + ); + } + + #[test] + fn test_multiple_distinct_fields() { + let foo = Type1::default().fields(vec![ + ("a", Field::default()), + ("b", Field::default()), + ("foo", Field::default()), + ]); + let bar = Type1::default().fields(vec![("bar", Field::default())]); + let types = vec![("Foo", &foo), ("Bar", &bar)]; + + let discriminator = Discriminator::new("Test", &types).unwrap(); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({ "b": 123, "foo": "test" })).unwrap()) + .unwrap(), + "Foo" + ); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({ "bar": "test" })).unwrap()) + .unwrap(), + "Bar" + ); + + assert_eq!( + discriminator + .resolve_type( + &Value::from_json(json!({ "unknown": { "foo": "bar" }, "a": 1 })).unwrap() + ) + .unwrap(), + "Foo" + ); + + // ambiguous cases + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({ "foo": "test", "bar": "test" })).unwrap()) + .unwrap(), + "Foo" + ); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({})).unwrap()) + .unwrap(), + "Foo" + ); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({ "unknown": { "foo": "bar" }})).unwrap()) + .unwrap(), + "Foo" + ); + } + + #[test] + fn test_fields_intersection() { + let a = Type1::default().fields(vec![ + ("shared", Field::default()), + ("a", Field::default()), + ("aa", Field::default()), + ("aaa", Field::default()), + ]); + let b = Type1::default().fields(vec![ + ("shared", Field::default()), + ("b", Field::default()), + ("aa", Field::default()), + ]); + let c = Type1::default().fields(vec![ + ("shared", Field::default()), + ("c", Field::default()), + ("aaa", Field::default()), + ]); + let types = vec![("A", &a), ("B", &b), ("C", &c)]; + + let discriminator = Discriminator::new("Test", &types).unwrap(); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({ "a": 1 })).unwrap()) + .unwrap(), + "A" + ); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({ "b": 1, "aa": 1 })).unwrap()) + .unwrap(), + "B" + ); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({ "c": 1, "aaa": 1 })).unwrap()) + .unwrap(), + "C" + ); + + // ambiguous cases + assert_eq!( + discriminator + .resolve_type( + &Value::from_json(json!({ "shared": 1, "a": 1, "b": 1, "c": 1 })).unwrap() + ) + .unwrap(), + "A" + ); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({})).unwrap()) + .unwrap(), + "A" + ); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({ "unknown": { "foo": "bar" }})).unwrap()) + .unwrap(), + "A" + ); + } + + #[test] + fn test_fields_protobuf_oneof() { + let var_var = Type1::default().fields(vec![("usual", Field::default())]); + let var0_var = Type1::default().fields(vec![ + ("usual", Field::default()), + ( + "payload", + Field { ty_of: Type::default().into_required(), ..Field::default() }, + ), + ]); + let var1_var = Type1::default().fields(vec![ + ("usual", Field::default()), + ( + "command", + Field { ty_of: Type::default().into_required(), ..Field::default() }, + ), + ]); + let var_var0 = Type1::default().fields(vec![ + ("usual", Field::default()), + ( + "flag", + Field { ty_of: Type::default().into_required(), ..Field::default() }, + ), + ]); + let var_var1 = Type1::default().fields(vec![ + ("usual", Field::default()), + ( + "optPayload", + Field { ty_of: Type::default().into_required(), ..Field::default() }, + ), + ]); + let var0_var0 = Type1::default().fields(vec![ + ("usual", Field::default()), + ( + "payload", + Field { ty_of: Type::default().into_required(), ..Field::default() }, + ), + ( + "flag", + Field { ty_of: Type::default().into_required(), ..Field::default() }, + ), + ]); + let var1_var0 = Type1::default().fields(vec![ + ("usual", Field::default()), + ( + "command", + Field { ty_of: Type::default().into_required(), ..Field::default() }, + ), + ( + "flag", + Field { ty_of: Type::default().into_required(), ..Field::default() }, + ), + ]); + let var0_var1 = Type1::default().fields(vec![ + ("usual", Field::default()), + ( + "payload", + Field { ty_of: Type::default().into_required(), ..Field::default() }, + ), + ( + "optPayload", + Field { ty_of: Type::default().into_required(), ..Field::default() }, + ), + ]); + let var1_var1 = Type1::default().fields(vec![ + ("usual", Field::default()), + ( + "command", + Field { ty_of: Type::default().into_required(), ..Field::default() }, + ), + ( + "optPayload", + Field { ty_of: Type::default().into_required(), ..Field::default() }, + ), + ]); + let types = vec![ + ("Var_Var", &var_var), + ("Var0_Var", &var0_var), + ("Var1_Var", &var1_var), + ("Var_Var0", &var_var0), + ("Var_Var1", &var_var1), + ("Var0_Var0", &var0_var0), + ("Var1_Var0", &var1_var0), + ("Var0_Var1", &var0_var1), + ("Var1_Var1", &var1_var1), + ]; + + let discriminator = Discriminator::new("Test", &types).unwrap(); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({ "usual": 1 })).unwrap()) + .unwrap(), + "Var_Var" + ); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({ "usual": 1, "payload": 1 })).unwrap()) + .unwrap(), + "Var0_Var" + ); + + assert_eq!( + discriminator + .resolve_type( + &Value::from_json(json!({ "usual": 1, "command": 2, "useless": 1 })).unwrap() + ) + .unwrap(), + "Var1_Var" + ); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({ "usual": 1, "flag": true })).unwrap()) + .unwrap(), + "Var_Var0" + ); + + assert_eq!( + discriminator + .resolve_type( + &Value::from_json(json!({ "usual": 1, "optPayload": 1, "a": 1, "b": 2 })) + .unwrap() + ) + .unwrap(), + "Var_Var1" + ); + + assert_eq!( + discriminator + .resolve_type( + &Value::from_json(json!({ "usual": 1, "payload": 1, "flag": true })).unwrap() + ) + .unwrap(), + "Var0_Var0" + ); + + assert_eq!( + discriminator + .resolve_type( + &Value::from_json(json!({ "usual": 1, "payload": 1, "optPayload": 1 })) + .unwrap() + ) + .unwrap(), + "Var0_Var1" + ); + + assert_eq!( + discriminator + .resolve_type( + &Value::from_json(json!({ "usual": 1, "command": 1, "flag": true })).unwrap() + ) + .unwrap(), + "Var1_Var0" + ); + + assert_eq!( + discriminator + .resolve_type( + &Value::from_json(json!({ "usual": 1, "command": 1, "optPayload": 1 })) + .unwrap() + ) + .unwrap(), + "Var1_Var1" + ); + + // ambiguous cases + assert_eq!( + discriminator + .resolve_type( + &Value::from_json(json!({ "usual": 1, "command": 1, "payload": 1 })).unwrap() + ) + .unwrap_err() + .to_string(), + "Failed to find corresponding type for value" + ); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({})).unwrap()) + .unwrap(), + "Var_Var" + ); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({ "unknown": { "foo": "bar" }})).unwrap()) + .unwrap(), + "Var_Var" + ); + } + + #[test] + fn test_additional_types() { + let type_a = Type1::default().fields(vec![ + ("uniqueA1", Field::default()), + ("common", Field::default()), + ]); + let type_b = Type1::default().fields(vec![ + ( + "uniqueB1", + Field { ty_of: Type::default().into_required(), ..Field::default() }, + ), + ("common", Field::default()), + ]); + let type_c = Type1::default().fields(vec![ + ("uniqueC1", Field::default()), + ("uniqueC2", Field::default()), + ]); + let type_d = Type1::default().fields(vec![ + ("uniqueD1", Field::default()), + ("common", Field::default()), + ( + "uniqueD2", + Field { ty_of: Type::default().into_required(), ..Field::default() }, + ), + ]); + + let types = vec![ + ("TypeA", &type_a), + ("TypeB", &type_b), + ("TypeC", &type_c), + ("TypeD", &type_d), + ]; + + let discriminator = Discriminator::new("Test", &types).unwrap(); + + assert_eq!( + discriminator + .resolve_type( + &Value::from_json(json!({ "uniqueA1": "value", "common": 1 })).unwrap() + ) + .unwrap(), + "TypeA" + ); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({ "uniqueB1": true, "common": 2 })).unwrap()) + .unwrap(), + "TypeB" + ); + + assert_eq!( + discriminator + .resolve_type( + &Value::from_json(json!({ "uniqueC1": "value1", "uniqueC2": "value2" })) + .unwrap() + ) + .unwrap(), + "TypeC" + ); + + assert_eq!( + discriminator + .resolve_type( + &Value::from_json( + json!({ "uniqueD1": "value", "common": 3, "uniqueD2": false }) + ) + .unwrap() + ) + .unwrap(), + "TypeD" + ); + + // ambiguous cases + assert_eq!( + discriminator + .resolve_type( + &Value::from_json( + json!({ "uniqueA1": "value", "uniqueB1": true, "common": 4 }) + ) + .unwrap() + ) + .unwrap(), + "TypeA" + ); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({})).unwrap()) + .unwrap(), + "TypeA" + ); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({ "unknown": { "foo": "bar" }})).unwrap()) + .unwrap(), + "TypeA" + ); + } + + #[test] + fn test_combination_of_shared_fields() { + let type_a = Type1::default().fields(vec![ + ("field1", Field::default()), + ("field2", Field::default()), + ]); + let type_b = Type1::default().fields(vec![ + ("field2", Field::default()), + ("field3", Field::default()), + ]); + let type_c = Type1::default().fields(vec![ + ("field1", Field::default()), + ("field3", Field::default()), + ]); + let type_d = Type1::default().fields(vec![ + ("field1", Field::default()), + ("field2", Field::default()), + ( + "field4", + Field { ty_of: Type::default().into_required(), ..Field::default() }, + ), + ]); + + let types = vec![ + ("TypeA", &type_a), + ("TypeB", &type_b), + ("TypeC", &type_c), + ("TypeD", &type_d), + ]; + + let discriminator = Discriminator::new("Test", &types).unwrap(); + + assert_eq!( + discriminator + .resolve_type( + &Value::from_json(json!({ "field1": "value", "field2": "value" })).unwrap() + ) + .unwrap(), + "TypeA" + ); + + assert_eq!( + discriminator + .resolve_type( + &Value::from_json(json!({ "field2": "value", "field3": "value" })).unwrap() + ) + .unwrap(), + "TypeB" + ); + + assert_eq!( + discriminator + .resolve_type( + &Value::from_json(json!({ "field1": "value", "field3": "value" })).unwrap() + ) + .unwrap(), + "TypeC" + ); + + assert_eq!( + discriminator + .resolve_type( + &Value::from_json( + json!({ "field1": "value", "field2": "value", "field4": "value" }) + ) + .unwrap() + ) + .unwrap(), + "TypeD" + ); + + // ambiguous cases + assert_eq!( + discriminator + .resolve_type( + &Value::from_json( + json!({ "field1": "value", "field2": "value", "field3": "value" }) + ) + .unwrap() + ) + .unwrap_err() + .to_string(), + "Failed to find corresponding type for value" + ); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({})).unwrap()) + .unwrap(), + "TypeA" + ); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!({ "unknown": { "foo": "bar" }})).unwrap()) + .unwrap(), + "TypeA" + ); + } + + #[test] + fn validation_number_of_types() { + let types: Vec<_> = (0..136) + .map(|i| (i.to_string(), Type1::default())) + .collect(); + let union_types: Vec<_> = types + .iter() + .map(|(name, type_)| (name.as_str(), type_)) + .collect(); + + assert_eq!( + Discriminator::new("BigUnion", &union_types) + + .unwrap_err() + .to_string(), + format!( + "Validation Error +• Union BigUnion defines more than {} types that is not supported +", + usize::BITS + ) + ); + } + + #[test] + fn test_validation_equal_types() { + let a = + Type1::default().fields(vec![("a", Field::default()), ("b", Field::default())]); + let b = Type1::default().fields(vec![ + ( + "a", + Field { ty_of: Type::default().into_required(), ..Field::default() }, + ), + ("b", Field::default()), + ]); + let c = + Type1::default().fields(vec![("a", Field::default()), ("b", Field::default())]); + let d = Type1::default().fields(vec![ + ("a", Field::default()), + ("b", Field::default()), + ( + "c", + Field { ty_of: Type::default().into_required(), ..Field::default() }, + ), + ]); + let e = + Type1::default().fields(vec![("c", Field::default()), ("d", Field::default())]); + let f = Type1::default().fields(vec![ + ("c", Field::default()), + ( + "d", + Field { ty_of: Type::default().into_required(), ..Field::default() }, + ), + ]); + + let types = vec![ + ("A", &a), + ("B", &b), + ("C", &c), + ("D", &d), + ("E", &e), + ("F", &f), + ]; + + assert_eq!( + Discriminator::new("Test", &types) + + .unwrap_err() + .to_string(), + "Validation Error +• Union have equal types: A == B == C [Test] +• Union have equal types: E == F [Test] +" + ); + } + + #[test] + fn test_validation_non_object() { + let foo = Type1::default().fields(vec![("foo", Field::default())]); + let bar = Type1::default().fields(vec![("bar", Field::default())]); + let types = vec![("Foo", &foo), ("Bar", &bar)]; + + let discriminator = Discriminator::new("Test", &types).unwrap(); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!("string")).unwrap()) + .unwrap_err() + .to_string(), + "Value expected to be object" + ); + + assert_eq!( + discriminator + .resolve_type(&Value::from_json(json!(25)).unwrap()) + .unwrap_err() + .to_string(), + "Value expected to be object" + ); + } +} diff --git a/projects/ssddOnTop/src/ir/mod.rs b/projects/ssddOnTop/src/ir/mod.rs new file mode 100644 index 0000000..f25bd69 --- /dev/null +++ b/projects/ssddOnTop/src/ir/mod.rs @@ -0,0 +1,5 @@ +mod model; +mod discriminator; + +pub use model::*; +pub use discriminator::*; diff --git a/projects/ssddOnTop/src/ir/model.rs b/projects/ssddOnTop/src/ir/model.rs new file mode 100644 index 0000000..bfa15da --- /dev/null +++ b/projects/ssddOnTop/src/ir/model.rs @@ -0,0 +1,57 @@ +use std::num::NonZeroU64; +use crate::http; +// use crate::jit::eval_ctx::EvalContext; + +#[derive(Clone, Debug)] +pub enum IR { + IO(IO), + Cache(Cache), +} + +#[derive(Clone, Debug)] +pub struct Cache { + pub max_age: NonZeroU64, + pub io: IO, +} + +#[derive(Clone, Copy, Debug)] +pub struct DataLoaderId(usize); + +impl DataLoaderId { + pub fn new(id: usize) -> Self { + Self(id) + } + + pub fn as_usize(&self) -> usize { + self.0 + } +} + +#[derive(PartialEq, Eq, Clone, Hash, Debug)] +pub struct IoId(u64); + +impl IoId { + pub fn new(id: u64) -> Self { + Self(id) + } + + pub fn as_u64(&self) -> u64 { + self.0 + } +} + +#[derive(Clone, Debug)] +pub enum IO { + Http { + req_template: http::RequestTemplate, + dl_id: Option, + } +} + +/*impl<'a> IO { + fn cache_key(&self, ctx: &EvalContext<'a>) -> IoId { + match self { + IO::Http { req_template, .. } => req_template.cache_key(ctx), + } + } +}*/ \ No newline at end of file diff --git a/projects/ssddOnTop/src/json/borrow.rs b/projects/ssddOnTop/src/json/borrow.rs new file mode 100644 index 0000000..1a38196 --- /dev/null +++ b/projects/ssddOnTop/src/json/borrow.rs @@ -0,0 +1,125 @@ +use std::borrow::Cow; + +use serde_json_borrow::{ObjectAsVec, Value}; + +use super::{gather_path_matches, group_by_key, JsonLike, JsonObjectLike}; + +// BorrowedValue +impl<'ctx> JsonObjectLike<'ctx> for ObjectAsVec<'ctx> { + type Value = Value<'ctx>; + + fn new() -> Self { + ObjectAsVec::default() + } + + fn get_key(&self, key: &str) -> Option<&Self::Value> { + self.get(key) + } + + fn insert_key(&mut self, key: &'ctx str, value: Self::Value) { + self.insert(key, value); + } +} + +impl<'ctx> JsonLike<'ctx> for Value<'ctx> { + type JsonObject = ObjectAsVec<'ctx>; + + fn null() -> Self { + Value::Null + } + + fn object(obj: Self::JsonObject) -> Self { + Value::Object(obj) + } + + fn array(arr: Vec) -> Self { + Value::Array(arr) + } + + fn string(s: Cow<'ctx, str>) -> Self { + Value::Str(s) + } + + fn as_array(&self) -> Option<&Vec> { + match self { + Value::Array(array) => Some(array), + _ => None, + } + } + + fn into_array(self) -> Option> { + match self { + Value::Array(array) => Some(array), + _ => None, + } + } + + fn as_object(&self) -> Option<&Self::JsonObject> { + self.as_object() + } + + fn as_object_mut(&mut self) -> Option<&mut Self::JsonObject> { + match self { + Value::Object(obj) => Some(obj), + _ => None, + } + } + + fn into_object(self) -> Option { + match self { + Value::Object(obj) => Some(obj), + _ => None, + } + } + + fn as_str(&self) -> Option<&str> { + self.as_str() + } + + fn as_i64(&self) -> Option { + self.as_i64() + } + + fn as_u64(&self) -> Option { + self.as_u64() + } + + fn as_f64(&self) -> Option { + self.as_f64() + } + + fn as_bool(&self) -> Option { + self.as_bool() + } + + fn is_null(&self) -> bool { + self.is_null() + } + + fn get_path>(&'ctx self, path: &[T]) -> Option<&Self> { + let mut val = self; + for token in path { + val = match val { + Value::Array(arr) => { + let index = token.as_ref().parse::().ok()?; + arr.get(index)? + } + Value::Object(map) => map.get(token.as_ref())?, + _ => return None, + }; + } + Some(val) + } + + fn get_key(&'ctx self, path: &str) -> Option<&Self> { + match self { + Value::Object(map) => map.get(path), + _ => None, + } + } + + fn group_by(&'ctx self, path: &[String]) -> std::collections::HashMap> { + let src = gather_path_matches(self, path, vec![]); + group_by_key(src) + } +} diff --git a/projects/ssddOnTop/src/json/graphql.rs b/projects/ssddOnTop/src/json/graphql.rs new file mode 100644 index 0000000..aa049a8 --- /dev/null +++ b/projects/ssddOnTop/src/json/graphql.rs @@ -0,0 +1,145 @@ +use std::borrow::Cow; +use std::collections::HashMap; + +use async_graphql::Name; +use async_graphql_value::ConstValue; +use indexmap::IndexMap; + +use super::*; + +impl<'obj, Value: JsonLike<'obj> + Clone> JsonObjectLike<'obj> for IndexMap { + type Value = Value; + + fn new() -> Self { + IndexMap::new() + } + + fn get_key(&self, key: &str) -> Option<&Self::Value> { + self.get(key) + } + + fn insert_key(&mut self, key: &'obj str, value: Self::Value) { + self.insert(Name::new(key), value); + } +} + +impl<'json> JsonLike<'json> for ConstValue { + type JsonObject = IndexMap; + + fn as_array(&self) -> Option<&Vec> { + match self { + ConstValue::List(seq) => Some(seq), + _ => None, + } + } + + fn into_array(self) -> Option> { + match self { + ConstValue::List(seq) => Some(seq), + _ => None, + } + } + + fn as_str(&self) -> Option<&str> { + match self { + ConstValue::String(s) => Some(s), + _ => None, + } + } + + fn as_i64(&self) -> Option { + match self { + ConstValue::Number(n) => n.as_i64(), + _ => None, + } + } + + fn as_u64(&self) -> Option { + match self { + ConstValue::Number(n) => n.as_u64(), + _ => None, + } + } + + fn as_f64(&self) -> Option { + match self { + ConstValue::Number(n) => n.as_f64(), + _ => None, + } + } + + fn as_bool(&self) -> Option { + match self { + ConstValue::Boolean(b) => Some(*b), + _ => None, + } + } + + fn is_null(&self) -> bool { + matches!(self, ConstValue::Null) + } + + fn get_path>(&self, path: &[T]) -> Option<&Self> { + let mut val = self; + for token in path { + val = match val { + ConstValue::List(seq) => { + let index = token.as_ref().parse::().ok()?; + seq.get(index)? + } + ConstValue::Object(map) => map.get(token.as_ref())?, + _ => return None, + }; + } + Some(val) + } + + fn get_key(&self, path: &str) -> Option<&Self> { + match self { + ConstValue::Object(map) => map.get(&async_graphql::Name::new(path)), + _ => None, + } + } + + fn group_by(&self, path: &[String]) -> HashMap> { + let src = gather_path_matches(self, path, vec![]); + group_by_key(src) + } + + fn null() -> Self { + Default::default() + } + + fn as_object(&self) -> Option<&Self::JsonObject> { + match self { + ConstValue::Object(map) => Some(map), + _ => None, + } + } + + fn as_object_mut(&mut self) -> Option<&mut Self::JsonObject> { + match self { + ConstValue::Object(map) => Some(map), + _ => None, + } + } + + fn into_object(self) -> Option { + match self { + ConstValue::Object(map) => Some(map), + _ => None, + } + } + + fn object(obj: Self::JsonObject) -> Self { + ConstValue::Object(obj) + } + + fn array(arr: Vec) -> Self { + ConstValue::List(arr) + } + + fn string(s: Cow<'json, str>) -> Self { + ConstValue::String(s.to_string()) + } +} diff --git a/projects/ssddOnTop/src/json/json_like.rs b/projects/ssddOnTop/src/json/json_like.rs new file mode 100644 index 0000000..d46f6fe --- /dev/null +++ b/projects/ssddOnTop/src/json/json_like.rs @@ -0,0 +1,194 @@ +use std::borrow::Cow; +use std::collections::HashMap; + +pub trait JsonLikeOwned: for<'json> JsonLike<'json> {} +impl JsonLikeOwned for T where T: for<'json> JsonLike<'json> {} + +/// A trait for objects that can be used as JSON values +pub trait JsonLike<'json>: Sized { + type JsonObject: JsonObjectLike<'json, Value = Self>; + + // Constructors + fn null() -> Self; + fn object(obj: Self::JsonObject) -> Self; + fn array(arr: Vec) -> Self; + fn string(s: Cow<'json, str>) -> Self; + + // Operators + fn as_array(&self) -> Option<&Vec>; + fn into_array(self) -> Option>; + fn as_object(&self) -> Option<&Self::JsonObject>; + fn as_object_mut(&mut self) -> Option<&mut Self::JsonObject>; + fn into_object(self) -> Option; + fn as_str(&self) -> Option<&str>; + fn as_i64(&self) -> Option; + fn as_u64(&self) -> Option; + fn as_f64(&self) -> Option; + fn as_bool(&self) -> Option; + fn is_null(&self) -> bool; + fn get_path>(&'json self, path: &[T]) -> Option<&Self>; + fn get_key(&'json self, path: &str) -> Option<&Self>; + fn group_by(&'json self, path: &[String]) -> HashMap>; +} + +/// A trait for objects that can be used as JSON objects +pub trait JsonObjectLike<'obj>: Sized { + type Value; + fn new() -> Self; + fn get_key(&self, key: &str) -> Option<&Self::Value>; + fn insert_key(&mut self, key: &'obj str, value: Self::Value); +} + +#[cfg(test)] +mod tests { + use pretty_assertions::assert_eq; + use serde_json::json; + + use super::super::gather_path_matches; + use super::{JsonLike, JsonObjectLike}; + use crate::json::group_by_key; + + // for lifetime testing purposes + #[allow(dead_code)] + fn create_json_like<'a, Value: JsonLike<'a>>() -> Value { + unimplemented!("fake test fn") + } + + // for lifetime testing purposes + #[allow(dead_code)] + fn test_json_like_lifetime<'a, Value: JsonLike<'a> + Clone>() -> Value { + let value: Value = create_json_like(); + + if value.is_null() { + return Value::null(); + } + + if value.as_bool().is_some() { + println!("bool"); + } + + if value.as_f64().is_some() { + println!("f64"); + } + + if let Some(s) = value.as_str() { + return Value::string(s.to_string().into()); + } + + if let Some(arr) = value.as_array() { + return Value::array(arr.clone()); + } + + if value.as_object().is_some() { + return Value::object(Value::JsonObject::new()); + } + + value + } + + #[test] + fn test_gather_path_matches() { + let input = json!([ + {"id": "1"}, + {"id": "2"}, + {"id": "3"} + ]); + + let actual = + serde_json::to_value(gather_path_matches(&input, &["id".into()], vec![])).unwrap(); + + let expected = json!( + [ + ["1", {"id": "1"}], + ["2", {"id": "2"}], + ["3", {"id": "3"}], + ] + ); + + assert_eq!(actual, expected) + } + + #[test] + fn test_gather_path_matches_nested() { + let input = json!({ + "data": [ + {"user": {"id": "1"}}, + {"user": {"id": "2"}}, + {"user": {"id": "3"}}, + {"user": [ + {"id": "4"}, + {"id": "5"} + ] + }, + ] + }); + + let actual = serde_json::to_value(gather_path_matches( + &input, + &["data".into(), "user".into(), "id".into()], + vec![], + )) + .unwrap(); + + let expected = json!( + [ + ["1", {"id": "1"}], + ["2", {"id": "2"}], + ["3", {"id": "3"}], + ["4", {"id": "4"}], + ["5", {"id": "5"}], + + ] + ); + + assert_eq!(actual, expected) + } + + #[test] + fn test_group_by_key() { + let arr = vec![ + (json!("1"), json!({"id": "1"})), + (json!("2"), json!({"id": "2"})), + (json!("2"), json!({"id": "2"})), + (json!("3"), json!({"id": "3"})), + ]; + let input: Vec<(&serde_json::Value, &serde_json::Value)> = + arr.iter().map(|a| (&a.0, &a.1)).collect(); + + let actual = serde_json::to_value(group_by_key(input)).unwrap(); + + let expected = json!( + { + "1": [{"id": "1"}], + "2": [{"id": "2"}, {"id": "2"}], + "3": [{"id": "3"}], + } + ); + + assert_eq!(actual, expected) + } + + #[test] + fn test_group_by_numeric_key() { + let arr = vec![ + (json!(1), json!({"id": 1})), + (json!(2), json!({"id": 2})), + (json!(2), json!({"id": 2})), + (json!(3), json!({"id": 3})), + ]; + let input: Vec<(&serde_json::Value, &serde_json::Value)> = + arr.iter().map(|a| (&a.0, &a.1)).collect(); + + let actual = serde_json::to_value(group_by_key(input)).unwrap(); + + let expected = json!( + { + "1": [{"id": 1}], + "2": [{"id": 2}, {"id": 2}], + "3": [{"id": 3}], + } + ); + + assert_eq!(actual, expected) + } +} diff --git a/projects/ssddOnTop/src/json/json_like_list.rs b/projects/ssddOnTop/src/json/json_like_list.rs new file mode 100644 index 0000000..6743b38 --- /dev/null +++ b/projects/ssddOnTop/src/json/json_like_list.rs @@ -0,0 +1,28 @@ +use super::JsonLike; + +pub trait JsonLikeList<'json>: JsonLike<'json> { + fn map(self, mut mapper: impl FnMut(Self) -> Result) -> Result { + if self.as_array().is_some() { + let new = self + .into_array() + .unwrap() + .into_iter() + .map(mapper) + .collect::>()?; + + Ok(Self::array(new)) + } else { + mapper(self) + } + } + + fn try_for_each(&self, mut f: impl FnMut(&Self) -> Result<(), Err>) -> Result<(), Err> { + if let Some(arr) = self.as_array() { + arr.iter().try_for_each(f) + } else { + f(self) + } + } +} + +impl<'json, T: JsonLike<'json>> JsonLikeList<'json> for T {} diff --git a/projects/ssddOnTop/src/json/mod.rs b/projects/ssddOnTop/src/json/mod.rs new file mode 100644 index 0000000..076813b --- /dev/null +++ b/projects/ssddOnTop/src/json/mod.rs @@ -0,0 +1,56 @@ +mod borrow; +mod graphql; +mod json_like; +mod json_like_list; +mod serde; + +use std::collections::HashMap; + +pub use json_like::*; +pub use json_like_list::*; + +// Highly micro-optimized and benchmarked version of get_path_all +// Any further changes should be verified with benchmarks +pub fn gather_path_matches<'json, J: JsonLike<'json>>( + root: &'json J, + path: &[String], + mut vector: Vec<(&'json J, &'json J)>, +) -> Vec<(&'json J, &'json J)> { + if let Some(root) = root.as_array() { + for value in root.iter() { + vector = gather_path_matches(value, path, vector); + } + } else if let Some((key, tail)) = path.split_first() { + if let Some(value) = root.get_key(key) { + if tail.is_empty() { + vector.push((value, root)); + } else { + vector = gather_path_matches(value, tail, vector); + } + } + } + + vector +} + +fn group_by_key<'json, J: JsonLike<'json>>( + src: Vec<(&'json J, &'json J)>, +) -> HashMap> { + let mut map: HashMap> = HashMap::new(); + for (key, value) in src { + // Need to handle number and string keys + let key_str = key + .as_str() + .map(|a| a.to_string()) + .or_else(|| key.as_f64().map(|a| a.to_string())); + + if let Some(key) = key_str { + if let Some(values) = map.get_mut(&key) { + values.push(value); + } else { + map.insert(key, vec![value]); + } + } + } + map +} diff --git a/projects/ssddOnTop/src/json/serde.rs b/projects/ssddOnTop/src/json/serde.rs new file mode 100644 index 0000000..4f6fad6 --- /dev/null +++ b/projects/ssddOnTop/src/json/serde.rs @@ -0,0 +1,119 @@ +use std::borrow::Cow; +use std::collections::HashMap; + +use super::{JsonLike, JsonObjectLike}; + +impl<'obj> JsonObjectLike<'obj> for serde_json::Map { + type Value = serde_json::Value; + + fn new() -> Self { + serde_json::Map::new() + } + + fn get_key(&self, key: &str) -> Option<&serde_json::Value> { + self.get(key) + } + + fn insert_key(&mut self, key: &'obj str, value: Self::Value) { + self.insert(key.to_owned(), value); + } +} + +impl<'json> JsonLike<'json> for serde_json::Value { + type JsonObject = serde_json::Map; + + fn as_array(&self) -> Option<&Vec> { + self.as_array() + } + + fn into_array(self) -> Option> { + if let Self::Array(vec) = self { + Some(vec) + } else { + None + } + } + + fn as_str(&self) -> Option<&str> { + self.as_str() + } + + fn as_i64(&self) -> Option { + self.as_i64() + } + + fn as_u64(&self) -> Option { + self.as_u64() + } + + fn as_f64(&self) -> Option { + self.as_f64() + } + + fn as_bool(&self) -> Option { + self.as_bool() + } + + fn is_null(&self) -> bool { + self.is_null() + } + + fn get_path>(&self, path: &[T]) -> Option<&Self> { + let mut val = self; + for token in path { + val = match val { + serde_json::Value::Array(arr) => { + let index = token.as_ref().parse::().ok()?; + arr.get(index)? + } + serde_json::Value::Object(map) => map.get(token.as_ref())?, + _ => return None, + }; + } + Some(val) + } + + fn get_key(&self, path: &str) -> Option<&Self> { + match self { + serde_json::Value::Object(map) => map.get(path), + _ => None, + } + } + + fn group_by(&self, path: &[String]) -> HashMap> { + let src = super::gather_path_matches(self, path, vec![]); + super::group_by_key(src) + } + + fn null() -> Self { + Self::Null + } + + fn as_object(&self) -> Option<&Self::JsonObject> { + self.as_object() + } + + fn as_object_mut(&mut self) -> Option<&mut Self::JsonObject> { + self.as_object_mut() + } + + fn into_object(self) -> Option { + if let Self::Object(obj) = self { + Some(obj) + } else { + None + } + } + + fn object(obj: Self::JsonObject) -> Self { + serde_json::Value::Object(obj) + } + + fn array(arr: Vec) -> Self { + serde_json::Value::Array(arr) + } + + fn string(s: Cow<'json, str>) -> Self { + serde_json::Value::String(s.to_string()) + } +} diff --git a/projects/ssddOnTop/src/lib.rs b/projects/ssddOnTop/src/lib.rs new file mode 100644 index 0000000..1dee637 --- /dev/null +++ b/projects/ssddOnTop/src/lib.rs @@ -0,0 +1,16 @@ +mod config; +mod from_doc; +mod blueprint; +mod mustache; +mod directive; +mod http; +mod helpers; +mod ir; +mod json; +mod path; +mod hasher; +mod value; + +pub fn is_default(val: &T) -> bool { + *val == T::default() +} diff --git a/projects/ssddOnTop/src/main.rs b/projects/ssddOnTop/src/main.rs new file mode 100644 index 0000000..b7d0cf2 --- /dev/null +++ b/projects/ssddOnTop/src/main.rs @@ -0,0 +1,11 @@ +fn main() -> anyhow::Result<()> { + tracing_subscriber::fmt::init(); + let rt = tokio::runtime::Builder::new_multi_thread() + .worker_threads(num_cpus::get()) + .enable_all() + .build()?; + rt.block_on(async { + tracing::info!("{}",num_cpus::get()); + }); + Ok(()) +} diff --git a/projects/ssddOnTop/src/mustache/eval.rs b/projects/ssddOnTop/src/mustache/eval.rs new file mode 100644 index 0000000..1e1b443 --- /dev/null +++ b/projects/ssddOnTop/src/mustache/eval.rs @@ -0,0 +1,274 @@ +use crate::mustache::model::{Mustache, Segment}; +use crate::path::PathString; + +pub trait Eval<'a> { + type In; + type Out; + + fn eval(&'a self, mustache: &'a Mustache, in_value: &'a Self::In) -> Self::Out; +} + +pub struct PathStringEval(std::marker::PhantomData); + +impl PathStringEval { + pub fn new() -> Self { + Self(std::marker::PhantomData) + } +} + +impl<'a, A: PathString> Eval<'a> for PathStringEval { + type In = A; + type Out = String; + + fn eval(&self, mustache: &Mustache, in_value: &Self::In) -> Self::Out { + mustache + .segments() + .iter() + .map(|segment| match segment { + Segment::Literal(text) => text.clone(), + Segment::Expression(parts) => in_value + .path_string(parts) + .map(|a| a.to_string()) + .unwrap_or_default(), + }) + .collect() + } +} + +pub trait Path { + fn get_path>(&self, in_value: &[S]) -> Option<&Self>; +} + +pub struct PathEval(std::marker::PhantomData); + +impl PathEval { + #[allow(unused)] + pub fn new() -> Self { + Self(std::marker::PhantomData) + } +} + +#[allow(unused)] +pub enum Exit<'a, A> { + Text(&'a str), + Value(&'a A), +} + +impl<'a, A: Path + 'a> Eval<'a> for PathEval<&'a A> { + type In = &'a A; + type Out = Vec>; + + fn eval(&'a self, mustache: &'a Mustache, in_value: &'a Self::In) -> Self::Out { + mustache + .segments() + .iter() + .filter_map(|segment| match segment { + Segment::Literal(text) => Some(Exit::Text(text)), + Segment::Expression(parts) => in_value.get_path(parts).map(Exit::Value), + }) + .collect::>() + } +} + +pub struct PathGraphqlEval(std::marker::PhantomData); + +impl PathGraphqlEval { + pub fn new() -> Self { + Self(std::marker::PhantomData) + } +} + +/*impl<'a, A: PathGraphql> Eval<'a> for PathGraphqlEval { + type In = A; + type Out = String; + + fn eval(&self, mustache: &Mustache, in_value: &Self::In) -> Self::Out { + mustache + .segments() + .iter() + .map(|segment| match segment { + Segment::Literal(text) => text.to_string(), + Segment::Expression(parts) => in_value.path_graphql(parts).unwrap_or_default(), + }) + .collect() + } +}*/ + +impl Mustache { + pub fn render(&self, value: &impl PathString) -> String { + PathStringEval::new().eval(self, value) + } + +/* pub fn render_graphql(&self, value: &impl PathGraphql) -> String { + PathGraphqlEval::new().eval(self, value) + }*/ +} + +/*#[cfg(test)] +mod tests { + + mod render { + use std::borrow::Cow; + + use serde_json::json; + + use crate::mustache::model::{Mustache, Segment}; + + #[test] + fn test_query_params_template() { + let s = r"/v1/templates?project-id={{value.projectId}}"; + let mustache: Mustache = Mustache::parse(s); + let ctx = json!(json!({"value": {"projectId": "123"}})); + let result = mustache.render(&ctx); + assert_eq!(result, "/v1/templates?project-id=123"); + } + + #[test] + fn test_render_mixed() { + struct DummyPath; + + impl PathString for DummyPath { + fn path_string>(&self, parts: &[T]) -> Option> { + let parts: Vec<&str> = parts.iter().map(AsRef::as_ref).collect(); + + if parts == ["foo", "bar"] { + Some(Cow::Borrowed("FOOBAR")) + } else if parts == ["baz", "qux"] { + Some(Cow::Borrowed("BAZQUX")) + } else { + None + } + } + } + + let mustache = Mustache::from(vec![ + Segment::Literal("prefix ".to_string()), + Segment::Expression(vec!["foo".to_string(), "bar".to_string()]), + Segment::Literal(" middle ".to_string()), + Segment::Expression(vec!["baz".to_string(), "qux".to_string()]), + Segment::Literal(" suffix".to_string()), + ]); + + assert_eq!( + mustache.render(&DummyPath), + "prefix FOOBAR middle BAZQUX suffix" + ); + } + + #[test] + fn test_render_with_missing_path() { + struct DummyPath; + + impl PathString for DummyPath { + fn path_string>(&self, _: &[T]) -> Option> { + None + } + } + + let mustache = Mustache::from(vec![ + Segment::Literal("prefix ".to_string()), + Segment::Expression(vec!["foo".to_string(), "bar".to_string()]), + Segment::Literal(" suffix".to_string()), + ]); + + assert_eq!(mustache.render(&DummyPath), "prefix suffix"); + } + + #[test] + fn test_json_like() { + let mustache = Mustache::parse(r#"{registered: "{{foo}}", display: "{{bar}}"}"#); + let ctx = json!({"foo": "baz", "bar": "qux"}); + let result = mustache.render(&ctx); + assert_eq!(result, r#"{registered: "baz", display: "qux"}"#); + } + + #[test] + fn test_json_like_static() { + let mustache = Mustache::parse(r#"{registered: "foo", display: "bar"}"#); + let ctx = json!({}); // Context is not used in this case + let result = mustache.render(&ctx); + assert_eq!(result, r#"{registered: "foo", display: "bar"}"#); + } + + #[test] + fn test_render_preserves_spaces() { + struct DummyPath; + + impl PathString for DummyPath { + fn path_string>(&self, parts: &[T]) -> Option> { + let parts: Vec<&str> = parts.iter().map(AsRef::as_ref).collect(); + + if parts == ["foo"] { + Some(Cow::Borrowed("bar")) + } else { + None + } + } + } + + let mustache = Mustache::from(vec![ + Segment::Literal(" ".to_string()), + Segment::Expression(vec!["foo".to_string()]), + Segment::Literal(" ".to_string()), + ]); + + assert_eq!(mustache.render(&DummyPath).as_str(), " bar "); + } + } + + mod render_graphql { + use crate::core::mustache::{Mustache, Segment}; + use crate::core::path::PathGraphql; + + #[test] + fn test_render_mixed() { + struct DummyPath; + + impl PathGraphql for DummyPath { + fn path_graphql>(&self, parts: &[T]) -> Option { + let parts: Vec<&str> = parts.iter().map(AsRef::as_ref).collect(); + + if parts == ["foo", "bar"] { + Some("FOOBAR".to_owned()) + } else if parts == ["baz", "qux"] { + Some("BAZQUX".to_owned()) + } else { + None + } + } + } + + let mustache = Mustache::from(vec![ + Segment::Literal("prefix ".to_string()), + Segment::Expression(vec!["foo".to_string(), "bar".to_string()]), + Segment::Literal(" middle ".to_string()), + Segment::Expression(vec!["baz".to_string(), "qux".to_string()]), + Segment::Literal(" suffix".to_string()), + ]); + + assert_eq!( + mustache.render_graphql(&DummyPath), + "prefix FOOBAR middle BAZQUX suffix" + ); + } + + #[test] + fn test_render_with_missing_path() { + struct DummyPath; + + impl PathGraphql for DummyPath { + fn path_graphql>(&self, _: &[T]) -> Option { + None + } + } + + let mustache = Mustache::from(vec![ + Segment::Literal("prefix ".to_string()), + Segment::Expression(vec!["foo".to_string(), "bar".to_string()]), + Segment::Literal(" suffix".to_string()), + ]); + + assert_eq!(mustache.render_graphql(&DummyPath), "prefix suffix"); + } + } +}*/ diff --git a/projects/ssddOnTop/src/mustache/mod.rs b/projects/ssddOnTop/src/mustache/mod.rs new file mode 100644 index 0000000..fd012f3 --- /dev/null +++ b/projects/ssddOnTop/src/mustache/mod.rs @@ -0,0 +1,3 @@ +pub mod model; +pub mod parse; +mod eval; \ No newline at end of file diff --git a/projects/ssddOnTop/src/mustache/model.rs b/projects/ssddOnTop/src/mustache/model.rs new file mode 100644 index 0000000..af18d19 --- /dev/null +++ b/projects/ssddOnTop/src/mustache/model.rs @@ -0,0 +1,68 @@ +use std::fmt::Display; + +#[derive(Debug, Clone, PartialEq, Hash, Default)] +pub struct Mustache(Vec); + +#[derive(Debug, Clone, PartialEq, Hash)] +pub enum Segment { + Literal(String), + Expression(Vec), +} + +impl> From for Mustache { + fn from(value: A) -> Self { + Mustache(value.into_iter().collect()) + } +} + +impl Mustache { + pub fn is_const(&self) -> bool { + match self { + Mustache(segments) => { + for s in segments { + if let Segment::Expression(_) = s { + return false; + } + } + true + } + } + } + + pub fn segments(&self) -> &Vec { + &self.0 + } + + pub fn expression_segments(&self) -> Vec<&Vec> { + self.segments() + .iter() + .filter_map(|seg| match seg { + Segment::Expression(parts) => Some(parts), + _ => None, + }) + .collect() + } + + /// Checks if the mustache template contains the given expression + pub fn expression_contains(&self, expression: &str) -> bool { + self.segments() + .iter() + .any(|seg| matches!(seg, Segment::Expression(parts) if parts.iter().any(|part| part.as_str() == expression))) + } +} + +impl Display for Mustache { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let str = self + .segments() + .iter() + .map(|segment| match segment { + Segment::Literal(text) => text.clone(), + Segment::Expression(parts) => format!("{{{{{}}}}}", parts.join(".")), + }) + .collect::>() + .join(""); + + write!(f, "{}", str) + } +} diff --git a/projects/ssddOnTop/src/mustache/parse.rs b/projects/ssddOnTop/src/mustache/parse.rs new file mode 100644 index 0000000..0b2eb99 --- /dev/null +++ b/projects/ssddOnTop/src/mustache/parse.rs @@ -0,0 +1,273 @@ +use nom::branch::alt; +use nom::bytes::complete::{tag, take_until}; +use nom::character::complete::char; +use nom::combinator::map; +use nom::multi::many0; +use nom::sequence::delimited; +use nom::{Finish, IResult}; +use crate::mustache::model::{Mustache, Segment}; +use super::*; + +impl Mustache { + // TODO: infallible function, no need to return Result + pub fn parse(str: &str) -> Mustache { + let result = parse_mustache(str).finish(); + match result { + Ok((_, mustache)) => mustache, + Err(_) => Mustache::from(vec![Segment::Literal(str.to_string())]), + } + } +} + +fn parse_name(input: &str) -> IResult<&str, String> { + let spaces = nom::character::complete::multispace0; + let alpha = nom::character::complete::alpha1; + let alphanumeric_or_underscore = nom::multi::many0(nom::branch::alt(( + nom::character::complete::alphanumeric1, + nom::bytes::complete::tag("_"), + ))); + + let parser = nom::sequence::tuple((spaces, alpha, alphanumeric_or_underscore, spaces)); + + nom::combinator::map(parser, |(_, a, b, _)| { + let b: String = b.into_iter().collect(); + format!("{}{}", a, b) + })(input) +} + +fn parse_expression(input: &str) -> IResult<&str, Segment> { + delimited( + tag("{{"), + map( + nom::sequence::tuple(( + nom::combinator::opt(char('.')), // Optional leading dot + nom::multi::separated_list1(char('.'), parse_name), + )), + |(_, expr_parts)| Segment::Expression(expr_parts), + ), + tag("}}"), + )(input) +} + +fn parse_segment(input: &str) -> IResult<&str, Vec> { + let expression_result = many0(alt(( + parse_expression, + map(take_until("{{"), |txt: &str| { + Segment::Literal(txt.to_string()) + }), + )))(input); + + if let Ok((remaining, segments)) = expression_result { + if remaining.is_empty() { + Ok((remaining, segments)) + } else { + let mut segments = segments; + segments.push(Segment::Literal(remaining.to_string())); + Ok(("", segments)) + } + } else { + Ok(("", vec![Segment::Literal(input.to_string())])) + } +} + +fn parse_mustache(input: &str) -> IResult<&str, Mustache> { + map(parse_segment, |segments| { + Mustache::from(segments.into_iter().filter(|seg| match seg { + Segment::Literal(s) => (!s.is_empty()) && s != "\"", + _ => true, + })) + })(input) +} + +#[cfg(test)] +mod tests { + + use pretty_assertions::assert_eq; + + use crate::mustache::model::{Mustache, Segment}; + + #[test] + fn test_to_string() { + let expectations = vec![ + r"/users/{{value.id}}/todos", + r"http://localhost:8090/{{foo.bar}}/api/{{hello.world}}/end", + r"http://localhost:{{args.port}}", + r"/users/{{value.userId}}", + r"/bar?id={{args.id}}&flag={{args.flag}}", + r"/foo?id={{value.id}}", + r"{{value.d}}", + r"/posts/{{args.id}}", + r"http://localhost:8000", + ]; + + for expected in expectations { + let mustache = Mustache::parse(expected); + + assert_eq!(expected, mustache.to_string()); + } + } + + #[test] + fn test_single_literal() { + let s = r"hello/world"; + let mustache: Mustache = Mustache::parse(s); + assert_eq!( + mustache, + Mustache::from(vec![Segment::Literal("hello/world".to_string())]) + ); + } + + #[test] + fn test_single_template() { + let s = r"{{hello.world}}"; + let mustache: Mustache = Mustache::parse(s); + assert_eq!( + mustache, + Mustache::from(vec![Segment::Expression(vec![ + "hello".to_string(), + "world".to_string(), + ])]) + ); + } + + #[test] + fn test_mixed() { + let s = r"http://localhost:8090/{{foo.bar}}/api/{{hello.world}}/end"; + let mustache: Mustache = Mustache::parse(s); + assert_eq!( + mustache, + Mustache::from(vec![ + Segment::Literal("http://localhost:8090/".to_string()), + Segment::Expression(vec!["foo".to_string(), "bar".to_string()]), + Segment::Literal("/api/".to_string()), + Segment::Expression(vec!["hello".to_string(), "world".to_string()]), + Segment::Literal("/end".to_string()), + ]) + ); + } + + #[test] + fn test_with_spaces() { + let s = "{{ foo . bar }}"; + let mustache: Mustache = Mustache::parse(s); + assert_eq!( + mustache, + Mustache::from(vec![Segment::Expression(vec![ + "foo".to_string(), + "bar".to_string(), + ])]) + ); + } + + #[test] + fn test_parse_expression_with_valid_input() { + let result = Mustache::parse("{{ foo.bar }} extra"); + let expected = Mustache::from(vec![ + Segment::Expression(vec!["foo".to_string(), "bar".to_string()]), + Segment::Literal(" extra".to_string()), + ]); + assert_eq!(result, expected); + } + + #[test] + fn test_parse_expression_with_invalid_input() { + let result = Mustache::parse("foo.bar }}"); + let expected = Mustache::from(vec![Segment::Literal("foo.bar }}".to_string())]); + assert_eq!(result, expected); + } + + #[test] + fn test_parse_segments_mixed() { + let result = Mustache::parse("prefix {{foo.bar}} middle {{baz.qux}} suffix"); + let expected = Mustache::from(vec![ + Segment::Literal("prefix ".to_string()), + Segment::Expression(vec!["foo".to_string(), "bar".to_string()]), + Segment::Literal(" middle ".to_string()), + Segment::Expression(vec!["baz".to_string(), "qux".to_string()]), + Segment::Literal(" suffix".to_string()), + ]); + assert_eq!(result, expected); + } + + #[test] + fn test_parse_segments_only_literal() { + let result = Mustache::parse("just a string"); + let expected = Mustache::from(vec![Segment::Literal("just a string".to_string())]); + assert_eq!(result, expected); + } + + #[test] + fn test_parse_segments_only_expression() { + let result = Mustache::parse("{{foo.bar}}"); + let expected = Mustache::from(vec![Segment::Expression(vec![ + "foo".to_string(), + "bar".to_string(), + ])]); + assert_eq!(result, expected); + } + + #[test] + fn test_unfinished_expression() { + let s = r"{{hello.world"; + let mustache: Mustache = Mustache::parse(s); + assert_eq!( + mustache, + Mustache::from(vec![Segment::Literal("{{hello.world".to_string())]) + ); + } + + #[test] + fn test_new_number() { + let mustache = Mustache::parse("123"); + assert_eq!( + mustache, + Mustache::from(vec![Segment::Literal("123".to_string())]) + ); + } + + #[test] + fn parse_env_name() { + let result = Mustache::parse("{{env.FOO}}"); + assert_eq!( + result, + Mustache::from(vec![Segment::Expression(vec![ + "env".to_string(), + "FOO".to_string(), + ])]) + ); + } + + #[test] + fn parse_env_with_underscores() { + let result = Mustache::parse("{{env.FOO_BAR}}"); + assert_eq!( + result, + Mustache::from(vec![Segment::Expression(vec![ + "env".to_string(), + "FOO_BAR".to_string(), + ])]) + ); + } + + #[test] + fn single_curly_brackets() { + let result = Mustache::parse("test:{SHA}string"); + assert_eq!( + result, + Mustache::from(vec![Segment::Literal("test:{SHA}string".to_string())]) + ); + } + + #[test] + fn test_optional_dot_expression() { + let s = r"{{.foo.bar}}"; + let mustache: Mustache = Mustache::parse(s); + assert_eq!( + mustache, + Mustache::from(vec![Segment::Expression(vec![ + "foo".to_string(), + "bar".to_string(), + ])]) + ); + } +} diff --git a/projects/ssddOnTop/src/path.rs b/projects/ssddOnTop/src/path.rs new file mode 100644 index 0000000..b6afe7b --- /dev/null +++ b/projects/ssddOnTop/src/path.rs @@ -0,0 +1,523 @@ +use std::borrow::Cow; + +use serde_json::json; + +// use crate::jit::eval_ctx::EvalContext; +use crate::json::JsonLike; + +/// +/// The path module provides a trait for accessing values from a JSON-like +/// structure. + +/// +/// The PathString trait provides a method for accessing values from a JSON-like +/// structure. The returned value is encoded as a plain string. +/// This is typically used in evaluating mustache templates. +pub trait PathString { + fn path_string<'a, T: AsRef>(&'a self, path: &'a [T]) -> Option>; +} + +/// PathValue trait provides a method for accessing values from JSON-like +/// structure, the returned value is wrapped with RawValue enum, delegating +/// encoding to the client of this method. +pub trait PathValue { + fn raw_value<'a, T: AsRef>(&'a self, path: &[T]) -> Option>; +} + +/// +/// The PathGraphql trait provides a method for accessing values from a +/// JSON-like structure. The returned value is encoded as a GraphQL Value. +pub trait PathGraphql { + fn path_graphql>(&self, path: &[T]) -> Option; +} + +impl PathString for serde_json::Value { + fn path_string<'a, T: AsRef>(&'a self, path: &'a [T]) -> Option> { + self.get_path(path).map(move |a| match a { + serde_json::Value::String(s) => Cow::Borrowed(s.as_str()), + _ => Cow::Owned(a.to_string()), + }) + } +} + +fn convert_value(value: Cow<'_, async_graphql::Value>) -> Option> { + match value { + Cow::Owned(async_graphql::Value::String(s)) => Some(Cow::Owned(s)), + Cow::Owned(async_graphql::Value::Number(n)) => Some(Cow::Owned(n.to_string())), + Cow::Owned(async_graphql::Value::Boolean(b)) => Some(Cow::Owned(b.to_string())), + Cow::Owned(async_graphql::Value::Object(map)) => Some(json!(map).to_string().into()), + Cow::Owned(async_graphql::Value::List(list)) => Some(json!(list).to_string().into()), + Cow::Borrowed(async_graphql::Value::String(s)) => Some(Cow::Borrowed(s.as_str())), + Cow::Borrowed(async_graphql::Value::Number(n)) => Some(Cow::Owned(n.to_string())), + Cow::Borrowed(async_graphql::Value::Boolean(b)) => Some(Cow::Owned(b.to_string())), + Cow::Borrowed(async_graphql::Value::Object(map)) => Some(json!(map).to_string().into()), + Cow::Borrowed(async_graphql::Value::List(list)) => Some(json!(list).to_string().into()), + _ => None, + } +} + +/// +/// An optimized version of async_graphql::Value that handles strings in a more +/// efficient manner. +#[derive(Clone, Debug, PartialEq)] +pub enum ValueString<'a> { + Value(Cow<'a, async_graphql::Value>), + String(Cow<'a, str>), +} + +/*impl<'a> EvalContext<'a> { + fn to_raw_value>(&self, path: &[T]) -> Option> { + let ctx = self; + + if path.is_empty() { + return None; + } + + if path.len() == 1 { + return match path[0].as_ref() { + "value" => Some(ValueString::Value(ctx.path_value(&[] as &[T])?)), + "args" => Some(ValueString::Value(ctx.path_arg::<&str>(&[])?)), + "vars" => Some(ValueString::String(Cow::Owned( + json!(ctx.vars()).to_string(), + ))), + _ => None, + }; + } + + path.split_first() + .and_then(move |(head, tail)| match head.as_ref() { + "value" => Some(ValueString::Value(ctx.path_value(tail)?)), + "args" => Some(ValueString::Value(ctx.path_arg(tail)?)), + "headers" => Some(ValueString::String(Cow::Borrowed( + ctx.header(tail[0].as_ref())?, + ))), + "vars" => Some(ValueString::String(Cow::Borrowed( + ctx.var(tail[0].as_ref())?, + ))), + "env" => Some(ValueString::String(ctx.env_var(tail[0].as_ref())?)), + _ => None, + }) + } +} + +impl<'a> PathValue for EvalContext<'a> { + fn raw_value<'b, T: AsRef>(&'b self, path: &[T]) -> Option> { + self.to_raw_value(path) + } +} + +impl<'a> PathString for EvalContext<'a> { + fn path_string>(&self, path: &[T]) -> Option> { + self.to_raw_value(path).and_then(|value| match value { + ValueString::String(env) => Some(env), + ValueString::Value(value) => convert_value(value), + }) + } +} + +impl<'a> PathGraphql for EvalContext<'a> { + fn path_graphql>(&self, path: &[T]) -> Option { + if path.len() < 2 { + return None; + } + + self.to_raw_value(path).map(|value| match value { + ValueString::Value(val) => val.to_string(), + ValueString::String(val) => format!(r#""{val}""#), + }) + } +}*/ + +/*#[cfg(test)] +mod tests { + + mod evaluation_context { + use std::borrow::Cow; + use std::collections::BTreeMap; + use std::sync::Arc; + + use async_graphql_value::{ConstValue as Value, Name, Number}; + use hyper::header::HeaderValue; + use hyper::HeaderMap; + use indexmap::IndexMap; + use once_cell::sync::Lazy; + + use crate::core::http::RequestContext; + use crate::core::ir::{EvalContext, ResolverContextLike, SelectionField}; + use crate::core::path::{PathGraphql, PathString, PathValue, ValueString}; + use crate::core::EnvIO; + use crate::path::ValueString; + + struct Env { + env: BTreeMap, + } + + impl EnvIO for Env { + fn get(&self, key: &str) -> Option> { + self.env.get(key).map(Cow::from) + } + } + + impl Env { + pub fn init(map: BTreeMap) -> Self { + Self { env: map } + } + } + + static TEST_VALUES: Lazy = Lazy::new(|| { + let mut root = IndexMap::new(); + let mut nested = IndexMap::new(); + + nested.insert( + Name::new("existing"), + Value::String("nested-test".to_owned()), + ); + root.insert(Name::new("bool"), Value::Boolean(true)); + root.insert(Name::new("nested"), Value::Object(nested)); + root.insert(Name::new("number"), Value::Number(Number::from(2))); + root.insert(Name::new("str"), Value::String("str-test".to_owned())); + + Value::Object(root) + }); + + static TEST_ARGS: Lazy> = Lazy::new(|| { + let mut root = IndexMap::new(); + let mut nested = IndexMap::new(); + + nested.insert( + Name::new("existing"), + Value::String("nested-test".to_owned()), + ); + + root.insert(Name::new("nested"), Value::Object(nested)); + root.insert(Name::new("root"), Value::String("root-test".to_owned())); + + root + }); + + static TEST_HEADERS: Lazy = Lazy::new(|| { + let mut map = HeaderMap::new(); + + map.insert("x-existing", HeaderValue::from_static("header")); + + map + }); + + static TEST_VARS: Lazy> = Lazy::new(|| { + let mut map = BTreeMap::new(); + + map.insert("existing".to_owned(), "var".to_owned()); + + map + }); + + static TEST_ENV_VARS: Lazy> = Lazy::new(|| { + let mut map = BTreeMap::new(); + + map.insert("existing".to_owned(), "env".to_owned()); + + map + }); + + #[derive(Clone)] + struct MockGraphqlContext; + + impl ResolverContextLike for MockGraphqlContext { + fn value(&self) -> Option<&Value> { + Some(&TEST_VALUES) + } + + fn args(&self) -> Option<&IndexMap> { + Some(&TEST_ARGS) + } + + fn field(&self) -> Option { + None + } + + fn is_query(&self) -> bool { + false + } + + fn add_error(&self, _: async_graphql::ServerError) {} + } + + static REQ_CTX: Lazy = Lazy::new(|| { + let mut req_ctx = RequestContext::default().allowed_headers(TEST_HEADERS.clone()); + + req_ctx.server.vars = TEST_VARS.clone(); + req_ctx.runtime.env = Arc::new(Env::init(TEST_ENV_VARS.clone())); + + req_ctx + }); + + static EVAL_CTX: Lazy> = + Lazy::new(|| EvalContext::new(&REQ_CTX, &MockGraphqlContext)); + + #[test] + fn path_to_value() { + let mut map = IndexMap::default(); + map.insert( + async_graphql_value::Name::new("number"), + async_graphql::Value::Number(2.into()), + ); + map.insert( + async_graphql_value::Name::new("str"), + async_graphql::Value::String("str-test".into()), + ); + map.insert( + async_graphql_value::Name::new("bool"), + async_graphql::Value::Boolean(true), + ); + let mut nested_map = IndexMap::default(); + nested_map.insert( + async_graphql_value::Name::new("existing"), + async_graphql::Value::String("nested-test".into()), + ); + map.insert( + async_graphql_value::Name::new("nested"), + async_graphql::Value::Object(nested_map), + ); + + // value + assert_eq!( + EVAL_CTX.raw_value(&["value", "bool"]), + Some(ValueString::Value(Cow::Borrowed( + &async_graphql::Value::Boolean(true) + ))) + ); + assert_eq!( + EVAL_CTX.raw_value(&["value", "number"]), + Some(ValueString::Value(Cow::Borrowed( + &async_graphql::Value::Number(2.into()) + ))) + ); + assert_eq!( + EVAL_CTX.raw_value(&["value", "str"]), + Some(ValueString::Value(Cow::Borrowed( + &async_graphql::Value::String("str-test".into()) + ))) + ); + assert_eq!(EVAL_CTX.raw_value(&["value", "missing"]), None); + assert_eq!(EVAL_CTX.raw_value(&["value", "nested", "missing"]), None); + assert_eq!( + EVAL_CTX.raw_value(&["value"]), + Some(ValueString::Value(Cow::Borrowed( + &async_graphql::Value::Object(map.clone()), + ))) + ); + + // args + assert_eq!( + EVAL_CTX.raw_value(&["args", "root"]), + Some(ValueString::Value(Cow::Borrowed( + &async_graphql::Value::String("root-test".into()), + ))) + ); + + let mut expected = IndexMap::new(); + expected.insert( + async_graphql_value::Name::new("existing"), + async_graphql::Value::String("nested-test".into()), + ); + assert_eq!( + EVAL_CTX.raw_value(&["args", "nested"]), + Some(ValueString::Value(Cow::Borrowed( + &async_graphql::Value::Object(expected) + ))) + ); + + assert_eq!(EVAL_CTX.raw_value(&["args", "missing"]), None); + assert_eq!(EVAL_CTX.raw_value(&["args", "nested", "missing"]), None); + + let mut expected = IndexMap::new(); + let mut nested_map = IndexMap::new(); + nested_map.insert( + async_graphql_value::Name::new("existing"), + async_graphql::Value::String("nested-test".into()), + ); + expected.insert( + async_graphql_value::Name::new("nested"), + async_graphql::Value::Object(nested_map), + ); + expected.insert( + async_graphql_value::Name::new("root"), + async_graphql::Value::String("root-test".into()), + ); + assert_eq!( + EVAL_CTX.raw_value(&["args"]), + Some(ValueString::Value(Cow::Borrowed( + &async_graphql::Value::Object(expected) + ))) + ); + + // headers + assert_eq!( + EVAL_CTX.raw_value(&["headers", "x-existing"]), + Some(ValueString::String(Cow::Borrowed("header"))) + ); + assert_eq!(EVAL_CTX.raw_value(&["headers", "x-missing"]), None); + + // vars + assert_eq!( + EVAL_CTX.raw_value(&["vars", "existing"]), + Some(ValueString::String(Cow::Borrowed("var"))) + ); + assert_eq!(EVAL_CTX.raw_value(&["vars", "missing"]), None); + assert_eq!( + EVAL_CTX.raw_value(&["vars"]), + Some(ValueString::String(Cow::Borrowed(r#"{"existing":"var"}"#))) + ); + + // envs + assert_eq!( + EVAL_CTX.raw_value(&["env", "existing"]), + Some(ValueString::String(Cow::Borrowed("env"))) + ); + assert_eq!(EVAL_CTX.raw_value(&["env", "x-missing"]), None); + + // other value types + assert_eq!(EVAL_CTX.raw_value(&["foo", "key"]), None); + assert_eq!(EVAL_CTX.raw_value(&["bar", "key"]), None); + assert_eq!(EVAL_CTX.raw_value(&["baz", "key"]), None); + } + + #[test] + fn path_to_string() { + // value + assert_eq!( + EVAL_CTX.path_string(&["value", "bool"]), + Some(Cow::Borrowed("true")) + ); + assert_eq!( + EVAL_CTX.path_string(&["value", "number"]), + Some(Cow::Borrowed("2")) + ); + assert_eq!( + EVAL_CTX.path_string(&["value", "str"]), + Some(Cow::Borrowed("str-test")) + ); + assert_eq!( + EVAL_CTX.path_string(&["value", "nested"]), + Some(Cow::Borrowed("{\"existing\":\"nested-test\"}")) + ); + assert_eq!(EVAL_CTX.path_string(&["value", "missing"]), None); + assert_eq!(EVAL_CTX.path_string(&["value", "nested", "missing"]), None); + assert_eq!( + EVAL_CTX.path_string(&["value"]), + Some(Cow::Borrowed( + r#"{"bool":true,"nested":{"existing":"nested-test"},"number":2,"str":"str-test"}"# + )) + ); + + // args + assert_eq!( + EVAL_CTX.path_string(&["args", "root"]), + Some(Cow::Borrowed("root-test")) + ); + assert_eq!( + EVAL_CTX.path_string(&["args", "nested"]), + Some(Cow::Borrowed("{\"existing\":\"nested-test\"}")) + ); + assert_eq!(EVAL_CTX.path_string(&["args", "missing"]), None); + assert_eq!(EVAL_CTX.path_string(&["args", "nested", "missing"]), None); + assert_eq!( + EVAL_CTX.path_string(&["args"]), + Some(Cow::Borrowed( + r#"{"nested":{"existing":"nested-test"},"root":"root-test"}"# + )) + ); + + // headers + assert_eq!( + EVAL_CTX.path_string(&["headers", "x-existing"]), + Some(Cow::Borrowed("header")) + ); + assert_eq!(EVAL_CTX.path_string(&["headers", "x-missing"]), None); + + // vars + assert_eq!( + EVAL_CTX.path_string(&["vars", "existing"]), + Some(Cow::Borrowed("var")) + ); + assert_eq!(EVAL_CTX.path_string(&["vars", "missing"]), None); + assert_eq!( + EVAL_CTX.path_string(&["vars"]), + Some(Cow::Borrowed(r#"{"existing":"var"}"#)) + ); + + // envs + assert_eq!( + EVAL_CTX.path_string(&["env", "existing"]), + Some(Cow::Borrowed("env")) + ); + assert_eq!(EVAL_CTX.path_string(&["env", "x-missing"]), None); + + // other value types + assert_eq!(EVAL_CTX.path_string(&["foo", "key"]), None); + assert_eq!(EVAL_CTX.path_string(&["bar", "key"]), None); + assert_eq!(EVAL_CTX.path_string(&["baz", "key"]), None); + } + + #[test] + fn path_to_graphql_string() { + // value + assert_eq!( + EVAL_CTX.path_graphql(&["value", "bool"]), + Some("true".to_owned()) + ); + assert_eq!( + EVAL_CTX.path_graphql(&["value", "number"]), + Some("2".to_owned()) + ); + assert_eq!( + EVAL_CTX.path_graphql(&["value", "str"]), + Some("\"str-test\"".to_owned()) + ); + assert_eq!( + EVAL_CTX.path_graphql(&["value", "nested"]), + Some("{existing: \"nested-test\"}".to_owned()) + ); + assert_eq!(EVAL_CTX.path_graphql(&["value", "missing"]), None); + assert_eq!(EVAL_CTX.path_graphql(&["value", "nested", "missing"]), None); + + // args + assert_eq!( + EVAL_CTX.path_graphql(&["args", "root"]), + Some("\"root-test\"".to_owned()) + ); + assert_eq!( + EVAL_CTX.path_graphql(&["args", "nested"]), + Some("{existing: \"nested-test\"}".to_owned()) + ); + assert_eq!(EVAL_CTX.path_graphql(&["args", "missing"]), None); + assert_eq!(EVAL_CTX.path_graphql(&["args", "nested", "missing"]), None); + + // headers + assert_eq!( + EVAL_CTX.path_graphql(&["headers", "x-existing"]), + Some("\"header\"".to_owned()) + ); + assert_eq!(EVAL_CTX.path_graphql(&["headers", "x-missing"]), None); + + // vars + assert_eq!( + EVAL_CTX.path_graphql(&["vars", "existing"]), + Some("\"var\"".to_owned()) + ); + assert_eq!(EVAL_CTX.path_graphql(&["vars", "missing"]), None); + + // envs + assert_eq!( + EVAL_CTX.path_graphql(&["env", "existing"]), + Some("\"env\"".to_owned()) + ); + assert_eq!(EVAL_CTX.path_graphql(&["env", "x-missing"]), None); + + // other value types + assert_eq!(EVAL_CTX.path_graphql(&["foo", "key"]), None); + assert_eq!(EVAL_CTX.path_graphql(&["bar", "key"]), None); + assert_eq!(EVAL_CTX.path_graphql(&["baz", "key"]), None); + } + } +}*/ diff --git a/projects/ssddOnTop/src/value/mod.rs b/projects/ssddOnTop/src/value/mod.rs new file mode 100644 index 0000000..5ca2c1d --- /dev/null +++ b/projects/ssddOnTop/src/value/mod.rs @@ -0,0 +1,3 @@ +mod value; + +pub use value::*; \ No newline at end of file diff --git a/projects/ssddOnTop/src/value/value.rs b/projects/ssddOnTop/src/value/value.rs new file mode 100644 index 0000000..04b50bb --- /dev/null +++ b/projects/ssddOnTop/src/value/value.rs @@ -0,0 +1,19 @@ +use derive_getters::Getters; + +#[derive(Clone, Getters)] +pub struct Value { + serde: serde_json::Value, + borrowed: serde_json_borrow::Value<'static>, +} + +impl Value { + pub fn new(serde: serde_json::Value) -> Self { + let borrowed = serde_json_borrow::Value::from(&serde); + let borrowed = extend_lifetime(borrowed); + Self { serde, borrowed } + } +} + +fn extend_lifetime<'b>(r: serde_json_borrow::Value<'b>) -> serde_json_borrow::Value<'static> { + unsafe { std::mem::transmute::, serde_json_borrow::Value<'static>>(r) } +} \ No newline at end of file From c8e07a6b9f19b0a98895b0e41f3e8e361ce32c0d Mon Sep 17 00:00:00 2001 From: Sandipsinh Rathod Date: Wed, 11 Sep 2024 15:27:10 -0400 Subject: [PATCH 02/21] setup blueprint --- Cargo.lock | 1 + projects/ssddOnTop/Cargo.toml | 1 + projects/ssddOnTop/src/blueprint/blueprint.rs | 94 ++++++++++++-- .../ssddOnTop/src/blueprint/definitions.rs | 117 ++++++++++++++++++ projects/ssddOnTop/src/blueprint/mod.rs | 2 + projects/ssddOnTop/src/blueprint/model.rs | 3 +- .../ssddOnTop/src/blueprint/operators/http.rs | 77 ++++++++++++ .../ssddOnTop/src/blueprint/operators/mod.rs | 1 + projects/ssddOnTop/src/config/config.rs | 17 ++- projects/ssddOnTop/src/config/mod.rs | 4 +- projects/ssddOnTop/src/config/url_query.rs | 18 +++ projects/ssddOnTop/src/endpoint.rs | 19 +++ projects/ssddOnTop/src/http/method.rs | 42 +++++++ projects/ssddOnTop/src/http/mod.rs | 2 + projects/ssddOnTop/src/http/req_template.rs | 40 +++++- projects/ssddOnTop/src/lib.rs | 1 + 16 files changed, 421 insertions(+), 18 deletions(-) create mode 100644 projects/ssddOnTop/src/blueprint/definitions.rs create mode 100644 projects/ssddOnTop/src/blueprint/operators/http.rs create mode 100644 projects/ssddOnTop/src/blueprint/operators/mod.rs create mode 100644 projects/ssddOnTop/src/config/url_query.rs create mode 100644 projects/ssddOnTop/src/endpoint.rs create mode 100644 projects/ssddOnTop/src/http/method.rs diff --git a/Cargo.lock b/Cargo.lock index 84f1131..6b07a72 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2101,6 +2101,7 @@ dependencies = [ "serde_json", "serde_json_borrow", "serde_path_to_error", + "strum_macros", "test-log", "tokio", "tracing", diff --git a/projects/ssddOnTop/Cargo.toml b/projects/ssddOnTop/Cargo.toml index fb8594d..bdc2e39 100644 --- a/projects/ssddOnTop/Cargo.toml +++ b/projects/ssddOnTop/Cargo.toml @@ -31,3 +31,4 @@ test-log = "0.2.16" convert_case = "0.6.0" prost-reflect = "0.14.2" fxhash = "0.2.1" +strum_macros = "0.26.4" diff --git a/projects/ssddOnTop/src/blueprint/blueprint.rs b/projects/ssddOnTop/src/blueprint/blueprint.rs index cee5b7d..ed0578e 100644 --- a/projects/ssddOnTop/src/blueprint/blueprint.rs +++ b/projects/ssddOnTop/src/blueprint/blueprint.rs @@ -1,7 +1,12 @@ use crate::blueprint::model::{Arg, ArgId, Field, FieldId, FieldName, TypeName}; -use crate::config::Config; -use std::collections::HashMap; - +use crate::config::{Config, GraphQLOperationType}; +use std::collections::{BTreeSet, HashMap}; +use derive_setters::Setters; +use serde_json::Value; +use crate::blueprint::definitions::to_definitions; +use crate::blueprint::wrapping_type::Type; +use crate::config; +use crate::ir::IR; #[derive(Debug, Eq, Hash, PartialEq)] pub struct FieldHash { @@ -16,6 +21,56 @@ pub struct Blueprint { pub upstream: Upstream, } +#[derive(Clone, Debug)] +pub struct Directive { + pub name: String, + pub arguments: HashMap, + pub index: usize, +} + + +#[derive(Clone, Debug)] +pub enum Definition { + Interface(InterfaceTypeDefinition), + Object(ObjectTypeDefinition), + InputObject(InputObjectTypeDefinition), +} + +#[derive(Clone, Debug)] +pub struct InputObjectTypeDefinition { + pub name: String, + pub fields: Vec, +} + +#[derive(Clone, Debug)] +pub struct ObjectTypeDefinition { + pub name: String, + pub fields: Vec, +} + + +#[derive(Clone, Debug)] +pub struct InterfaceTypeDefinition { + pub name: String, + pub fields: Vec, +} + +#[derive(Clone, Debug, Setters, Default)] +pub struct FieldDefinition { + pub name: String, + pub args: Vec, + pub of_type: Type, + pub resolver: Option, + pub directives: Vec, +} + +#[derive(Clone, Debug)] +pub struct InputFieldDefinition { + pub name: String, + pub of_type: Type, +} + + #[derive(Debug)] pub struct Server { pub port: u16, @@ -30,7 +85,10 @@ impl TryFrom<&Config> for Blueprint { fn try_from(config: &Config) -> Result { let qry = config.schema.query.as_ref().ok_or(anyhow::anyhow!("Query not found"))?; - let fields = fields_to_map(qry, config); + let defs = to_definitions(config)?; + + let fields = fields_to_map(qry, config, defs); + let server = Server { port: config.server.port, }; @@ -45,28 +103,44 @@ impl TryFrom<&Config> for Blueprint { } } -fn fields_to_map(qry: &str, config: &Config) -> HashMap { +fn fields_to_map(qry: &str, config: &Config, defs: Vec) -> HashMap { let mut fields = HashMap::new(); - populate_nested_field(config, qry, &mut fields); + populate_nested_field(config, qry, 0, &mut fields, &defs); fields } fn populate_nested_field( config: &Config, ty_name: &str, + field_id: usize, field_map: &mut HashMap, + defs: &[Definition], ) { // I don't have additional check for scalars as of now.. // This should work fine if let Some(ty) = config.types.get(ty_name) { for (field_name, field) in ty.fields.iter() { let field_name = FieldName(field_name.clone()); - populate_nested_field(config, field.ty_of.name(), field_map); + populate_nested_field(config, field.ty_of.name(), field_id + 1, field_map, defs); let mut arg_id = 0; let field = Field { - id: FieldId::new(0), + id: FieldId::new(field_id), name: field_name.clone(), type_of: field.ty_of.clone(), + ir: { + let x = defs.iter().find_map(|def| match def { + Definition::Interface(int) => { + Some(int.fields.iter().find(|f| field_name.0.eq(&f.name))?.clone()) + } + Definition::Object(obj) => { + Some(obj.fields.iter().find(|f| field_name.0.eq(&f.name))?.clone()) + } + Definition::InputObject(_) => { + None + } + }); + x.and_then(|x| x.resolver.clone()) + }, args: field.args.iter().map(|(arg_name, arg)| { let arg = Arg { id: ArgId::new(arg_id), @@ -95,8 +169,8 @@ mod test { fn test() { let reader = ConfigReader::init(); let root = env!("CARGO_MANIFEST_DIR"); - let config = reader.read(format!("{}/schema/schema.graphql",root)).unwrap(); + let config = reader.read(format!("{}/schema/schema.graphql", root)).unwrap(); let blueprint = crate::blueprint::Blueprint::try_from(&config).unwrap(); - println!("{:#?}", blueprint); + // println!("{:#?}", blueprint); } } \ No newline at end of file diff --git a/projects/ssddOnTop/src/blueprint/definitions.rs b/projects/ssddOnTop/src/blueprint/definitions.rs new file mode 100644 index 0000000..8395835 --- /dev/null +++ b/projects/ssddOnTop/src/blueprint/definitions.rs @@ -0,0 +1,117 @@ +use crate::blueprint::operators::http::update_http; +use crate::blueprint::{Definition, FieldDefinition, InputFieldDefinition, InputObjectTypeDefinition, InterfaceTypeDefinition, ObjectTypeDefinition}; +use crate::config; +use crate::config::Config; + +pub fn to_definitions(config: &Config) -> anyhow::Result> { + let mut definitions = vec![]; + for (ty_name, ty) in config.types.iter() { + let def = to_object_type_definition(ty_name, ty, config).and_then(|definition| match definition { + Definition::Object(_) => { + Ok(definition) + /*if config.input_types().contains(ty_name) { + to_input_object_type_definition(object_type_definition) + } else if config.interface_types().contains(ty_name) { + to_interface_type_definition(object_type_definition) + } else { + Ok(definition) + }*/ + } + _ => Ok(definition), + })?; + definitions.push(def); + } + Ok(definitions) +} + +fn to_interface_type_definition(definition: ObjectTypeDefinition) -> anyhow::Result { + Ok( + Definition::Interface(InterfaceTypeDefinition { + name: definition.name, + fields: definition.fields, + }) + ) +} + +fn to_input_object_type_definition( + definition: ObjectTypeDefinition, +) -> anyhow::Result { + Ok( + Definition::InputObject(InputObjectTypeDefinition { + name: definition.name, + fields: definition + .fields + .iter() + .map(|field| InputFieldDefinition { + name: field.name.clone(), + of_type: field.of_type.clone(), + }) + .collect(), + }) + ) +} + +fn to_object_type_definition( + name: &str, + type_of: &config::Type1, + config_module: &Config, +) -> anyhow::Result { + to_fields(name, type_of, config_module).map(|fields| { + Definition::Object(ObjectTypeDefinition { + name: name.to_string(), + fields, + }) + }) +} + +fn to_fields( + name: &str, + ty: &config::Type1, + config: &Config, +) -> anyhow::Result> { + if !config.types.contains_key(name) { + // assume it's a scalar + return Ok(vec![]); + } + + let mut fields = vec![]; + for (field_name, field) in ty.fields.iter() { + to_field_definition(field_name, field, config).map(|field| { + fields.push(field); + })?; + } + + Ok(fields) +} + + +fn to_field_definition( + field_name: &str, + field: &config::Field, + config: &Config, +) -> anyhow::Result { + let mut def = FieldDefinition::default(); + def = update_args(field_name, field.clone(), def); + def = update_http(field, config, def)?; + Ok(def) +} + +fn update_args( + field_name: &str, + field: config::Field, + mut def: FieldDefinition, +) -> FieldDefinition { + let args = field.args.iter().map(|(name, arg)| { + let arg = InputFieldDefinition { + name: name.clone(), + of_type: arg.type_of.clone(), + }; + arg + }).collect::>(); + + def.name = field_name.to_string(); + def.args = args; + def.of_type = field.ty_of.clone(); + + def +} diff --git a/projects/ssddOnTop/src/blueprint/mod.rs b/projects/ssddOnTop/src/blueprint/mod.rs index 3b0a863..edce276 100644 --- a/projects/ssddOnTop/src/blueprint/mod.rs +++ b/projects/ssddOnTop/src/blueprint/mod.rs @@ -1,5 +1,7 @@ pub mod wrapping_type; mod blueprint; mod model; +mod definitions; +mod operators; pub use blueprint::*; \ No newline at end of file diff --git a/projects/ssddOnTop/src/blueprint/model.rs b/projects/ssddOnTop/src/blueprint/model.rs index 76e7cb7..f423ef9 100644 --- a/projects/ssddOnTop/src/blueprint/model.rs +++ b/projects/ssddOnTop/src/blueprint/model.rs @@ -1,4 +1,5 @@ use std::fmt::{Debug, Formatter}; +use crate::ir::IR; #[derive(Clone, Debug, Eq, Hash, PartialEq)] pub struct FieldName(pub String); @@ -56,6 +57,6 @@ pub struct Field { pub id: FieldId, pub name: FieldName, pub type_of: crate::blueprint::wrapping_type::Type, - // pub ir: Option, + pub ir: Option, pub args: Vec, } \ No newline at end of file diff --git a/projects/ssddOnTop/src/blueprint/operators/http.rs b/projects/ssddOnTop/src/blueprint/operators/http.rs new file mode 100644 index 0000000..984642d --- /dev/null +++ b/projects/ssddOnTop/src/blueprint/operators/http.rs @@ -0,0 +1,77 @@ +use crate::http::method::Method; +use crate::blueprint::FieldDefinition; +use crate::config; +use crate::config::Resolver; +use crate::endpoint::Endpoint; +use crate::http::RequestTemplate; +use crate::ir::{IO, IR}; +use crate::mustache::model::Mustache; + +fn compile_http( + config_module: &config::Config, + http: &config::Http, +) -> anyhow::Result { + let mut base_url = String::new(); + if let Some(base) = http.base_url.clone() { + base_url = base; + }else { + if let Some(base) = config_module.upstream.base_url.clone() { + base_url = base; + }else { + return Err(anyhow::anyhow!("No base URL defined")); + } + } + let mut base_url = base_url.trim_end_matches('/').to_owned(); + base_url.push_str(http.path.clone().as_str()); + + let query = http + .query + .clone() + .iter() + .map(|key_value| { + ( + key_value.key.clone(), + key_value.value.clone(), + key_value.skip_empty.unwrap_or_default(), + ) + }) + .collect(); + + let req_template = RequestTemplate::try_from( + Endpoint::new(base_url.to_string()) + .method(http.method.clone()) + .query(query) + )?; + + let ir = if http.method == Method::GET { + // Find a query parameter that contains a reference to the {{.value}} key + let key = http.query.iter().find_map(|q| { + Mustache::parse(&q.value) + .expression_contains("value") + .then(|| q.key.clone()) + }); + IR::IO(IO::Http { + req_template, + dl_id: None, + }) + } else { + IR::IO(IO::Http { req_template, dl_id: None }) + }; + + Ok(ir) +} + +pub fn update_http( + field: &config::Field, + config: &config::Config, + mut def: FieldDefinition, +) -> anyhow::Result { + let Some(Resolver::Http(http)) = field.resolver.as_ref() else { + return Ok(def); + }; + + let ir = compile_http(config, http)?; + def.resolver = Some(ir); + // TODO: Validate + Ok(def) +} diff --git a/projects/ssddOnTop/src/blueprint/operators/mod.rs b/projects/ssddOnTop/src/blueprint/operators/mod.rs new file mode 100644 index 0000000..e05256f --- /dev/null +++ b/projects/ssddOnTop/src/blueprint/operators/mod.rs @@ -0,0 +1 @@ +pub mod http; \ No newline at end of file diff --git a/projects/ssddOnTop/src/config/config.rs b/projects/ssddOnTop/src/config/config.rs index c8aaacc..01ab08f 100644 --- a/projects/ssddOnTop/src/config/config.rs +++ b/projects/ssddOnTop/src/config/config.rs @@ -1,9 +1,10 @@ use crate::blueprint::wrapping_type; +use crate::config::url_query::URLQuery; use crate::is_default; use serde::{Deserialize, Serialize}; use std::collections::BTreeMap; use std::num::NonZeroU64; -use derive_setters::Setters; +use crate::http::method::Method; #[derive(Serialize, Deserialize, Clone, Debug)] pub struct Config { @@ -86,6 +87,12 @@ pub struct Arg { #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] pub struct Http { pub path: String, + #[serde(default, skip_serializing_if = "is_default")] + pub method: Method, + #[serde(rename = "baseURL", default, skip_serializing_if = "is_default")] + pub base_url: Option, + #[serde(default, skip_serializing_if = "is_default")] + pub query: Vec, } @@ -93,3 +100,11 @@ pub struct Http { pub enum Resolver { Http(Http), } + +#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[serde(rename_all = "lowercase")] +pub enum GraphQLOperationType { + #[default] + Query, + Mutation, +} \ No newline at end of file diff --git a/projects/ssddOnTop/src/config/mod.rs b/projects/ssddOnTop/src/config/mod.rs index 3aeaacb..d0bb7de 100644 --- a/projects/ssddOnTop/src/config/mod.rs +++ b/projects/ssddOnTop/src/config/mod.rs @@ -1,7 +1,9 @@ mod config; mod reader; mod kv; +mod url_query; pub use config::*; pub use reader::*; -pub use kv::*; \ No newline at end of file +pub use kv::*; +pub use url_query::*; \ No newline at end of file diff --git a/projects/ssddOnTop/src/config/url_query.rs b/projects/ssddOnTop/src/config/url_query.rs new file mode 100644 index 0000000..df1410c --- /dev/null +++ b/projects/ssddOnTop/src/config/url_query.rs @@ -0,0 +1,18 @@ +use serde::{Deserialize, Serialize}; + +use crate::is_default; + +#[derive(Serialize, Deserialize, Clone, Debug, Default, Eq, PartialEq)] +#[serde(rename_all = "camelCase")] +/// The URLQuery input type represents a query parameter to be included in a +/// URL. +pub struct URLQuery { + /// The key or name of the query parameter. + pub key: String, + /// The actual value or a mustache template to resolve the value dynamically + /// for the query parameter. + pub value: String, + #[serde(default, skip_serializing_if = "is_default")] + /// Determines whether to ignore query parameters with empty values. + pub skip_empty: Option, +} diff --git a/projects/ssddOnTop/src/endpoint.rs b/projects/ssddOnTop/src/endpoint.rs new file mode 100644 index 0000000..6b732e8 --- /dev/null +++ b/projects/ssddOnTop/src/endpoint.rs @@ -0,0 +1,19 @@ +use derive_setters::Setters; +use crate::http::method::Method; + +#[derive(Clone, Debug, Setters)] +pub struct Endpoint { + pub path: String, + pub query: Vec<(String, String, bool)>, + pub method: Method, +} + +impl Endpoint { + pub fn new(url: String) -> Endpoint { + Self { + path: url, + query: Default::default(), + method: Default::default(), + } + } +} diff --git a/projects/ssddOnTop/src/http/method.rs b/projects/ssddOnTop/src/http/method.rs new file mode 100644 index 0000000..1cf5cb1 --- /dev/null +++ b/projects/ssddOnTop/src/http/method.rs @@ -0,0 +1,42 @@ +use serde::{Deserialize, Serialize}; +use strum_macros::Display; + +#[derive( + Clone, + Debug, + Serialize, + Deserialize, + PartialEq, + Eq, + Hash, + Default, + Display, +)] +pub enum Method { + #[default] + GET, + POST, + PUT, + PATCH, + DELETE, + HEAD, + OPTIONS, + CONNECT, + TRACE, +} + +impl Method { + pub fn to_hyper(self) -> hyper::Method { + match self { + Method::GET => hyper::Method::GET, + Method::POST => hyper::Method::POST, + Method::PUT => hyper::Method::PUT, + Method::PATCH => hyper::Method::PATCH, + Method::DELETE => hyper::Method::DELETE, + Method::HEAD => hyper::Method::HEAD, + Method::OPTIONS => hyper::Method::OPTIONS, + Method::CONNECT => hyper::Method::CONNECT, + Method::TRACE => hyper::Method::TRACE, + } + } +} diff --git a/projects/ssddOnTop/src/http/mod.rs b/projects/ssddOnTop/src/http/mod.rs index 3739ead..a2f6ce9 100644 --- a/projects/ssddOnTop/src/http/mod.rs +++ b/projects/ssddOnTop/src/http/mod.rs @@ -1,2 +1,4 @@ mod req_template; +pub mod method; + pub use req_template::*; \ No newline at end of file diff --git a/projects/ssddOnTop/src/http/req_template.rs b/projects/ssddOnTop/src/http/req_template.rs index 575a18a..eb4616a 100644 --- a/projects/ssddOnTop/src/http/req_template.rs +++ b/projects/ssddOnTop/src/http/req_template.rs @@ -1,15 +1,13 @@ -use std::hash::{Hash, Hasher}; -use crate::hasher::MyHasher; -use crate::helpers::headers::MustacheHeaders; -use crate::ir::IoId; +use crate::endpoint::Endpoint; use crate::mustache::model::Mustache; +use std::hash::Hash; #[derive(Debug, Clone)] pub struct RequestTemplate { pub root_url: Mustache, pub query: Vec, pub method: reqwest::Method, - pub headers: MustacheHeaders, + // pub headers: MustacheHeaders, } #[derive(Debug, Clone)] @@ -19,6 +17,38 @@ pub struct Query { pub skip_empty: bool, } +impl TryFrom for RequestTemplate { + type Error = anyhow::Error; + fn try_from(endpoint: Endpoint) -> anyhow::Result { + let path = Mustache::parse(endpoint.path.as_str()); + let query = endpoint + .query + .iter() + .map(|(k, v, skip)| { + Ok(Query { + key: k.as_str().to_string(), + value: Mustache::parse(v.as_str()), + skip_empty: *skip, + }) + }) + .collect::>>()?; + let method = endpoint.method.clone().to_hyper(); +/* let headers = endpoint + .headers + .iter() + .map(|(k, v)| Ok((k.clone(), Mustache::parse(v.to_str()?)))) + .collect::>>()?;*/ + + + Ok(Self { + root_url: path, + query, + method, + // headers, + }) + } +} + /*impl RequestTemplate { pub fn cache_key(&self, ctx: &EvalContext) -> IoId { let mut hasher = MyHasher::default(); diff --git a/projects/ssddOnTop/src/lib.rs b/projects/ssddOnTop/src/lib.rs index 1dee637..67bb506 100644 --- a/projects/ssddOnTop/src/lib.rs +++ b/projects/ssddOnTop/src/lib.rs @@ -10,6 +10,7 @@ mod json; mod path; mod hasher; mod value; +mod endpoint; pub fn is_default(val: &T) -> bool { *val == T::default() From 7d11cf65a039d99a2b6777c21107e48f9e0e219d Mon Sep 17 00:00:00 2001 From: Sandipsinh Rathod Date: Wed, 11 Sep 2024 16:16:31 -0400 Subject: [PATCH 03/21] http server --- mock-api/src/lib.rs | 4 +- mock-api/src/routes/get_user.rs | 5 +- projects/ssddOnTop/Cargo.toml | 2 +- projects/ssddOnTop/run.sh | 5 + projects/ssddOnTop/src/blueprint/blueprint.rs | 92 +++++---- .../ssddOnTop/src/blueprint/definitions.rs | 91 ++++----- projects/ssddOnTop/src/blueprint/mod.rs | 6 +- projects/ssddOnTop/src/blueprint/model.rs | 4 +- .../ssddOnTop/src/blueprint/operators/http.rs | 20 +- .../ssddOnTop/src/blueprint/operators/mod.rs | 2 +- .../ssddOnTop/src/blueprint/wrapping_type.rs | 56 ++++-- projects/ssddOnTop/src/config/config.rs | 14 +- projects/ssddOnTop/src/config/kv.rs | 2 +- projects/ssddOnTop/src/config/mod.rs | 6 +- projects/ssddOnTop/src/config/reader.rs | 14 +- projects/ssddOnTop/src/directive.rs | 14 +- projects/ssddOnTop/src/endpoint.rs | 2 +- projects/ssddOnTop/src/from_doc.rs | 98 ++++------ projects/ssddOnTop/src/hasher.rs | 2 +- projects/ssddOnTop/src/helpers/headers.rs | 11 +- projects/ssddOnTop/src/helpers/mod.rs | 2 +- projects/ssddOnTop/src/http/method.rs | 12 +- projects/ssddOnTop/src/http/mod.rs | 6 +- projects/ssddOnTop/src/http/req_template.rs | 13 +- projects/ssddOnTop/src/http/request.rs | 23 +++ .../ssddOnTop/src/http/request_handler.rs | 14 ++ projects/ssddOnTop/src/ir/discriminator.rs | 182 +++++++++++++----- projects/ssddOnTop/src/ir/mod.rs | 4 +- projects/ssddOnTop/src/ir/model.rs | 6 +- projects/ssddOnTop/src/lib.rs | 13 +- projects/ssddOnTop/src/main.rs | 4 +- projects/ssddOnTop/src/mustache/eval.rs | 2 +- projects/ssddOnTop/src/mustache/mod.rs | 2 +- projects/ssddOnTop/src/mustache/parse.rs | 4 +- projects/ssddOnTop/src/run/http1.rs | 47 +++++ projects/ssddOnTop/src/run/mod.rs | 4 + projects/ssddOnTop/src/run/run.rs | 17 ++ projects/ssddOnTop/src/value/mod.rs | 2 +- projects/ssddOnTop/src/value/value.rs | 6 +- src/bin/generate-mocks.rs | 7 +- 40 files changed, 519 insertions(+), 301 deletions(-) create mode 100755 projects/ssddOnTop/run.sh create mode 100644 projects/ssddOnTop/src/http/request.rs create mode 100644 projects/ssddOnTop/src/http/request_handler.rs create mode 100644 projects/ssddOnTop/src/run/http1.rs create mode 100644 projects/ssddOnTop/src/run/mod.rs create mode 100644 projects/ssddOnTop/src/run/run.rs diff --git a/mock-api/src/lib.rs b/mock-api/src/lib.rs index 8bbb83a..2d06cb6 100644 --- a/mock-api/src/lib.rs +++ b/mock-api/src/lib.rs @@ -66,7 +66,9 @@ impl IntoResponse for AppError { fn into_response(self) -> axum::response::Response { match self { AppError::NotFound(msg) => (StatusCode::NOT_FOUND, msg).into_response(), - AppError::InternalServerError(msg) => (StatusCode::INTERNAL_SERVER_ERROR, msg).into_response(), + AppError::InternalServerError(msg) => { + (StatusCode::INTERNAL_SERVER_ERROR, msg).into_response() + } } } } diff --git a/mock-api/src/routes/get_user.rs b/mock-api/src/routes/get_user.rs index dbaf54f..97f6e62 100644 --- a/mock-api/src/routes/get_user.rs +++ b/mock-api/src/routes/get_user.rs @@ -16,6 +16,9 @@ pub async fn handle( let user_id = user_id.0; match state.db.user(user_id) { Some(user) => Ok(Json(user).into_response()), - None => Err(AppError::NotFound(format!("User with id {} not found", user_id))), + None => Err(AppError::NotFound(format!( + "User with id {} not found", + user_id + ))), } } diff --git a/projects/ssddOnTop/Cargo.toml b/projects/ssddOnTop/Cargo.toml index bdc2e39..1c4f73b 100644 --- a/projects/ssddOnTop/Cargo.toml +++ b/projects/ssddOnTop/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" [dependencies] tokio = {version = "1.40.0", features = ["full"]} tracing = "0.1.40" -hyper = "1.4.1" +hyper = {version = "1.4.1",features = ["http1","server"]} hyper-util = {version = "0.1.8", features = ["tokio"]} http-body-util = "0.1.2" bytes = "1.7.1" diff --git a/projects/ssddOnTop/run.sh b/projects/ssddOnTop/run.sh new file mode 100755 index 0000000..c75c909 --- /dev/null +++ b/projects/ssddOnTop/run.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +set -e + +cargo run -p ssddOnTop #--release \ No newline at end of file diff --git a/projects/ssddOnTop/src/blueprint/blueprint.rs b/projects/ssddOnTop/src/blueprint/blueprint.rs index ed0578e..4c77966 100644 --- a/projects/ssddOnTop/src/blueprint/blueprint.rs +++ b/projects/ssddOnTop/src/blueprint/blueprint.rs @@ -1,12 +1,12 @@ -use crate::blueprint::model::{Arg, ArgId, Field, FieldId, FieldName, TypeName}; -use crate::config::{Config, GraphQLOperationType}; -use std::collections::{BTreeSet, HashMap}; -use derive_setters::Setters; -use serde_json::Value; use crate::blueprint::definitions::to_definitions; +use crate::blueprint::model::{Arg, ArgId, Field, FieldId, FieldName, TypeName}; use crate::blueprint::wrapping_type::Type; -use crate::config; +use crate::config::Config; use crate::ir::IR; +use derive_setters::Setters; +use serde_json::Value; +use std::collections::HashMap; +use std::net::{IpAddr, SocketAddr}; #[derive(Debug, Eq, Hash, PartialEq)] pub struct FieldHash { @@ -28,7 +28,6 @@ pub struct Directive { pub index: usize, } - #[derive(Clone, Debug)] pub enum Definition { Interface(InterfaceTypeDefinition), @@ -48,7 +47,6 @@ pub struct ObjectTypeDefinition { pub fields: Vec, } - #[derive(Clone, Debug)] pub struct InterfaceTypeDefinition { pub name: String, @@ -70,11 +68,17 @@ pub struct InputFieldDefinition { pub of_type: Type, } - #[derive(Debug)] pub struct Server { + pub host: IpAddr, pub port: u16, } + +impl Server { + pub fn addr(&self) -> SocketAddr { + SocketAddr::new(self.host, self.port) + } +} #[derive(Debug)] pub struct Upstream { pub base_url: Option, @@ -84,12 +88,17 @@ impl TryFrom<&Config> for Blueprint { type Error = anyhow::Error; fn try_from(config: &Config) -> Result { - let qry = config.schema.query.as_ref().ok_or(anyhow::anyhow!("Query not found"))?; + let qry = config + .schema + .query + .as_ref() + .ok_or(anyhow::anyhow!("Query not found"))?; let defs = to_definitions(config)?; let fields = fields_to_map(qry, config, defs); let server = Server { + host: IpAddr::from([127, 0, 0, 1]), port: config.server.port, }; let upstream = Upstream { @@ -129,34 +138,45 @@ fn populate_nested_field( type_of: field.ty_of.clone(), ir: { let x = defs.iter().find_map(|def| match def { - Definition::Interface(int) => { - Some(int.fields.iter().find(|f| field_name.0.eq(&f.name))?.clone()) - } - Definition::Object(obj) => { - Some(obj.fields.iter().find(|f| field_name.0.eq(&f.name))?.clone()) - } - Definition::InputObject(_) => { - None - } + Definition::Interface(int) => Some( + int.fields + .iter() + .find(|f| field_name.0.eq(&f.name))? + .clone(), + ), + Definition::Object(obj) => Some( + obj.fields + .iter() + .find(|f| field_name.0.eq(&f.name))? + .clone(), + ), + Definition::InputObject(_) => None, }); x.and_then(|x| x.resolver.clone()) }, - args: field.args.iter().map(|(arg_name, arg)| { - let arg = Arg { - id: ArgId::new(arg_id), - name: arg_name.clone(), - type_of: arg.type_of.clone(), - }; - arg_id += 1; - - arg - }).collect(), + args: field + .args + .iter() + .map(|(arg_name, arg)| { + let arg = Arg { + id: ArgId::new(arg_id), + name: arg_name.clone(), + type_of: arg.type_of.clone(), + }; + arg_id += 1; + + arg + }) + .collect(), }; - field_map.insert(FieldHash { - name: field_name, - id: TypeName(ty_name.to_string()), - }, field); + field_map.insert( + FieldHash { + name: field_name, + id: TypeName(ty_name.to_string()), + }, + field, + ); } } } @@ -169,8 +189,10 @@ mod test { fn test() { let reader = ConfigReader::init(); let root = env!("CARGO_MANIFEST_DIR"); - let config = reader.read(format!("{}/schema/schema.graphql", root)).unwrap(); + let config = reader + .read(format!("{}/schema/schema.graphql", root)) + .unwrap(); let blueprint = crate::blueprint::Blueprint::try_from(&config).unwrap(); // println!("{:#?}", blueprint); } -} \ No newline at end of file +} diff --git a/projects/ssddOnTop/src/blueprint/definitions.rs b/projects/ssddOnTop/src/blueprint/definitions.rs index 8395835..b38f231 100644 --- a/projects/ssddOnTop/src/blueprint/definitions.rs +++ b/projects/ssddOnTop/src/blueprint/definitions.rs @@ -1,54 +1,54 @@ use crate::blueprint::operators::http::update_http; -use crate::blueprint::{Definition, FieldDefinition, InputFieldDefinition, InputObjectTypeDefinition, InterfaceTypeDefinition, ObjectTypeDefinition}; +use crate::blueprint::{ + Definition, FieldDefinition, InputFieldDefinition, InputObjectTypeDefinition, + InterfaceTypeDefinition, ObjectTypeDefinition, +}; use crate::config; use crate::config::Config; pub fn to_definitions(config: &Config) -> anyhow::Result> { let mut definitions = vec![]; for (ty_name, ty) in config.types.iter() { - let def = to_object_type_definition(ty_name, ty, config).and_then(|definition| match definition { - Definition::Object(_) => { - Ok(definition) - /*if config.input_types().contains(ty_name) { - to_input_object_type_definition(object_type_definition) - } else if config.interface_types().contains(ty_name) { - to_interface_type_definition(object_type_definition) - } else { - Ok(definition) - }*/ - } - _ => Ok(definition), - })?; + let def = + to_object_type_definition(ty_name, ty, config).and_then( + |definition| match definition { + Definition::Object(_) => { + Ok(definition) + /*if config.input_types().contains(ty_name) { + to_input_object_type_definition(object_type_definition) + } else if config.interface_types().contains(ty_name) { + to_interface_type_definition(object_type_definition) + } else { + Ok(definition) + }*/ + } + _ => Ok(definition), + }, + )?; definitions.push(def); } Ok(definitions) } fn to_interface_type_definition(definition: ObjectTypeDefinition) -> anyhow::Result { - Ok( - Definition::Interface(InterfaceTypeDefinition { - name: definition.name, - fields: definition.fields, - }) - ) + Ok(Definition::Interface(InterfaceTypeDefinition { + name: definition.name, + fields: definition.fields, + })) } -fn to_input_object_type_definition( - definition: ObjectTypeDefinition, -) -> anyhow::Result { - Ok( - Definition::InputObject(InputObjectTypeDefinition { - name: definition.name, - fields: definition - .fields - .iter() - .map(|field| InputFieldDefinition { - name: field.name.clone(), - of_type: field.of_type.clone(), - }) - .collect(), - }) - ) +fn to_input_object_type_definition(definition: ObjectTypeDefinition) -> anyhow::Result { + Ok(Definition::InputObject(InputObjectTypeDefinition { + name: definition.name, + fields: definition + .fields + .iter() + .map(|field| InputFieldDefinition { + name: field.name.clone(), + of_type: field.of_type.clone(), + }) + .collect(), + })) } fn to_object_type_definition( @@ -84,7 +84,6 @@ fn to_fields( Ok(fields) } - fn to_field_definition( field_name: &str, field: &config::Field, @@ -101,13 +100,17 @@ fn update_args( field: config::Field, mut def: FieldDefinition, ) -> FieldDefinition { - let args = field.args.iter().map(|(name, arg)| { - let arg = InputFieldDefinition { - name: name.clone(), - of_type: arg.type_of.clone(), - }; - arg - }).collect::>(); + let args = field + .args + .iter() + .map(|(name, arg)| { + let arg = InputFieldDefinition { + name: name.clone(), + of_type: arg.type_of.clone(), + }; + arg + }) + .collect::>(); def.name = field_name.to_string(); def.args = args; diff --git a/projects/ssddOnTop/src/blueprint/mod.rs b/projects/ssddOnTop/src/blueprint/mod.rs index edce276..1d66931 100644 --- a/projects/ssddOnTop/src/blueprint/mod.rs +++ b/projects/ssddOnTop/src/blueprint/mod.rs @@ -1,7 +1,7 @@ -pub mod wrapping_type; mod blueprint; -mod model; mod definitions; +mod model; mod operators; +pub mod wrapping_type; -pub use blueprint::*; \ No newline at end of file +pub use blueprint::*; diff --git a/projects/ssddOnTop/src/blueprint/model.rs b/projects/ssddOnTop/src/blueprint/model.rs index f423ef9..b4c4e6c 100644 --- a/projects/ssddOnTop/src/blueprint/model.rs +++ b/projects/ssddOnTop/src/blueprint/model.rs @@ -1,5 +1,5 @@ -use std::fmt::{Debug, Formatter}; use crate::ir::IR; +use std::fmt::{Debug, Formatter}; #[derive(Clone, Debug, Eq, Hash, PartialEq)] pub struct FieldName(pub String); @@ -59,4 +59,4 @@ pub struct Field { pub type_of: crate::blueprint::wrapping_type::Type, pub ir: Option, pub args: Vec, -} \ No newline at end of file +} diff --git a/projects/ssddOnTop/src/blueprint/operators/http.rs b/projects/ssddOnTop/src/blueprint/operators/http.rs index 984642d..c2d2e57 100644 --- a/projects/ssddOnTop/src/blueprint/operators/http.rs +++ b/projects/ssddOnTop/src/blueprint/operators/http.rs @@ -1,23 +1,20 @@ -use crate::http::method::Method; use crate::blueprint::FieldDefinition; use crate::config; use crate::config::Resolver; use crate::endpoint::Endpoint; +use crate::http::method::Method; use crate::http::RequestTemplate; use crate::ir::{IO, IR}; use crate::mustache::model::Mustache; -fn compile_http( - config_module: &config::Config, - http: &config::Http, -) -> anyhow::Result { +fn compile_http(config_module: &config::Config, http: &config::Http) -> anyhow::Result { let mut base_url = String::new(); if let Some(base) = http.base_url.clone() { base_url = base; - }else { + } else { if let Some(base) = config_module.upstream.base_url.clone() { base_url = base; - }else { + } else { return Err(anyhow::anyhow!("No base URL defined")); } } @@ -37,10 +34,10 @@ fn compile_http( }) .collect(); - let req_template = RequestTemplate::try_from( + let req_template = RequestTemplate::try_from( Endpoint::new(base_url.to_string()) .method(http.method.clone()) - .query(query) + .query(query), )?; let ir = if http.method == Method::GET { @@ -55,7 +52,10 @@ fn compile_http( dl_id: None, }) } else { - IR::IO(IO::Http { req_template, dl_id: None }) + IR::IO(IO::Http { + req_template, + dl_id: None, + }) }; Ok(ir) diff --git a/projects/ssddOnTop/src/blueprint/operators/mod.rs b/projects/ssddOnTop/src/blueprint/operators/mod.rs index e05256f..3883215 100644 --- a/projects/ssddOnTop/src/blueprint/operators/mod.rs +++ b/projects/ssddOnTop/src/blueprint/operators/mod.rs @@ -1 +1 @@ -pub mod http; \ No newline at end of file +pub mod http; diff --git a/projects/ssddOnTop/src/blueprint/wrapping_type.rs b/projects/ssddOnTop/src/blueprint/wrapping_type.rs index fa693b5..87c9792 100644 --- a/projects/ssddOnTop/src/blueprint/wrapping_type.rs +++ b/projects/ssddOnTop/src/blueprint/wrapping_type.rs @@ -52,7 +52,10 @@ impl std::fmt::Debug for Type { impl Default for Type { fn default() -> Self { - Type::Named { name: "JSON".to_string(), non_null: false } + Type::Named { + name: "JSON".to_string(), + non_null: false, + } } } @@ -80,22 +83,37 @@ impl Type { /// convert this type into NonNull type pub fn into_required(self) -> Self { match self { - Type::Named { name, .. } => Self::Named { name, non_null: true }, - Type::List { of_type, .. } => Self::List { of_type, non_null: true }, + Type::Named { name, .. } => Self::Named { + name, + non_null: true, + }, + Type::List { of_type, .. } => Self::List { + of_type, + non_null: true, + }, } } /// convert this into nullable type pub fn into_nullable(self) -> Self { match self { - Type::Named { name, .. } => Self::Named { name, non_null: false }, - Type::List { of_type, .. } => Self::List { of_type, non_null: false }, + Type::Named { name, .. } => Self::Named { + name, + non_null: false, + }, + Type::List { of_type, .. } => Self::List { + of_type, + non_null: false, + }, } } /// create a nullable list type from this type pub fn into_list(self) -> Self { - Type::List { of_type: Box::new(self), non_null: false } + Type::List { + of_type: Box::new(self), + non_null: false, + } } /// convert this type from list to non-list for any level of nesting @@ -110,9 +128,10 @@ impl Type { pub fn with_name(self, name: String) -> Self { match self { Type::Named { non_null, .. } => Type::Named { name, non_null }, - Type::List { of_type, non_null } => { - Type::List { of_type: Box::new(of_type.with_name(name)), non_null } - } + Type::List { of_type, non_null } => Type::List { + of_type: Box::new(of_type.with_name(name)), + non_null, + }, } } } @@ -122,12 +141,14 @@ impl From<&async_graphql_types::Type> for Type { let non_null = !value.nullable; match &value.base { - async_graphql_types::BaseType::Named(name) => { - Self::Named { name: name.to_string(), non_null } - } - async_graphql_types::BaseType::List(type_) => { - Self::List { of_type: Box::new(type_.as_ref().into()), non_null } - } + async_graphql_types::BaseType::Named(name) => Self::Named { + name: name.to_string(), + non_null, + }, + async_graphql_types::BaseType::List(type_) => Self::List { + of_type: Box::new(type_.as_ref().into()), + non_null, + }, } } } @@ -170,6 +191,9 @@ impl From<&Type> for async_graphql::dynamic::TypeRef { impl From for Type { fn from(value: String) -> Self { - Self::Named { name: value, non_null: false } + Self::Named { + name: value, + non_null: false, + } } } diff --git a/projects/ssddOnTop/src/config/config.rs b/projects/ssddOnTop/src/config/config.rs index 01ab08f..9d288f5 100644 --- a/projects/ssddOnTop/src/config/config.rs +++ b/projects/ssddOnTop/src/config/config.rs @@ -1,10 +1,10 @@ use crate::blueprint::wrapping_type; use crate::config::url_query::URLQuery; +use crate::http::method::Method; use crate::is_default; use serde::{Deserialize, Serialize}; use std::collections::BTreeMap; use std::num::NonZeroU64; -use crate::http::method::Method; #[derive(Serialize, Deserialize, Clone, Debug)] pub struct Config { @@ -23,8 +23,7 @@ pub struct RootSchema { pub subscription: Option, } - -#[derive(Serialize, Deserialize,Clone, Debug)] +#[derive(Serialize, Deserialize, Clone, Debug)] pub struct Server { #[serde(default, skip_serializing_if = "is_default")] pub port: u16, @@ -32,13 +31,11 @@ pub struct Server { impl Default for Server { fn default() -> Self { - Server { - port: 8000, - } + Server { port: 8000 } } } -#[derive(Serialize, Deserialize,Clone, Debug, Default)] +#[derive(Serialize, Deserialize, Clone, Debug, Default)] pub struct Upstream { #[serde(rename = "baseURL", default, skip_serializing_if = "is_default")] pub base_url: Option, @@ -95,7 +92,6 @@ pub struct Http { pub query: Vec, } - #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] pub enum Resolver { Http(Http), @@ -107,4 +103,4 @@ pub enum GraphQLOperationType { #[default] Query, Mutation, -} \ No newline at end of file +} diff --git a/projects/ssddOnTop/src/config/kv.rs b/projects/ssddOnTop/src/config/kv.rs index 2045635..47086f1 100644 --- a/projects/ssddOnTop/src/config/kv.rs +++ b/projects/ssddOnTop/src/config/kv.rs @@ -4,4 +4,4 @@ use serde::{Deserialize, Serialize}; pub struct KeyValue { pub key: String, pub value: String, -} \ No newline at end of file +} diff --git a/projects/ssddOnTop/src/config/mod.rs b/projects/ssddOnTop/src/config/mod.rs index d0bb7de..40505ac 100644 --- a/projects/ssddOnTop/src/config/mod.rs +++ b/projects/ssddOnTop/src/config/mod.rs @@ -1,9 +1,9 @@ mod config; -mod reader; mod kv; +mod reader; mod url_query; pub use config::*; -pub use reader::*; pub use kv::*; -pub use url_query::*; \ No newline at end of file +pub use reader::*; +pub use url_query::*; diff --git a/projects/ssddOnTop/src/config/reader.rs b/projects/ssddOnTop/src/config/reader.rs index 4af7cd1..34eb5aa 100644 --- a/projects/ssddOnTop/src/config/reader.rs +++ b/projects/ssddOnTop/src/config/reader.rs @@ -3,15 +3,11 @@ use crate::config::Config; use std::path::Path; -pub struct ConfigReader { - -} +pub struct ConfigReader {} impl ConfigReader { pub fn init() -> Self { - Self { - - } + Self {} } pub fn read>(&self, path: T) -> anyhow::Result { let sdl = std::fs::read_to_string(path)?; @@ -28,7 +24,9 @@ mod tests { fn test_read() { let root = env!("CARGO_MANIFEST_DIR"); let reader = ConfigReader::init(); - let config = reader.read(format!("{}/schema/schema.graphql",root)).unwrap(); + let config = reader + .read(format!("{}/schema/schema.graphql", root)) + .unwrap(); assert_eq!(config.types.len(), 5); } -} \ No newline at end of file +} diff --git a/projects/ssddOnTop/src/directive.rs b/projects/ssddOnTop/src/directive.rs index 2252908..16eb8c5 100644 --- a/projects/ssddOnTop/src/directive.rs +++ b/projects/ssddOnTop/src/directive.rs @@ -17,7 +17,7 @@ pub trait DirectiveCodec: Sized { format!("@{}", Self::directive_name()) } fn from_directives<'a>( - directives: impl Iterator>, + directives: impl Iterator>, ) -> Result> { for directive in directives { if directive.node.name.node == Self::directive_name() { @@ -49,10 +49,9 @@ impl<'a, A: Deserialize<'a> + Serialize + 'a> DirectiveCodec for A { fn from_directive(directive: &ConstDirective) -> Result { let mut map = Map::new(); - for (k,v) in directive.arguments.iter() { - let (k,v) = serde_json::to_value(&v.node).map(|v| (k.node.as_str().to_string(), v))?; - map.insert(k,v); - + for (k, v) in directive.arguments.iter() { + let (k, v) = serde_json::to_value(&v.node).map(|v| (k.node.as_str().to_string(), v))?; + map.insert(k, v); } Ok(deserialize(Value::Object(map))?) @@ -72,6 +71,9 @@ impl<'a, A: Deserialize<'a> + Serialize + 'a> DirectiveCodec for A { )); } - ConstDirective { name: pos(Name::new(name)), arguments } + ConstDirective { + name: pos(Name::new(name)), + arguments, + } } } diff --git a/projects/ssddOnTop/src/endpoint.rs b/projects/ssddOnTop/src/endpoint.rs index 6b732e8..1935cba 100644 --- a/projects/ssddOnTop/src/endpoint.rs +++ b/projects/ssddOnTop/src/endpoint.rs @@ -1,5 +1,5 @@ -use derive_setters::Setters; use crate::http::method::Method; +use derive_setters::Setters; #[derive(Clone, Debug, Setters)] pub struct Endpoint { diff --git a/projects/ssddOnTop/src/from_doc.rs b/projects/ssddOnTop/src/from_doc.rs index d34dac8..a29e3a5 100644 --- a/projects/ssddOnTop/src/from_doc.rs +++ b/projects/ssddOnTop/src/from_doc.rs @@ -1,7 +1,11 @@ use crate::config::{Arg, Cache, Config, Field, Resolver, RootSchema, Server, Type1, Upstream}; use crate::directive::DirectiveCodec; use anyhow::Result; -use async_graphql::parser::types::{ConstDirective, FieldDefinition, InputObjectType, InputValueDefinition, InterfaceType, ObjectType, SchemaDefinition, ServiceDocument, Type, TypeDefinition, TypeKind, TypeSystemDefinition}; +use async_graphql::parser::types::{ + ConstDirective, FieldDefinition, InputObjectType, InputValueDefinition, InterfaceType, + ObjectType, SchemaDefinition, ServiceDocument, Type, TypeDefinition, TypeKind, + TypeSystemDefinition, +}; use async_graphql::{Name, Positioned}; use std::collections::BTreeMap; @@ -29,7 +33,6 @@ pub fn from_doc(doc: ServiceDocument) -> Result { let upstream = upstream(sd)?; let schema = schema_definition(&doc).map(to_root_schema)?; - Ok(Config { types, upstream, @@ -45,16 +48,16 @@ fn to_root_schema(schema_definition: &SchemaDefinition) -> RootSchema { .as_ref() .map(pos_name_to_string); - RootSchema { query, mutation, subscription } + RootSchema { + query, + mutation, + subscription, + } } fn upstream(schema_definition: &SchemaDefinition) -> Result { - process_schema_directives( - schema_definition, - Upstream::directive_name().as_str(), - ) + process_schema_directives(schema_definition, Upstream::directive_name().as_str()) } - fn schema_definition(doc: &ServiceDocument) -> Result<&SchemaDefinition> { doc.definitions .iter() @@ -82,7 +85,6 @@ fn process_schema_directives( res } - fn pos_name_to_string(pos: &Positioned) -> String { pos.node.to_string() } @@ -94,18 +96,17 @@ fn to_types( for type_definition in type_definitions.iter() { let type_name = pos_name_to_string(&type_definition.node.name); let ty = match type_definition.node.kind.clone() { - TypeKind::Object(object_type) => to_object_type( - &object_type, - &type_definition.node.directives, - ), - TypeKind::Interface(interface_type) => to_object_type( - &interface_type, - &type_definition.node.directives, - ), - TypeKind::InputObject(input_object_type) => to_input_object( - input_object_type, - ), - _ => Err(anyhow::anyhow!("Unsupported type kind: {:?}", type_definition.node.kind)), + TypeKind::Object(object_type) => { + to_object_type(&object_type, &type_definition.node.directives) + } + TypeKind::Interface(interface_type) => { + to_object_type(&interface_type, &type_definition.node.directives) + } + TypeKind::InputObject(input_object_type) => to_input_object(input_object_type), + _ => Err(anyhow::anyhow!( + "Unsupported type kind: {:?}", + type_definition.node.kind + )), }?; map.insert(type_name, ty); @@ -114,13 +115,12 @@ fn to_types( Ok(map) } -fn to_input_object( - input_object_type: InputObjectType, -) -> Result { +fn to_input_object(input_object_type: InputObjectType) -> Result { let fields = to_input_object_fields(&input_object_type.fields)?; - Ok( - Type1 { fields, ..Default::default() } - ) + Ok(Type1 { + fields, + ..Default::default() + }) } fn to_input_object_fields( @@ -130,31 +130,21 @@ fn to_input_object_fields( } fn to_input_object_field(field_definition: &InputValueDefinition) -> Result { - to_common_field( - field_definition, - BTreeMap::new(), - ) + to_common_field(field_definition, BTreeMap::new()) } -fn to_object_type( - object: &T, - directives: &[Positioned], -) -> Result +fn to_object_type(object: &T, directives: &[Positioned]) -> Result where T: ObjectLike, { let fields = object.fields(); - let cache= Cache::from_directives(directives.iter())?; + let cache = Cache::from_directives(directives.iter())?; let fields = to_fields(fields)?; - Ok( - Type1 { fields, cache } - ) + Ok(Type1 { fields, cache }) } -fn to_fields( - fields: &Vec>, -) -> Result> { +fn to_fields(fields: &Vec>) -> Result> { to_fields_inner(fields, to_field) } @@ -180,10 +170,7 @@ fn to_field(field_definition: &FieldDefinition) -> Result { to_common_field(field_definition, to_args(field_definition)) } -fn to_common_field( - field: &F, - args: BTreeMap, -) -> Result +fn to_common_field(field: &F, args: BTreeMap) -> Result where F: FieldLike + HasName, { @@ -191,13 +178,11 @@ where let directives = field.directives(); let resolver = Resolver::from_directives(directives.iter())?; - Ok( - Field { - ty_of: type_of.into(), - args, - resolver, - } - ) + Ok(Field { + ty_of: type_of.into(), + args, + resolver, + }) } fn to_args(field_definition: &FieldDefinition) -> BTreeMap { @@ -212,7 +197,6 @@ fn to_args(field_definition: &FieldDefinition) -> BTreeMap { args } - fn to_arg(input_value_definition: &InputValueDefinition) -> Arg { let type_of = &input_value_definition.ty.node; @@ -222,10 +206,12 @@ fn to_arg(input_value_definition: &InputValueDefinition) -> Arg { } else { None }; - Arg { type_of: type_of.into(), default_value } + Arg { + type_of: type_of.into(), + default_value, + } } - trait HasName { fn name(&self) -> &Positioned; } diff --git a/projects/ssddOnTop/src/hasher.rs b/projects/ssddOnTop/src/hasher.rs index ab4bfa0..f157570 100644 --- a/projects/ssddOnTop/src/hasher.rs +++ b/projects/ssddOnTop/src/hasher.rs @@ -1,5 +1,5 @@ -use std::hash::Hasher; use fxhash::FxHasher; +use std::hash::Hasher; #[derive(Default)] pub struct MyHasher { diff --git a/projects/ssddOnTop/src/helpers/headers.rs b/projects/ssddOnTop/src/helpers/headers.rs index 3940c87..c41d072 100644 --- a/projects/ssddOnTop/src/helpers/headers.rs +++ b/projects/ssddOnTop/src/helpers/headers.rs @@ -1,11 +1,10 @@ -use reqwest::header::HeaderName; -use anyhow::Result; use crate::config::KeyValue; use crate::mustache::model::Mustache; +use anyhow::Result; +use reqwest::header::HeaderName; pub type MustacheHeaders = Vec<(HeaderName, Mustache)>; - pub fn to_mustache_headers(headers: &[KeyValue]) -> Result { let mut ans = vec![]; for key_value in headers { @@ -19,11 +18,11 @@ pub fn to_mustache_headers(headers: &[KeyValue]) -> Result { #[cfg(test)] mod tests { - use anyhow::Result; - use hyper::header::HeaderName; - use crate::config::KeyValue; use super::to_mustache_headers; + use crate::config::KeyValue; use crate::mustache::model::Mustache; + use anyhow::Result; + use hyper::header::HeaderName; #[test] fn valid_headers() -> Result<()> { diff --git a/projects/ssddOnTop/src/helpers/mod.rs b/projects/ssddOnTop/src/helpers/mod.rs index a97581c..7b67a24 100644 --- a/projects/ssddOnTop/src/helpers/mod.rs +++ b/projects/ssddOnTop/src/helpers/mod.rs @@ -1 +1 @@ -pub mod headers; \ No newline at end of file +pub mod headers; diff --git a/projects/ssddOnTop/src/http/method.rs b/projects/ssddOnTop/src/http/method.rs index 1cf5cb1..fe7f49e 100644 --- a/projects/ssddOnTop/src/http/method.rs +++ b/projects/ssddOnTop/src/http/method.rs @@ -1,17 +1,7 @@ use serde::{Deserialize, Serialize}; use strum_macros::Display; -#[derive( - Clone, - Debug, - Serialize, - Deserialize, - PartialEq, - Eq, - Hash, - Default, - Display, -)] +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash, Default, Display)] pub enum Method { #[default] GET, diff --git a/projects/ssddOnTop/src/http/mod.rs b/projects/ssddOnTop/src/http/mod.rs index a2f6ce9..ecb4d3c 100644 --- a/projects/ssddOnTop/src/http/mod.rs +++ b/projects/ssddOnTop/src/http/mod.rs @@ -1,4 +1,6 @@ -mod req_template; pub mod method; +mod req_template; +pub mod request; +pub mod request_handler; -pub use req_template::*; \ No newline at end of file +pub use req_template::*; diff --git a/projects/ssddOnTop/src/http/req_template.rs b/projects/ssddOnTop/src/http/req_template.rs index eb4616a..75d9095 100644 --- a/projects/ssddOnTop/src/http/req_template.rs +++ b/projects/ssddOnTop/src/http/req_template.rs @@ -33,12 +33,11 @@ impl TryFrom for RequestTemplate { }) .collect::>>()?; let method = endpoint.method.clone().to_hyper(); -/* let headers = endpoint - .headers - .iter() - .map(|(k, v)| Ok((k.clone(), Mustache::parse(v.to_str()?)))) - .collect::>>()?;*/ - + /* let headers = endpoint + .headers + .iter() + .map(|(k, v)| Ok((k.clone(), Mustache::parse(v.to_str()?)))) + .collect::>>()?;*/ Ok(Self { root_url: path, @@ -71,4 +70,4 @@ impl TryFrom for RequestTemplate { IoId::new(hasher.finish()) } -}*/ \ No newline at end of file +}*/ diff --git a/projects/ssddOnTop/src/http/request.rs b/projects/ssddOnTop/src/http/request.rs new file mode 100644 index 0000000..9912c42 --- /dev/null +++ b/projects/ssddOnTop/src/http/request.rs @@ -0,0 +1,23 @@ +use http_body_util::BodyExt; +use hyper::body::Incoming; + +pub struct Request { + pub method: hyper::Method, + pub url: hyper::Uri, + pub headers: hyper::HeaderMap, + pub body: bytes::Bytes, +} + +impl Request { + pub async fn from_hyper(req: hyper::Request) -> anyhow::Result { + let (part, body) = req.into_parts(); + let body = body.collect().await?.to_bytes(); + + Ok(Self { + method: part.method, + url: part.uri, + headers: part.headers, + body, + }) + } +} diff --git a/projects/ssddOnTop/src/http/request_handler.rs b/projects/ssddOnTop/src/http/request_handler.rs new file mode 100644 index 0000000..805b956 --- /dev/null +++ b/projects/ssddOnTop/src/http/request_handler.rs @@ -0,0 +1,14 @@ +use crate::blueprint::Blueprint; +use crate::http::request::Request; +use bytes::Bytes; +use http_body_util::Full; +use std::sync::Arc; + +pub async fn handle_request( + req: Request, + blueprint: Arc, +) -> anyhow::Result>> { + Ok(hyper::Response::new(Full::new(Bytes::from_static( + b"Hello, World!", + )))) +} diff --git a/projects/ssddOnTop/src/ir/discriminator.rs b/projects/ssddOnTop/src/ir/discriminator.rs index c9c47c2..a19b96c 100644 --- a/projects/ssddOnTop/src/ir/discriminator.rs +++ b/projects/ssddOnTop/src/ir/discriminator.rs @@ -124,12 +124,10 @@ impl FieldInfo { impl Discriminator { pub fn new(union_name: &str, union_types: &[(&str, &Type1)]) -> Result { if union_types.len() > usize::BITS as usize { - return Err( - anyhow::anyhow!( - "Union {union_name} defines more than {} types that is not supported", + return Err(anyhow::anyhow!( + "Union {union_name} defines more than {} types that is not supported", usize::BITS - ) - ); + )); } let mut types = Vec::with_capacity(union_types.len()); @@ -337,12 +335,12 @@ impl Repr { #[cfg(test)] mod tests { + use super::*; + use crate::blueprint::wrapping_type::Type; + use crate::config::Field; use async_graphql::Value; use serde_json::json; use test_log::test; - use crate::blueprint::wrapping_type::Type; - use crate::config::Field; - use super::*; #[test] fn test_single_distinct_field_optional() { @@ -393,11 +391,17 @@ mod tests { fn test_single_distinct_field_required() { let foo = Type1::default().fields(vec![( "foo", - Field { ty_of: Type::default().into_required(), ..Field::default() }, + Field { + ty_of: Type::default().into_required(), + ..Field::default() + }, )]); let bar = Type1::default().fields(vec![( "bar", - Field { ty_of: Type::default().into_required(), ..Field::default() }, + Field { + ty_of: Type::default().into_required(), + ..Field::default() + }, )]); let types = vec![("Foo", &foo), ("Bar", &bar)]; @@ -445,43 +449,70 @@ mod tests { let a = Type1::default().fields(vec![ ( "a", - Field { ty_of: Type::default().into_required(), ..Field::default() }, + Field { + ty_of: Type::default().into_required(), + ..Field::default() + }, ), ( "ab", - Field { ty_of: Type::default().into_required(), ..Field::default() }, + Field { + ty_of: Type::default().into_required(), + ..Field::default() + }, ), ( "abab", - Field { ty_of: Type::default().into_required(), ..Field::default() }, + Field { + ty_of: Type::default().into_required(), + ..Field::default() + }, ), ]); let b = Type1::default().fields(vec![ ( "b", - Field { ty_of: Type::default().into_required(), ..Field::default() }, + Field { + ty_of: Type::default().into_required(), + ..Field::default() + }, ), ( "ab", - Field { ty_of: Type::default().into_required(), ..Field::default() }, + Field { + ty_of: Type::default().into_required(), + ..Field::default() + }, ), ( "abab", - Field { ty_of: Type::default().into_required(), ..Field::default() }, + Field { + ty_of: Type::default().into_required(), + ..Field::default() + }, ), ( "ac", - Field { ty_of: Type::default().into_required(), ..Field::default() }, + Field { + ty_of: Type::default().into_required(), + ..Field::default() + }, ), ]); let c = Type1::default().fields(vec![ ( "c", - Field { ty_of: Type::default().into_required(), ..Field::default() }, + Field { + ty_of: Type::default().into_required(), + ..Field::default() + }, ), ( "ac", - Field { ty_of: Type::default().into_required(), ..Field::default() }, + Field { + ty_of: Type::default().into_required(), + ..Field::default() + }, ), ]); let types = vec![("A", &a), ("B", &b), ("C", &c)]; @@ -742,72 +773,108 @@ mod tests { ("usual", Field::default()), ( "payload", - Field { ty_of: Type::default().into_required(), ..Field::default() }, + Field { + ty_of: Type::default().into_required(), + ..Field::default() + }, ), ]); let var1_var = Type1::default().fields(vec![ ("usual", Field::default()), ( "command", - Field { ty_of: Type::default().into_required(), ..Field::default() }, + Field { + ty_of: Type::default().into_required(), + ..Field::default() + }, ), ]); let var_var0 = Type1::default().fields(vec![ ("usual", Field::default()), ( "flag", - Field { ty_of: Type::default().into_required(), ..Field::default() }, + Field { + ty_of: Type::default().into_required(), + ..Field::default() + }, ), ]); let var_var1 = Type1::default().fields(vec![ ("usual", Field::default()), ( "optPayload", - Field { ty_of: Type::default().into_required(), ..Field::default() }, + Field { + ty_of: Type::default().into_required(), + ..Field::default() + }, ), ]); let var0_var0 = Type1::default().fields(vec![ ("usual", Field::default()), ( "payload", - Field { ty_of: Type::default().into_required(), ..Field::default() }, + Field { + ty_of: Type::default().into_required(), + ..Field::default() + }, ), ( "flag", - Field { ty_of: Type::default().into_required(), ..Field::default() }, + Field { + ty_of: Type::default().into_required(), + ..Field::default() + }, ), ]); let var1_var0 = Type1::default().fields(vec![ ("usual", Field::default()), ( "command", - Field { ty_of: Type::default().into_required(), ..Field::default() }, + Field { + ty_of: Type::default().into_required(), + ..Field::default() + }, ), ( "flag", - Field { ty_of: Type::default().into_required(), ..Field::default() }, + Field { + ty_of: Type::default().into_required(), + ..Field::default() + }, ), ]); let var0_var1 = Type1::default().fields(vec![ ("usual", Field::default()), ( "payload", - Field { ty_of: Type::default().into_required(), ..Field::default() }, + Field { + ty_of: Type::default().into_required(), + ..Field::default() + }, ), ( "optPayload", - Field { ty_of: Type::default().into_required(), ..Field::default() }, + Field { + ty_of: Type::default().into_required(), + ..Field::default() + }, ), ]); let var1_var1 = Type1::default().fields(vec![ ("usual", Field::default()), ( "command", - Field { ty_of: Type::default().into_required(), ..Field::default() }, + Field { + ty_of: Type::default().into_required(), + ..Field::default() + }, ), ( "optPayload", - Field { ty_of: Type::default().into_required(), ..Field::default() }, + Field { + ty_of: Type::default().into_required(), + ..Field::default() + }, ), ]); let types = vec![ @@ -937,7 +1004,10 @@ mod tests { let type_b = Type1::default().fields(vec![ ( "uniqueB1", - Field { ty_of: Type::default().into_required(), ..Field::default() }, + Field { + ty_of: Type::default().into_required(), + ..Field::default() + }, ), ("common", Field::default()), ]); @@ -950,7 +1020,10 @@ mod tests { ("common", Field::default()), ( "uniqueD2", - Field { ty_of: Type::default().into_required(), ..Field::default() }, + Field { + ty_of: Type::default().into_required(), + ..Field::default() + }, ), ]); @@ -995,7 +1068,7 @@ mod tests { &Value::from_json( json!({ "uniqueD1": "value", "common": 3, "uniqueD2": false }) ) - .unwrap() + .unwrap() ) .unwrap(), "TypeD" @@ -1008,7 +1081,7 @@ mod tests { &Value::from_json( json!({ "uniqueA1": "value", "uniqueB1": true, "common": 4 }) ) - .unwrap() + .unwrap() ) .unwrap(), "TypeA" @@ -1048,7 +1121,10 @@ mod tests { ("field2", Field::default()), ( "field4", - Field { ty_of: Type::default().into_required(), ..Field::default() }, + Field { + ty_of: Type::default().into_required(), + ..Field::default() + }, ), ]); @@ -1094,7 +1170,7 @@ mod tests { &Value::from_json( json!({ "field1": "value", "field2": "value", "field4": "value" }) ) - .unwrap() + .unwrap() ) .unwrap(), "TypeD" @@ -1107,7 +1183,7 @@ mod tests { &Value::from_json( json!({ "field1": "value", "field2": "value", "field3": "value" }) ) - .unwrap() + .unwrap() ) .unwrap_err() .to_string(), @@ -1141,7 +1217,6 @@ mod tests { assert_eq!( Discriminator::new("BigUnion", &union_types) - .unwrap_err() .to_string(), format!( @@ -1155,32 +1230,38 @@ mod tests { #[test] fn test_validation_equal_types() { - let a = - Type1::default().fields(vec![("a", Field::default()), ("b", Field::default())]); + let a = Type1::default().fields(vec![("a", Field::default()), ("b", Field::default())]); let b = Type1::default().fields(vec![ ( "a", - Field { ty_of: Type::default().into_required(), ..Field::default() }, + Field { + ty_of: Type::default().into_required(), + ..Field::default() + }, ), ("b", Field::default()), ]); - let c = - Type1::default().fields(vec![("a", Field::default()), ("b", Field::default())]); + let c = Type1::default().fields(vec![("a", Field::default()), ("b", Field::default())]); let d = Type1::default().fields(vec![ ("a", Field::default()), ("b", Field::default()), ( "c", - Field { ty_of: Type::default().into_required(), ..Field::default() }, + Field { + ty_of: Type::default().into_required(), + ..Field::default() + }, ), ]); - let e = - Type1::default().fields(vec![("c", Field::default()), ("d", Field::default())]); + let e = Type1::default().fields(vec![("c", Field::default()), ("d", Field::default())]); let f = Type1::default().fields(vec![ ("c", Field::default()), ( "d", - Field { ty_of: Type::default().into_required(), ..Field::default() }, + Field { + ty_of: Type::default().into_required(), + ..Field::default() + }, ), ]); @@ -1194,10 +1275,7 @@ mod tests { ]; assert_eq!( - Discriminator::new("Test", &types) - - .unwrap_err() - .to_string(), + Discriminator::new("Test", &types).unwrap_err().to_string(), "Validation Error • Union have equal types: A == B == C [Test] • Union have equal types: E == F [Test] diff --git a/projects/ssddOnTop/src/ir/mod.rs b/projects/ssddOnTop/src/ir/mod.rs index f25bd69..90a9ec9 100644 --- a/projects/ssddOnTop/src/ir/mod.rs +++ b/projects/ssddOnTop/src/ir/mod.rs @@ -1,5 +1,5 @@ -mod model; mod discriminator; +mod model; -pub use model::*; pub use discriminator::*; +pub use model::*; diff --git a/projects/ssddOnTop/src/ir/model.rs b/projects/ssddOnTop/src/ir/model.rs index bfa15da..fc8d49d 100644 --- a/projects/ssddOnTop/src/ir/model.rs +++ b/projects/ssddOnTop/src/ir/model.rs @@ -1,5 +1,5 @@ -use std::num::NonZeroU64; use crate::http; +use std::num::NonZeroU64; // use crate::jit::eval_ctx::EvalContext; #[derive(Clone, Debug)] @@ -45,7 +45,7 @@ pub enum IO { Http { req_template: http::RequestTemplate, dl_id: Option, - } + }, } /*impl<'a> IO { @@ -54,4 +54,4 @@ pub enum IO { IO::Http { req_template, .. } => req_template.cache_key(ctx), } } -}*/ \ No newline at end of file +}*/ diff --git a/projects/ssddOnTop/src/lib.rs b/projects/ssddOnTop/src/lib.rs index 67bb506..869c716 100644 --- a/projects/ssddOnTop/src/lib.rs +++ b/projects/ssddOnTop/src/lib.rs @@ -1,16 +1,17 @@ -mod config; -mod from_doc; mod blueprint; -mod mustache; +mod config; mod directive; -mod http; +mod endpoint; +mod from_doc; +mod hasher; mod helpers; +mod http; mod ir; mod json; +mod mustache; mod path; -mod hasher; +pub mod run; mod value; -mod endpoint; pub fn is_default(val: &T) -> bool { *val == T::default() diff --git a/projects/ssddOnTop/src/main.rs b/projects/ssddOnTop/src/main.rs index b7d0cf2..beb722b 100644 --- a/projects/ssddOnTop/src/main.rs +++ b/projects/ssddOnTop/src/main.rs @@ -4,8 +4,6 @@ fn main() -> anyhow::Result<()> { .worker_threads(num_cpus::get()) .enable_all() .build()?; - rt.block_on(async { - tracing::info!("{}",num_cpus::get()); - }); + rt.block_on(ssddOnTop::run::run())?; Ok(()) } diff --git a/projects/ssddOnTop/src/mustache/eval.rs b/projects/ssddOnTop/src/mustache/eval.rs index 1e1b443..74939b7 100644 --- a/projects/ssddOnTop/src/mustache/eval.rs +++ b/projects/ssddOnTop/src/mustache/eval.rs @@ -99,7 +99,7 @@ impl Mustache { PathStringEval::new().eval(self, value) } -/* pub fn render_graphql(&self, value: &impl PathGraphql) -> String { + /* pub fn render_graphql(&self, value: &impl PathGraphql) -> String { PathGraphqlEval::new().eval(self, value) }*/ } diff --git a/projects/ssddOnTop/src/mustache/mod.rs b/projects/ssddOnTop/src/mustache/mod.rs index fd012f3..2cd3ff7 100644 --- a/projects/ssddOnTop/src/mustache/mod.rs +++ b/projects/ssddOnTop/src/mustache/mod.rs @@ -1,3 +1,3 @@ +mod eval; pub mod model; pub mod parse; -mod eval; \ No newline at end of file diff --git a/projects/ssddOnTop/src/mustache/parse.rs b/projects/ssddOnTop/src/mustache/parse.rs index 0b2eb99..d6982c0 100644 --- a/projects/ssddOnTop/src/mustache/parse.rs +++ b/projects/ssddOnTop/src/mustache/parse.rs @@ -1,3 +1,5 @@ +use super::*; +use crate::mustache::model::{Mustache, Segment}; use nom::branch::alt; use nom::bytes::complete::{tag, take_until}; use nom::character::complete::char; @@ -5,8 +7,6 @@ use nom::combinator::map; use nom::multi::many0; use nom::sequence::delimited; use nom::{Finish, IResult}; -use crate::mustache::model::{Mustache, Segment}; -use super::*; impl Mustache { // TODO: infallible function, no need to return Result diff --git a/projects/ssddOnTop/src/run/http1.rs b/projects/ssddOnTop/src/run/http1.rs new file mode 100644 index 0000000..60146be --- /dev/null +++ b/projects/ssddOnTop/src/run/http1.rs @@ -0,0 +1,47 @@ +use crate::blueprint::{Blueprint, Server}; +use crate::http::request_handler::handle_request; +use hyper::service::service_fn; +use std::net::SocketAddr; +use std::sync::Arc; +use tokio::net::TcpListener; +use tokio::sync::oneshot; + +pub async fn start(blueprint: Blueprint) -> anyhow::Result<()> { + let blueprint = Arc::new(blueprint); + let addr = blueprint.server.addr(); + let listener = TcpListener::bind(addr).await?; + + tracing::info!("Listening on: http://{}", addr); + loop { + let blueprint = blueprint.clone(); + + let stream_result = listener.accept().await; + match stream_result { + Ok((stream, _)) => { + let io = hyper_util::rt::TokioIo::new(stream); + tokio::spawn(async move { + let blueprint = blueprint.clone(); + + let server = hyper::server::conn::http1::Builder::new() + .serve_connection( + io, + service_fn(move |req| { + let blueprint = blueprint.clone(); + + async move { + let req = + crate::http::request::Request::from_hyper(req).await?; + handle_request(req, blueprint).await + } + }), + ) + .await; + if let Err(e) = server { + tracing::error!("An error occurred while handling a request: {e}"); + } + }); + } + Err(e) => tracing::error!("An error occurred while handling request: {e}"), + } + } +} diff --git a/projects/ssddOnTop/src/run/mod.rs b/projects/ssddOnTop/src/run/mod.rs new file mode 100644 index 0000000..e57406b --- /dev/null +++ b/projects/ssddOnTop/src/run/mod.rs @@ -0,0 +1,4 @@ +mod http1; +mod run; + +pub use run::*; diff --git a/projects/ssddOnTop/src/run/run.rs b/projects/ssddOnTop/src/run/run.rs new file mode 100644 index 0000000..b76918a --- /dev/null +++ b/projects/ssddOnTop/src/run/run.rs @@ -0,0 +1,17 @@ +use crate::blueprint::Blueprint; +use crate::config::ConfigReader; +use crate::run; + +pub async fn run() -> anyhow::Result<()> { + let config_reader = ConfigReader::init(); + let path = std::env::args().into_iter().collect::>(); + let path = path.get(1).cloned().unwrap_or({ + let root = env!("CARGO_MANIFEST_DIR"); + format!("{}/schema/schema.graphql", root) + }); + + let config = config_reader.read(path)?; + let blueprint = Blueprint::try_from(&config)?; + run::http1::start(blueprint).await?; + Ok(()) +} diff --git a/projects/ssddOnTop/src/value/mod.rs b/projects/ssddOnTop/src/value/mod.rs index 5ca2c1d..a2c21a2 100644 --- a/projects/ssddOnTop/src/value/mod.rs +++ b/projects/ssddOnTop/src/value/mod.rs @@ -1,3 +1,3 @@ mod value; -pub use value::*; \ No newline at end of file +pub use value::*; diff --git a/projects/ssddOnTop/src/value/value.rs b/projects/ssddOnTop/src/value/value.rs index 04b50bb..651ad37 100644 --- a/projects/ssddOnTop/src/value/value.rs +++ b/projects/ssddOnTop/src/value/value.rs @@ -15,5 +15,7 @@ impl Value { } fn extend_lifetime<'b>(r: serde_json_borrow::Value<'b>) -> serde_json_borrow::Value<'static> { - unsafe { std::mem::transmute::, serde_json_borrow::Value<'static>>(r) } -} \ No newline at end of file + unsafe { + std::mem::transmute::, serde_json_borrow::Value<'static>>(r) + } +} diff --git a/src/bin/generate-mocks.rs b/src/bin/generate-mocks.rs index b7399f7..7909dd2 100644 --- a/src/bin/generate-mocks.rs +++ b/src/bin/generate-mocks.rs @@ -1,4 +1,7 @@ -use std::{fs, sync::{Arc, Mutex}}; +use std::{ + fs, + sync::{Arc, Mutex}, +}; use anyhow::Result; use mock_json::{mock, registry, MockFn}; @@ -74,7 +77,7 @@ fn main() -> Result<()> { generate(&template, 1)?; ordered_number_mock.reset(); - generate(&template, 2)?; + generate(&template, 2)?; ordered_number_mock.reset(); generate(&template, 3)?; From 99a270d9f4513a85334e50185496a2a8c4ed35b5 Mon Sep 17 00:00:00 2001 From: Sandipsinh Rathod Date: Wed, 11 Sep 2024 16:59:37 -0400 Subject: [PATCH 04/21] add target rt --- Cargo.lock | 1125 ++++++++++++++++- projects/ssddOnTop/Cargo.toml | 16 +- projects/ssddOnTop/src/app_ctx.rs | 16 + projects/ssddOnTop/src/blueprint/blueprint.rs | 6 +- projects/ssddOnTop/src/cache.rs | 197 +++ projects/ssddOnTop/src/config/config.rs | 2 + projects/ssddOnTop/src/helpers/headers.rs | 2 +- projects/ssddOnTop/src/http/method.rs | 17 + projects/ssddOnTop/src/http/req_template.rs | 3 +- projects/ssddOnTop/src/http/request.rs | 5 +- .../ssddOnTop/src/http/request_handler.rs | 27 +- projects/ssddOnTop/src/lib.rs | 3 + projects/ssddOnTop/src/request_context.rs | 166 +++ projects/ssddOnTop/src/target_runtime.rs | 111 ++ 14 files changed, 1633 insertions(+), 63 deletions(-) create mode 100644 projects/ssddOnTop/src/app_ctx.rs create mode 100644 projects/ssddOnTop/src/cache.rs create mode 100644 projects/ssddOnTop/src/request_context.rs create mode 100644 projects/ssddOnTop/src/target_runtime.rs diff --git a/Cargo.lock b/Cargo.lock index 6b07a72..2c37e86 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -112,6 +112,57 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71938f30533e4d95a6d17aa530939da3842c2ab6f4f84b9dae68447e4129f74a" +[[package]] +name = "async-channel" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81953c529336010edd6d8e358f886d9581267795c61b19475b71314bffa46d35" +dependencies = [ + "concurrent-queue", + "event-listener 2.5.3", + "futures-core", +] + +[[package]] +name = "async-channel" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89b47800b0be77592da0afd425cc03468052844aff33b84e33cc696f64e77b6a" +dependencies = [ + "concurrent-queue", + "event-listener-strategy", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-executor" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7ebdfa2ebdab6b1760375fa7d6f382b9f486eac35fc994625a00e89280bdbb7" +dependencies = [ + "async-task", + "concurrent-queue", + "fastrand 2.1.1", + "futures-lite 2.3.0", + "slab", +] + +[[package]] +name = "async-global-executor" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05b1b633a2115cd122d73b955eadd9916c18c8f510ec9cd1686404c60ad1c29c" +dependencies = [ + "async-channel 2.3.1", + "async-executor", + "async-io 2.3.4", + "async-lock 3.4.0", + "blocking", + "futures-lite 2.3.0", + "once_cell", +] + [[package]] name = "async-graphql" version = "7.0.9" @@ -123,14 +174,14 @@ dependencies = [ "async-graphql-value", "async-stream", "async-trait", - "base64", + "base64 0.22.1", "bytes", "fast_chemail", "fnv", "futures-timer", "futures-util", "handlebars", - "http", + "http 1.1.0", "indexmap", "mime", "multer", @@ -187,6 +238,127 @@ dependencies = [ "serde_json", ] +[[package]] +name = "async-io" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fc5b45d93ef0529756f812ca52e44c221b35341892d3dcc34132ac02f3dd2af" +dependencies = [ + "async-lock 2.8.0", + "autocfg", + "cfg-if", + "concurrent-queue", + "futures-lite 1.13.0", + "log", + "parking", + "polling 2.8.0", + "rustix 0.37.27", + "slab", + "socket2 0.4.10", + "waker-fn", +] + +[[package]] +name = "async-io" +version = "2.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "444b0228950ee6501b3568d3c93bf1176a1fdbc3b758dcd9475046d30f4dc7e8" +dependencies = [ + "async-lock 3.4.0", + "cfg-if", + "concurrent-queue", + "futures-io", + "futures-lite 2.3.0", + "parking", + "polling 3.7.3", + "rustix 0.38.35", + "slab", + "tracing", + "windows-sys 0.59.0", +] + +[[package]] +name = "async-lock" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "287272293e9d8c41773cec55e365490fe034813a2f172f502d6ddcf75b2f582b" +dependencies = [ + "event-listener 2.5.3", +] + +[[package]] +name = "async-lock" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff6e472cdea888a4bd64f342f09b3f50e1886d32afe8df3d663c01140b811b18" +dependencies = [ + "event-listener 5.3.1", + "event-listener-strategy", + "pin-project-lite", +] + +[[package]] +name = "async-process" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea6438ba0a08d81529c69b36700fa2f95837bfe3e776ab39cde9c14d9149da88" +dependencies = [ + "async-io 1.13.0", + "async-lock 2.8.0", + "async-signal", + "blocking", + "cfg-if", + "event-listener 3.1.0", + "futures-lite 1.13.0", + "rustix 0.38.35", + "windows-sys 0.48.0", +] + +[[package]] +name = "async-signal" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "637e00349800c0bdf8bfc21ebbc0b6524abea702b0da4168ac00d070d0c0b9f3" +dependencies = [ + "async-io 2.3.4", + "async-lock 3.4.0", + "atomic-waker", + "cfg-if", + "futures-core", + "futures-io", + "rustix 0.38.35", + "signal-hook-registry", + "slab", + "windows-sys 0.59.0", +] + +[[package]] +name = "async-std" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62565bb4402e926b29953c785397c6dc0391b7b446e45008b0049eb43cec6f5d" +dependencies = [ + "async-channel 1.9.0", + "async-global-executor", + "async-io 1.13.0", + "async-lock 2.8.0", + "async-process", + "crossbeam-utils", + "futures-channel", + "futures-core", + "futures-io", + "futures-lite 1.13.0", + "gloo-timers", + "kv-log-macro", + "log", + "memchr", + "once_cell", + "pin-project-lite", + "pin-utils", + "slab", + "wasm-bindgen-futures", +] + [[package]] name = "async-stream" version = "0.3.5" @@ -209,11 +381,17 @@ dependencies = [ "syn", ] +[[package]] +name = "async-task" +version = "4.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de" + [[package]] name = "async-trait" -version = "0.1.81" +version = "0.1.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107" +checksum = "a27b8a3a6e1a44fa4c8baf1f653e4172e81486d4941f2237e20dc2d0cf4ddff1" dependencies = [ "proc-macro2", "quote", @@ -242,10 +420,10 @@ dependencies = [ "axum-core", "bytes", "futures-util", - "http", - "http-body", + "http 1.1.0", + "http-body 1.0.1", "http-body-util", - "hyper", + "hyper 1.4.1", "hyper-util", "itoa", "matchit", @@ -275,8 +453,8 @@ dependencies = [ "async-trait", "bytes", "futures-util", - "http", - "http-body", + "http 1.1.0", + "http-body 1.0.1", "http-body-util", "mime", "pin-project-lite", @@ -302,12 +480,33 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + [[package]] name = "base64" version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + [[package]] name = "bitflags" version = "2.6.0" @@ -323,6 +522,19 @@ dependencies = [ "generic-array", ] +[[package]] +name = "blocking" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "703f41c54fc768e63e091340b424302bb1c29ef4aa0c7f10fe849dfb114d29ea" +dependencies = [ + "async-channel 2.3.1", + "async-task", + "futures-io", + "futures-lite 2.3.0", + "piper", +] + [[package]] name = "bumpalo" version = "3.16.0" @@ -344,6 +556,32 @@ dependencies = [ "serde", ] +[[package]] +name = "cacache" +version = "12.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "142316461ed3a3dfcba10417317472da5bfd0461e4d276bf7c07b330766d9490" +dependencies = [ + "async-std", + "digest", + "either", + "futures", + "hex", + "libc", + "memmap2", + "miette", + "reflink-copy", + "serde", + "serde_derive", + "serde_json", + "sha1", + "sha2", + "ssri", + "tempfile", + "thiserror", + "walkdir", +] + [[package]] name = "cc" version = "1.1.15" @@ -441,6 +679,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "concurrent-queue" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "convert_case" version = "0.4.0" @@ -481,6 +728,24 @@ dependencies = [ "libc", ] +[[package]] +name = "crossbeam-channel" +version = "0.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33480d6946193aa8033910124896ca395333cae7e2d1113d1fef6c3272217df2" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "crossbeam-utils" version = "0.8.20" @@ -545,6 +810,15 @@ dependencies = [ "parking_lot_core", ] +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", +] + [[package]] name = "derive-getters" version = "0.5.0" @@ -670,6 +944,44 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "event-listener" +version = "2.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" + +[[package]] +name = "event-listener" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d93877bcde0eb80ca09131a08d23f0a5c18a620b01db137dba666d18cd9b30c2" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite", +] + +[[package]] +name = "event-listener" +version = "5.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6032be9bd27023a771701cc49f9f053c751055f71efb2e0ae5c15809093675ba" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite", +] + +[[package]] +name = "event-listener-strategy" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f214dc438f977e6d4e3500aaa277f5ad94ca83fbbd9b1a15713ce2344ccc5a1" +dependencies = [ + "event-listener 5.3.1", + "pin-project-lite", +] + [[package]] name = "fast_chemail" version = "0.9.6" @@ -679,6 +991,15 @@ dependencies = [ "ascii_utils", ] +[[package]] +name = "fastrand" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" +dependencies = [ + "instant", +] + [[package]] name = "fastrand" version = "2.1.1" @@ -773,6 +1094,34 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" +[[package]] +name = "futures-lite" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce" +dependencies = [ + "fastrand 1.9.0", + "futures-core", + "futures-io", + "memchr", + "parking", + "pin-project-lite", + "waker-fn", +] + +[[package]] +name = "futures-lite" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52527eb5074e35e9339c6b4e8d12600c7128b68fb25dcb9fa9dec18f7c25f3a5" +dependencies = [ + "fastrand 2.1.1", + "futures-core", + "futures-io", + "parking", + "pin-project-lite", +] + [[package]] name = "futures-macro" version = "0.3.30" @@ -856,6 +1205,18 @@ version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" +[[package]] +name = "gloo-timers" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b995a66bb87bebce9a0f4a95aed01daca4872c050bfcb21653361c03bc35e5c" +dependencies = [ + "futures-channel", + "futures-core", + "js-sys", + "wasm-bindgen", +] + [[package]] name = "governor" version = "0.6.3" @@ -876,6 +1237,25 @@ dependencies = [ "spinning_top", ] +[[package]] +name = "h2" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http 0.2.12", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + [[package]] name = "h2" version = "0.4.6" @@ -887,7 +1267,7 @@ dependencies = [ "fnv", "futures-core", "futures-sink", - "http", + "http 1.1.0", "indexmap", "slab", "tokio", @@ -905,7 +1285,7 @@ dependencies = [ "diff_logger", "easy_retry", "mock_json", - "reqwest", + "reqwest 0.12.7", "serde_json", "tokio", "tracing", @@ -944,6 +1324,29 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +[[package]] +name = "hermit-abi" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "http" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + [[package]] name = "http" version = "1.1.0" @@ -955,6 +1358,17 @@ dependencies = [ "itoa", ] +[[package]] +name = "http-body" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" +dependencies = [ + "bytes", + "http 0.2.12", + "pin-project-lite", +] + [[package]] name = "http-body" version = "1.0.1" @@ -962,7 +1376,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ "bytes", - "http", + "http 1.1.0", ] [[package]] @@ -973,11 +1387,69 @@ checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" dependencies = [ "bytes", "futures-util", - "http", - "http-body", + "http 1.1.0", + "http-body 1.0.1", "pin-project-lite", ] +[[package]] +name = "http-cache" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b5ab65432bbdfe8490dfde21d0366353a8d39f2bc24aca0146889f931b0b4b5" +dependencies = [ + "async-trait", + "bincode", + "cacache", + "http 0.2.12", + "http-cache-semantics", + "httpdate", + "moka", + "serde", + "url", +] + +[[package]] +name = "http-cache-reqwest" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8285341ce7e709c56a0f259ff1c789c70edfbaa88acd69d27e4d63980b92dc" +dependencies = [ + "anyhow", + "async-trait", + "http 0.2.12", + "http-cache", + "http-cache-semantics", + "reqwest 0.11.27", + "reqwest-middleware", + "serde", + "task-local-extensions", + "url", +] + +[[package]] +name = "http-cache-semantics" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7aec9f678bca3f4a15194b980f20ed9bfe0dd38e8d298c65c559a93dfbd6380a" +dependencies = [ + "http 0.2.12", + "http-serde", + "reqwest 0.11.27", + "serde", + "time", +] + +[[package]] +name = "http-serde" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f560b665ad9f1572cfcaf034f7fb84338a7ce945216d64a90fd81f046a3caee" +dependencies = [ + "http 0.2.12", + "serde", +] + [[package]] name = "httparse" version = "1.9.4" @@ -990,6 +1462,30 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" +[[package]] +name = "hyper" +version = "0.14.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a152ddd61dfaec7273fe8419ab357f33aee0d914c5f4efbf0d96fa749eea5ec9" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2 0.3.26", + "http 0.2.12", + "http-body 0.4.6", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2 0.5.7", + "tokio", + "tower-service", + "tracing", + "want", +] + [[package]] name = "hyper" version = "1.4.1" @@ -999,9 +1495,9 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", - "http", - "http-body", + "h2 0.4.6", + "http 1.1.0", + "http-body 1.0.1", "httparse", "httpdate", "itoa", @@ -1018,8 +1514,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5ee4be2c948921a1a5320b629c4193916ed787a7f7f293fd3f7f5a6c9de74155" dependencies = [ "futures-util", - "http", - "hyper", + "http 1.1.0", + "hyper 1.4.1", "hyper-util", "rustls", "rustls-pki-types", @@ -1028,6 +1524,19 @@ dependencies = [ "tower-service", ] +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes", + "hyper 0.14.30", + "native-tls", + "tokio", + "tokio-native-tls", +] + [[package]] name = "hyper-tls" version = "0.6.0" @@ -1036,7 +1545,7 @@ checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" dependencies = [ "bytes", "http-body-util", - "hyper", + "hyper 1.4.1", "hyper-util", "native-tls", "tokio", @@ -1053,11 +1562,11 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "http", - "http-body", - "hyper", + "http 1.1.0", + "http-body 1.0.1", + "hyper 1.4.1", "pin-project-lite", - "socket2", + "socket2 0.5.7", "tokio", "tower", "tower-service", @@ -1075,7 +1584,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core", + "windows-core 0.52.0", ] [[package]] @@ -1120,6 +1629,26 @@ dependencies = [ "serde", ] +[[package]] +name = "instant" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "io-lifetimes" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" +dependencies = [ + "hermit-abi 0.3.9", + "libc", + "windows-sys 0.48.0", +] + [[package]] name = "ipnet" version = "2.9.0" @@ -1156,6 +1685,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "kv-log-macro" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" +dependencies = [ + "log", +] + [[package]] name = "lazy_static" version = "1.5.0" @@ -1168,6 +1706,12 @@ version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" +[[package]] +name = "linux-raw-sys" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" + [[package]] name = "linux-raw-sys" version = "0.4.14" @@ -1189,6 +1733,9 @@ name = "log" version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" +dependencies = [ + "value-bag", +] [[package]] name = "matchers" @@ -1211,12 +1758,54 @@ version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +[[package]] +name = "memmap2" +version = "0.5.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83faa42c0a078c393f6b29d5db232d8be22776a891f8f56e5284faee4a20b327" +dependencies = [ + "libc", +] + +[[package]] +name = "miette" +version = "5.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59bb584eaeeab6bd0226ccf3509a69d7936d148cf3d036ad350abe35e8c6856e" +dependencies = [ + "miette-derive", + "once_cell", + "thiserror", + "unicode-width", +] + +[[package]] +name = "miette-derive" +version = "5.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49e7bc1560b95a3c4a25d03de42fe76ca718ab92d1a22a55b9b4cf67b3ae635c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "mime" version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" +[[package]] +name = "mime_guess" +version = "2.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e" +dependencies = [ + "mime", + "unicase", +] + [[package]] name = "minimal-lexical" version = "0.2.1" @@ -1238,7 +1827,7 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" dependencies = [ - "hermit-abi", + "hermit-abi 0.3.9", "libc", "wasi", "windows-sys 0.52.0", @@ -1271,6 +1860,30 @@ dependencies = [ "serde_json", ] +[[package]] +name = "moka" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32cf62eb4dd975d2dde76432fb1075c49e3ee2331cf36f1f8fd4b66550d32b6f" +dependencies = [ + "async-lock 3.4.0", + "async-trait", + "crossbeam-channel", + "crossbeam-epoch", + "crossbeam-utils", + "event-listener 5.3.1", + "futures-util", + "once_cell", + "parking_lot", + "quanta", + "rustc_version", + "smallvec", + "tagptr", + "thiserror", + "triomphe", + "uuid", +] + [[package]] name = "multer" version = "3.1.0" @@ -1280,7 +1893,7 @@ dependencies = [ "bytes", "encoding_rs", "futures-util", - "http", + "http 1.1.0", "httparse", "memchr", "mime", @@ -1311,7 +1924,7 @@ version = "0.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2eb04e9c688eff1c89d72b407f168cf79bb9e867a9d3323ed6c01519eb9cc053" dependencies = [ - "bitflags", + "bitflags 2.6.0", "cfg-if", "libc", ] @@ -1354,6 +1967,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + [[package]] name = "num-traits" version = "0.2.19" @@ -1369,7 +1988,7 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi", + "hermit-abi 0.3.9", "libc", ] @@ -1394,7 +2013,7 @@ version = "0.10.66" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" dependencies = [ - "bitflags", + "bitflags 2.6.0", "cfg-if", "foreign-types", "libc", @@ -1436,7 +2055,13 @@ dependencies = [ name = "overload" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + +[[package]] +name = "parking" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" [[package]] name = "parking_lot" @@ -1544,18 +2169,66 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "piper" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96c8c490f422ef9a4efd2cb5b42b76c8613d7e7dfc1caf667b8a3350a5acc066" +dependencies = [ + "atomic-waker", + "fastrand 2.1.1", + "futures-io", +] + [[package]] name = "pkg-config" version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +[[package]] +name = "polling" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b2d323e8ca7996b3e23126511a523f7e62924d93ecd5ae73b333815b0eb3dce" +dependencies = [ + "autocfg", + "bitflags 1.3.2", + "cfg-if", + "concurrent-queue", + "libc", + "log", + "pin-project-lite", + "windows-sys 0.48.0", +] + +[[package]] +name = "polling" +version = "3.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc2790cd301dec6cd3b7a025e4815cf825724a51c98dccfe6a3e55f05ffb6511" +dependencies = [ + "cfg-if", + "concurrent-queue", + "hermit-abi 0.4.0", + "pin-project-lite", + "rustix 0.38.35", + "tracing", + "windows-sys 0.59.0", +] + [[package]] name = "portable-atomic" version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da544ee218f0d287a911e9c99a39a8c9bc8fcad3cb8db5959940044ecfc67265" +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "ppv-lite86" version = "0.2.20" @@ -1696,7 +2369,7 @@ version = "11.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb9ee317cfe3fbd54b36a511efc1edd42e216903c9cd575e686dd68a2ba90d8d" dependencies = [ - "bitflags", + "bitflags 2.6.0", ] [[package]] @@ -1705,7 +2378,18 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" dependencies = [ - "bitflags", + "bitflags 2.6.0", +] + +[[package]] +name = "reflink-copy" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc31414597d1cd7fdd2422798b7652a6329dda0fe0219e6335a13d5bcaa9aeb6" +dependencies = [ + "cfg-if", + "rustix 0.38.35", + "windows", ] [[package]] @@ -1752,24 +2436,65 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" +[[package]] +name = "reqwest" +version = "0.11.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd67538700a17451e7cba03ac727fb961abb7607553461627b97de0b89cf4a62" +dependencies = [ + "base64 0.21.7", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2 0.3.26", + "http 0.2.12", + "http-body 0.4.6", + "hyper 0.14.30", + "hyper-tls 0.5.0", + "ipnet", + "js-sys", + "log", + "mime", + "mime_guess", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile 1.0.4", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper 0.1.2", + "system-configuration 0.5.1", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", +] + [[package]] name = "reqwest" version = "0.12.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" dependencies = [ - "base64", + "base64 0.22.1", "bytes", "encoding_rs", "futures-core", "futures-util", - "h2", - "http", - "http-body", + "h2 0.4.6", + "http 1.1.0", + "http-body 1.0.1", "http-body-util", - "hyper", + "hyper 1.4.1", "hyper-rustls", - "hyper-tls", + "hyper-tls 0.6.0", "hyper-util", "ipnet", "js-sys", @@ -1779,12 +2504,12 @@ dependencies = [ "once_cell", "percent-encoding", "pin-project-lite", - "rustls-pemfile", + "rustls-pemfile 2.1.3", "serde", "serde_json", "serde_urlencoded", "sync_wrapper 1.0.1", - "system-configuration", + "system-configuration 0.6.1", "tokio", "tokio-native-tls", "tower-service", @@ -1795,6 +2520,21 @@ dependencies = [ "windows-registry", ] +[[package]] +name = "reqwest-middleware" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a735987236a8e238bf0296c7e351b999c188ccc11477f311b82b55c93984216" +dependencies = [ + "anyhow", + "async-trait", + "http 0.2.12", + "reqwest 0.11.27", + "serde", + "task-local-extensions", + "thiserror", +] + [[package]] name = "ring" version = "0.17.8" @@ -1825,16 +2565,30 @@ dependencies = [ "semver", ] +[[package]] +name = "rustix" +version = "0.37.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea8ca367a3a01fe35e6943c400addf443c0f57670e6ec51196f71a4b8762dd2" +dependencies = [ + "bitflags 1.3.2", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys 0.3.8", + "windows-sys 0.48.0", +] + [[package]] name = "rustix" version = "0.38.35" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a85d50532239da68e9addb745ba38ff4612a242c1c7ceea689c4bc7c2f43c36f" dependencies = [ - "bitflags", + "bitflags 2.6.0", "errno", "libc", - "linux-raw-sys", + "linux-raw-sys 0.4.14", "windows-sys 0.52.0", ] @@ -1851,13 +2605,22 @@ dependencies = [ "zeroize", ] +[[package]] +name = "rustls-pemfile" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" +dependencies = [ + "base64 0.21.7", +] + [[package]] name = "rustls-pemfile" version = "2.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "196fe16b00e106300d3e45ecfcb764fa292a535d7326a29a5875c579c7417425" dependencies = [ - "base64", + "base64 0.22.1", "rustls-pki-types", ] @@ -1890,6 +2653,15 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + [[package]] name = "schannel" version = "0.1.23" @@ -1911,7 +2683,7 @@ version = "2.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" dependencies = [ - "bitflags", + "bitflags 2.6.0", "core-foundation", "core-foundation-sys", "libc", @@ -1999,6 +2771,28 @@ dependencies = [ "serde", ] +[[package]] +name = "sha-1" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5058ada175748e33390e40e872bd0fe59a19f265d0158daa551c5a88a76009c" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + [[package]] name = "sha2" version = "0.10.8" @@ -2049,6 +2843,16 @@ version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +[[package]] +name = "socket2" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "socket2" version = "0.5.7" @@ -2081,22 +2885,29 @@ dependencies = [ "anyhow", "async-graphql", "async-graphql-value", + "async-trait", "bytes", "convert_case 0.6.0", "derive-getters", "derive_more", "derive_setters", "fxhash", + "http 1.1.0", "http-body-util", - "hyper", + "http-cache", + "http-cache-reqwest", + "http-cache-semantics", + "hyper 1.4.1", "hyper-util", "indenter", "indexmap", + "moka", "nom", "num_cpus", "pretty_assertions", "prost-reflect", - "reqwest", + "reqwest 0.11.27", + "reqwest-middleware", "serde", "serde_json", "serde_json_borrow", @@ -2106,6 +2917,24 @@ dependencies = [ "tokio", "tracing", "tracing-subscriber", + "url", +] + +[[package]] +name = "ssri" +version = "9.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da7a2b3c2bc9693bcb40870c4e9b5bf0d79f9cb46273321bf855ec513e919082" +dependencies = [ + "base64 0.21.7", + "digest", + "hex", + "miette", + "serde", + "sha-1", + "sha2", + "thiserror", + "xxhash-rust", ] [[package]] @@ -2174,15 +3003,36 @@ dependencies = [ "futures-core", ] +[[package]] +name = "system-configuration" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "system-configuration-sys 0.5.0", +] + [[package]] name = "system-configuration" version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" dependencies = [ - "bitflags", + "bitflags 2.6.0", "core-foundation", - "system-configuration-sys", + "system-configuration-sys 0.6.0", +] + +[[package]] +name = "system-configuration-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" +dependencies = [ + "core-foundation-sys", + "libc", ] [[package]] @@ -2195,6 +3045,21 @@ dependencies = [ "libc", ] +[[package]] +name = "tagptr" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b2093cf4c8eb1e67749a6762251bc9cd836b6fc171623bd0a9d324d37af2417" + +[[package]] +name = "task-local-extensions" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba323866e5d033818e3240feeb9f7db2c4296674e4d9e16b97b7bf8f490434e8" +dependencies = [ + "pin-utils", +] + [[package]] name = "tempfile" version = "3.12.0" @@ -2202,9 +3067,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" dependencies = [ "cfg-if", - "fastrand", + "fastrand 2.1.1", "once_cell", - "rustix", + "rustix 0.38.35", "windows-sys 0.59.0", ] @@ -2260,6 +3125,37 @@ dependencies = [ "once_cell", ] +[[package]] +name = "time" +version = "0.3.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "time-macros" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" +dependencies = [ + "num-conv", + "time-core", +] + [[package]] name = "tinyvec" version = "1.8.0" @@ -2288,7 +3184,7 @@ dependencies = [ "parking_lot", "pin-project-lite", "signal-hook-registry", - "socket2", + "socket2 0.5.7", "tokio-macros", "windows-sys 0.52.0", ] @@ -2392,7 +3288,7 @@ dependencies = [ "axum", "forwarded-header-value", "governor", - "http", + "http 1.1.0", "pin-project", "thiserror", "tower", @@ -2461,6 +3357,12 @@ dependencies = [ "tracing-log", ] +[[package]] +name = "triomphe" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "859eb650cfee7434994602c3a68b25d77ad9e68c8a6cd491616ef86661382eb3" + [[package]] name = "try-lock" version = "0.2.5" @@ -2479,6 +3381,15 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" +[[package]] +name = "unicase" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" +dependencies = [ + "version_check", +] + [[package]] name = "unicode-bidi" version = "0.3.15" @@ -2506,6 +3417,12 @@ version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" +[[package]] +name = "unicode-width" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" + [[package]] name = "untrusted" version = "0.9.0" @@ -2521,6 +3438,7 @@ dependencies = [ "form_urlencoded", "idna", "percent-encoding", + "serde", ] [[package]] @@ -2529,12 +3447,27 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" +[[package]] +name = "uuid" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81dfa00651efa65069b0b6b651f4aaa31ba9e3c3ce0137aaad053604ee7e0314" +dependencies = [ + "getrandom", +] + [[package]] name = "valuable" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[package]] +name = "value-bag" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a84c137d37ab0142f0f2ddfe332651fdbf252e7b7dbb4e67b6c1f1b2e925101" + [[package]] name = "vcpkg" version = "0.2.15" @@ -2547,6 +3480,22 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "waker-fn" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "317211a0dc0ceedd78fb2ca9a44aed3d7b9b26f81870d485c07122b4350673b7" + +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + [[package]] name = "want" version = "0.3.1" @@ -2655,12 +3604,31 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +dependencies = [ + "windows-sys 0.48.0", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd04d41d93c4992d421894c18c8b43496aa748dd4c081bac0dc93eb0489272b6" +dependencies = [ + "windows-core 0.58.0", + "windows-targets 0.52.6", +] + [[package]] name = "windows-core" version = "0.52.0" @@ -2670,6 +3638,41 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-core" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-implement" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -2857,6 +3860,22 @@ dependencies = [ "memchr", ] +[[package]] +name = "winreg" +version = "0.50.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" +dependencies = [ + "cfg-if", + "windows-sys 0.48.0", +] + +[[package]] +name = "xxhash-rust" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a5cbf750400958819fb6178eaa83bee5cd9c29a26a40cc241df8c70fdd46984" + [[package]] name = "yansi" version = "0.5.1" diff --git a/projects/ssddOnTop/Cargo.toml b/projects/ssddOnTop/Cargo.toml index 1c4f73b..5d606f3 100644 --- a/projects/ssddOnTop/Cargo.toml +++ b/projects/ssddOnTop/Cargo.toml @@ -18,7 +18,7 @@ async-graphql-value = "7.0.9" serde_path_to_error = "0.1.16" tracing-subscriber = "0.3.18" num_cpus = "1.16.0" -reqwest = "0.12.7" +reqwest = "0.11" nom = "7.1.3" pretty_assertions = "1.4.0" serde_json_borrow = "0.6.0" @@ -32,3 +32,17 @@ convert_case = "0.6.0" prost-reflect = "0.14.2" fxhash = "0.2.1" strum_macros = "0.26.4" +http-cache-reqwest = { version = "0.13.0", features = [ + "manager-moka", +], default-features = false } +reqwest-middleware = "0.2.5" +http-cache-semantics = { version = "1.0.1", default-features = false, features = ["with_serde", "reqwest"]} +moka = { version = "0.12.7", default-features = false, features = [ + "future", +]} +async-trait = "0.1.82" + +[dev-dependencies] +http-cache = "0.18.0" +url = "2.5.2" +http = "1.1.0" \ No newline at end of file diff --git a/projects/ssddOnTop/src/app_ctx.rs b/projects/ssddOnTop/src/app_ctx.rs new file mode 100644 index 0000000..c5a30fd --- /dev/null +++ b/projects/ssddOnTop/src/app_ctx.rs @@ -0,0 +1,16 @@ +use std::sync::Arc; +use crate::blueprint::Blueprint; +use crate::target_runtime::TargetRuntime; + +#[derive(Clone)] +pub struct AppCtx { + pub runtime: TargetRuntime, + pub blueprint: Arc, +} + +impl AppCtx { + pub fn new(runtime: TargetRuntime, blueprint: Arc) -> Self { + Self { runtime, blueprint } + } + +} \ No newline at end of file diff --git a/projects/ssddOnTop/src/blueprint/blueprint.rs b/projects/ssddOnTop/src/blueprint/blueprint.rs index 4c77966..5f13f45 100644 --- a/projects/ssddOnTop/src/blueprint/blueprint.rs +++ b/projects/ssddOnTop/src/blueprint/blueprint.rs @@ -68,7 +68,7 @@ pub struct InputFieldDefinition { pub of_type: Type, } -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct Server { pub host: IpAddr, pub port: u16, @@ -79,9 +79,10 @@ impl Server { SocketAddr::new(self.host, self.port) } } -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct Upstream { pub base_url: Option, + pub http_cache: u64, } impl TryFrom<&Config> for Blueprint { @@ -103,6 +104,7 @@ impl TryFrom<&Config> for Blueprint { }; let upstream = Upstream { base_url: config.upstream.base_url.clone(), + http_cache: config.upstream.http_cache.unwrap_or(10000), }; Ok(Blueprint { fields, diff --git a/projects/ssddOnTop/src/cache.rs b/projects/ssddOnTop/src/cache.rs new file mode 100644 index 0000000..c06b89c --- /dev/null +++ b/projects/ssddOnTop/src/cache.rs @@ -0,0 +1,197 @@ +use http_cache_reqwest::{CacheManager, HttpResponse}; +use http_cache_semantics::CachePolicy; +use serde::{Deserialize, Serialize}; +use moka::future::Cache; +use moka::policy::EvictionPolicy; +pub type BoxError = Box; +pub type Result = std::result::Result; +use std::sync::Arc; + + +pub struct HttpCacheManager { + pub cache: Arc>, +} + +impl Default for HttpCacheManager { + fn default() -> Self { + Self::new(42) + } +} + +#[derive(Clone, Deserialize, Serialize)] +pub struct Store { + response: HttpResponse, + policy: CachePolicy, +} + +impl HttpCacheManager { + pub fn new(cache_size: u64) -> Self { + let cache = Cache::builder() + .eviction_policy(EvictionPolicy::lru()) + .max_capacity(cache_size) + .build(); + Self { cache: Arc::new(cache) } + } + + pub async fn clear(&self) -> Result<()> { + self.cache.invalidate_all(); + self.cache.run_pending_tasks().await; + Ok(()) + } +} + +#[async_trait::async_trait] +impl CacheManager for HttpCacheManager { + async fn get(&self, cache_key: &str) -> Result> { + let store: Store = match self.cache.get(cache_key).await { + Some(d) => d, + None => return Ok(None), + }; + Ok(Some((store.response, store.policy))) + } + + async fn put( + &self, + cache_key: String, + response: HttpResponse, + policy: CachePolicy, + ) -> Result { + let data = Store { response: response.clone(), policy }; + self.cache.insert(cache_key, data).await; + self.cache.run_pending_tasks().await; + Ok(response) + } + + async fn delete(&self, cache_key: &str) -> Result<()> { + self.cache.invalidate(cache_key).await; + self.cache.run_pending_tasks().await; + Ok(()) + } +} + +/*#[cfg(test)] +mod tests { + use std::collections::HashMap; + use std::str::FromStr; + use http::Response; + use http_cache::HttpVersion; + use reqwest::{Method, ResponseBuilderExt, StatusCode}; + use reqwest::header::HeaderMap; + use url::Url; + + use super::*; + + impl http_cache_semantics::ResponseLike for http::Response { + fn status(&self) -> StatusCode { + StatusCode::from_str(self.status().as_str()).unwrap() + } + + fn headers(&self) -> &HeaderMap { + todo!() + } + } + + fn convert_response(response: HttpResponse) -> Result> { + let ret_res = http::Response::builder() + .status(response.status) + .version( + match response.version { + HttpVersion::Http09 => http::Version::HTTP_09, + HttpVersion::Http10 => http::Version::HTTP_10, + HttpVersion::Http11 => http::Version::HTTP_11, + HttpVersion::H2 => http::Version::HTTP_2, + HttpVersion::H3 => http::Version::HTTP_3, + _ => unreachable!() + } + ) + .body(response.body)?; + let (parts, body) = ret_res.into_parts(); + + Ok(Response::from_parts(parts, bytes::Bytes::from(body))) + } + + async fn insert_key_into_cache(manager: &HttpCacheManager, key: &str) { + let request_url = "http://localhost:8080/test"; + let url = Url::parse(request_url).unwrap(); + + let http_resp = HttpResponse { + headers: HashMap::default(), + body: vec![1, 2, 3], + status: 200, + url: url.clone(), + version: HttpVersion::Http11, + }; + let resp = convert_response(http_resp.clone()).unwrap(); + let request: reqwest::Request = + reqwest::Request::new(Method::GET, request_url.parse().unwrap()); + + let _ = manager + .put( + key.to_string(), + http_resp, + CachePolicy::new(&request, &resp), + ) + .await + .unwrap(); + } + + #[tokio::test] + async fn test_put() { + let manager = HttpCacheManager::default(); + insert_key_into_cache(&manager, "test").await; + assert!(manager.cache.contains_key("test")); + } + + #[tokio::test] + async fn test_get_when_key_present() { + let manager = HttpCacheManager::default(); + insert_key_into_cache(&manager, "test").await; + let value = manager.get("test").await.unwrap(); + assert!(value.is_some()); + } + + #[tokio::test] + async fn test_get_when_key_not_present() { + let manager = HttpCacheManager::default(); + let result = manager.get("test").await.unwrap(); + assert!(result.is_none()); + } + + #[tokio::test] + async fn test_delete_when_key_present() { + let manager = HttpCacheManager::default(); + insert_key_into_cache(&manager, "test").await; + + assert!(manager.cache.iter().count() as i32 == 1); + let _ = manager.delete("test").await; + assert!(manager.cache.iter().count() as i32 == 0); + } + + #[tokio::test] + async fn test_clear() { + let manager = HttpCacheManager::default(); + insert_key_into_cache(&manager, "test").await; + assert!(manager.cache.iter().count() as i32 == 1); + let _ = manager.clear().await; + assert!(manager.cache.iter().count() as i32 == 0); + } + + #[tokio::test] + async fn test_lru_eviction_policy() { + let manager = HttpCacheManager::new(2); + insert_key_into_cache(&manager, "test-1").await; + insert_key_into_cache(&manager, "test-2").await; + insert_key_into_cache(&manager, "test-10").await; + + let res = manager.get("test-1").await.unwrap(); + assert!(res.is_none()); + + let res = manager.get("test-2").await.unwrap(); + assert!(res.is_some()); + + let res = manager.get("test-10").await.unwrap(); + assert!(res.is_some()); + + assert_eq!(manager.cache.entry_count(), 2); + } +}*/ diff --git a/projects/ssddOnTop/src/config/config.rs b/projects/ssddOnTop/src/config/config.rs index 9d288f5..5a641b8 100644 --- a/projects/ssddOnTop/src/config/config.rs +++ b/projects/ssddOnTop/src/config/config.rs @@ -39,6 +39,8 @@ impl Default for Server { pub struct Upstream { #[serde(rename = "baseURL", default, skip_serializing_if = "is_default")] pub base_url: Option, + #[serde(default, skip_serializing_if = "is_default")] + pub http_cache: Option, } // TODO: rename diff --git a/projects/ssddOnTop/src/helpers/headers.rs b/projects/ssddOnTop/src/helpers/headers.rs index c41d072..f28d827 100644 --- a/projects/ssddOnTop/src/helpers/headers.rs +++ b/projects/ssddOnTop/src/helpers/headers.rs @@ -22,7 +22,7 @@ mod tests { use crate::config::KeyValue; use crate::mustache::model::Mustache; use anyhow::Result; - use hyper::header::HeaderName; + use reqwest::header::HeaderName; #[test] fn valid_headers() -> Result<()> { diff --git a/projects/ssddOnTop/src/http/method.rs b/projects/ssddOnTop/src/http/method.rs index fe7f49e..b8a1481 100644 --- a/projects/ssddOnTop/src/http/method.rs +++ b/projects/ssddOnTop/src/http/method.rs @@ -15,6 +15,23 @@ pub enum Method { TRACE, } +impl From for Method { + fn from(value: hyper::Method) -> Self { + match value { + hyper::Method::GET => Method::GET, + hyper::Method::POST => Method::POST, + hyper::Method::PUT => Method::PUT, + hyper::Method::PATCH => Method::PATCH, + hyper::Method::DELETE => Method::DELETE, + hyper::Method::HEAD => Method::HEAD, + hyper::Method::OPTIONS => Method::OPTIONS, + hyper::Method::CONNECT => Method::CONNECT, + hyper::Method::TRACE => Method::TRACE, + _ => unreachable!(), + } + } +} + impl Method { pub fn to_hyper(self) -> hyper::Method { match self { diff --git a/projects/ssddOnTop/src/http/req_template.rs b/projects/ssddOnTop/src/http/req_template.rs index 75d9095..a9a0470 100644 --- a/projects/ssddOnTop/src/http/req_template.rs +++ b/projects/ssddOnTop/src/http/req_template.rs @@ -1,12 +1,13 @@ use crate::endpoint::Endpoint; use crate::mustache::model::Mustache; use std::hash::Hash; +use hyper::Method; #[derive(Debug, Clone)] pub struct RequestTemplate { pub root_url: Mustache, pub query: Vec, - pub method: reqwest::Method, + pub method: Method, // pub headers: MustacheHeaders, } diff --git a/projects/ssddOnTop/src/http/request.rs b/projects/ssddOnTop/src/http/request.rs index 9912c42..d927491 100644 --- a/projects/ssddOnTop/src/http/request.rs +++ b/projects/ssddOnTop/src/http/request.rs @@ -1,8 +1,9 @@ use http_body_util::BodyExt; use hyper::body::Incoming; +use crate::http::method::Method; pub struct Request { - pub method: hyper::Method, + pub method: Method, pub url: hyper::Uri, pub headers: hyper::HeaderMap, pub body: bytes::Bytes, @@ -14,7 +15,7 @@ impl Request { let body = body.collect().await?.to_bytes(); Ok(Self { - method: part.method, + method: Method::from(part.method), url: part.uri, headers: part.headers, body, diff --git a/projects/ssddOnTop/src/http/request_handler.rs b/projects/ssddOnTop/src/http/request_handler.rs index 805b956..1ec479c 100644 --- a/projects/ssddOnTop/src/http/request_handler.rs +++ b/projects/ssddOnTop/src/http/request_handler.rs @@ -3,12 +3,33 @@ use crate::http::request::Request; use bytes::Bytes; use http_body_util::Full; use std::sync::Arc; +use crate::http::method::Method; pub async fn handle_request( req: Request, blueprint: Arc, ) -> anyhow::Result>> { - Ok(hyper::Response::new(Full::new(Bytes::from_static( - b"Hello, World!", - )))) + let resp = match req.method { + Method::GET => { + hyper::Response::new(Full::new(Bytes::from_static( + b"Hello, World!", + ))) + } + Method::POST => { + handle_gql_req(req, blueprint).await? + } + _ => { + hyper::Response::builder() + .status(hyper::StatusCode::METHOD_NOT_ALLOWED) + .body(Full::new(Bytes::from_static(b"Method Not Allowed")))? + } + }; + Ok(resp) } + +async fn handle_gql_req( + _request: Request, + _blueprint: Arc, +) -> anyhow::Result>> { + todo!() +} \ No newline at end of file diff --git a/projects/ssddOnTop/src/lib.rs b/projects/ssddOnTop/src/lib.rs index 869c716..8337016 100644 --- a/projects/ssddOnTop/src/lib.rs +++ b/projects/ssddOnTop/src/lib.rs @@ -12,6 +12,9 @@ mod mustache; mod path; pub mod run; mod value; +mod target_runtime; +mod cache; +mod app_ctx; pub fn is_default(val: &T) -> bool { *val == T::default() diff --git a/projects/ssddOnTop/src/request_context.rs b/projects/ssddOnTop/src/request_context.rs new file mode 100644 index 0000000..bc2fd8e --- /dev/null +++ b/projects/ssddOnTop/src/request_context.rs @@ -0,0 +1,166 @@ +use std::num::NonZeroU64; +use std::str::FromStr; +use std::sync::{Arc, Mutex}; + +use async_graphql_value::ConstValue; +use cache_control::{Cachability, CacheControl}; +use derive_setters::Setters; +use reqwest::header::{HeaderMap, HeaderName, HeaderValue}; +use crate::blueprint::{Blueprint, Server, Upstream}; +use crate::ir::IoId; + +#[derive(Setters)] +pub struct RequestContext { + pub server: Server, + pub upstream: Upstream, + pub x_response_headers: Arc>, + pub cookie_headers: Option>>, + // A subset of all the headers received in the GraphQL Request that will be sent to the + // upstream. + pub allowed_headers: HeaderMap, + pub http_data_loaders: Arc>>, + pub min_max_age: Arc>>, + pub cache_public: Arc>>, + pub runtime: TargetRuntime, + pub cache: DedupeResult, + pub dedupe_handler: Arc>, +} + +impl RequestContext { + pub fn new(target_runtime: TargetRuntime) -> RequestContext { + RequestContext { + server: Default::default(), + upstream: Default::default(), + x_response_headers: Arc::new(Mutex::new(HeaderMap::new())), + cookie_headers: None, + http_data_loaders: Arc::new(vec![]), + min_max_age: Arc::new(Mutex::new(None)), + cache_public: Arc::new(Mutex::new(None)), + runtime: target_runtime, + cache: DedupeResult::new(true), + dedupe_handler: Arc::new(DedupeResult::new(false)), + allowed_headers: HeaderMap::new(), + } + } + fn set_min_max_age_conc(&self, min_max_age: i32) { + *self.min_max_age.lock().unwrap() = Some(min_max_age); + } + pub fn get_min_max_age(&self) -> Option { + *self.min_max_age.lock().unwrap() + } + + pub fn set_cache_public_false(&self) { + *self.cache_public.lock().unwrap() = Some(false); + } + + pub fn is_cache_public(&self) -> Option { + *self.cache_public.lock().unwrap() + } + + pub fn set_min_max_age(&self, max_age: i32) { + let min_max_age_lock = self.get_min_max_age(); + match min_max_age_lock { + Some(min_max_age) if max_age < min_max_age => { + self.set_min_max_age_conc(max_age); + } + None => { + self.set_min_max_age_conc(max_age); + } + _ => {} + } + } + + pub fn set_cache_visibility(&self, cachability: &Option) { + if let Some(Cachability::Private) = cachability { + self.set_cache_public_false() + } + } + + pub fn set_cache_control(&self, cache_policy: CacheControl) { + if let Some(max_age) = cache_policy.max_age { + self.set_min_max_age(max_age.as_secs() as i32); + } + self.set_cache_visibility(&cache_policy.cachability); + if Some(Cachability::NoCache) == cache_policy.cachability { + self.set_min_max_age(-1); + } + } + + pub fn set_cookie_headers(&self, headers: &HeaderMap) { + // TODO fix execution_spec test and use append method + // to allow multiple set cookie + if let Some(map) = &self.cookie_headers { + let map = &mut map.lock().unwrap(); + + // Check if the incoming headers contain 'set-cookie' + if let Some(new_cookies) = headers.get("set-cookie") { + let cookie_name = HeaderName::from_str("set-cookie").unwrap(); + + // Check if 'set-cookie' already exists in our map + if let Some(existing_cookies) = map.get(&cookie_name) { + // Convert the existing HeaderValue to a str, append the new cookies, + // and then convert back to a HeaderValue. If the conversion fails, we skip + // appending. + if let Ok(existing_str) = existing_cookies.to_str() { + if let Ok(new_cookies_str) = new_cookies.to_str() { + // Create a new value by appending the new cookies to the existing ones + let combined_cookies = format!("{}; {}", existing_str, new_cookies_str); + + // Replace the old value with the new, combined value + map.insert( + cookie_name, + HeaderValue::from_str(&combined_cookies).unwrap(), + ); + } + } + } else { + // If 'set-cookie' does not already exist in our map, just insert the new value + map.insert(cookie_name, new_cookies.clone()); + } + } + } + } + + pub async fn cache_get(&self, key: &IoId) -> Result, anyhow::Error> { + self.runtime.cache.get(key).await + } + + #[allow(clippy::too_many_arguments)] + pub async fn cache_insert( + &self, + key: IoId, + value: ConstValue, + ttl: NonZeroU64, + ) -> Result<(), anyhow::Error> { + self.runtime.cache.set(key, value, ttl).await + } + + + /// Modifies existing headers to include the experimental headers + pub fn extend_x_headers(&self, headers: &mut HeaderMap) { + if self.has_experimental_headers() { + let x_response_headers = &self.x_response_headers.lock().unwrap(); + for (header, value) in x_response_headers.iter() { + headers.insert(header, value.clone()); + } + } + } +} + +impl From<&Blueprint> for RequestContext { + fn from(blueprint: &Blueprint) -> Self { + Self { + server: blueprint.server.clone(), + upstream: blueprint.upstream.clone(), + x_response_headers: Arc::new(Mutex::new(HeaderMap::new())), + cookie_headers, + allowed_headers: HeaderMap::new(), + http_data_loaders: app_ctx.http_data_loaders.clone(), + min_max_age: Arc::new(Mutex::new(None)), + cache_public: Arc::new(Mutex::new(None)), + runtime: app_ctx.runtime.clone(), + cache: DedupeResult::new(true), + dedupe_handler: app_ctx.dedupe_handler.clone(), + } + } +} diff --git a/projects/ssddOnTop/src/target_runtime.rs b/projects/ssddOnTop/src/target_runtime.rs new file mode 100644 index 0000000..47fc05f --- /dev/null +++ b/projects/ssddOnTop/src/target_runtime.rs @@ -0,0 +1,111 @@ +use std::sync::Arc; +use crate::target_runtime::cache::HttpCacheManager; +use crate::target_runtime::http::NativeHttp; + +#[derive(Clone)] +pub struct TargetRuntime { + /// HTTP client for making standard HTTP requests. + pub http: Arc, + pub cache: Arc, +} + +mod cache { + use http_cache_reqwest::{CacheManager, HttpResponse}; + use http_cache_semantics::CachePolicy; + use serde::{Deserialize, Serialize}; + pub type BoxError = Box; + pub type Result = std::result::Result; + use std::sync::Arc; + + use moka::future::Cache; + use moka::policy::EvictionPolicy; + + pub struct HttpCacheManager { + pub cache: Arc>, + } + + impl Default for HttpCacheManager { + fn default() -> Self { + Self::new(42) + } + } + + #[derive(Clone, Deserialize, Serialize)] + pub struct Store { + response: HttpResponse, + policy: CachePolicy, + } + + impl HttpCacheManager { + pub fn new(cache_size: u64) -> Self { + let cache = Cache::builder() + .eviction_policy(EvictionPolicy::lru()) + .max_capacity(cache_size) + .build(); + Self { cache: Arc::new(cache) } + } + + pub async fn clear(&self) -> Result<()> { + self.cache.invalidate_all(); + self.cache.run_pending_tasks().await; + Ok(()) + } + } + + #[async_trait::async_trait] + impl CacheManager for HttpCacheManager { + async fn get(&self, cache_key: &str) -> Result> { + let store: Store = match self.cache.get(cache_key).await { + Some(d) => d, + None => return Ok(None), + }; + Ok(Some((store.response, store.policy))) + } + + async fn put( + &self, + cache_key: String, + response: HttpResponse, + policy: CachePolicy, + ) -> Result { + let data = Store { response: response.clone(), policy }; + self.cache.insert(cache_key, data).await; + self.cache.run_pending_tasks().await; + Ok(response) + } + + async fn delete(&self, cache_key: &str) -> Result<()> { + self.cache.invalidate(cache_key).await; + self.cache.run_pending_tasks().await; + Ok(()) + } + } +} + +mod http { + use http_cache_reqwest::{Cache, CacheMode, HttpCache, HttpCacheOptions}; + use reqwest::Client; + use reqwest_middleware::{ClientBuilder, ClientWithMiddleware}; + use crate::blueprint::Upstream; + use crate::cache::HttpCacheManager; + + pub struct NativeHttp { + client: ClientWithMiddleware, + } + + impl NativeHttp { + pub fn init(upstream: &Upstream) -> Self { + let mut client = ClientBuilder::new(Client::new()); + + client = client.with(Cache(HttpCache { + mode: CacheMode::Default, + manager: HttpCacheManager::new(upstream.http_cache), + options: HttpCacheOptions::default(), + })); + + Self { + client: client.build(), + } + } + } +} \ No newline at end of file From 29dd0db0f2aa207cdfd3d83b5461c45b72f5cb67 Mon Sep 17 00:00:00 2001 From: Sandipsinh Rathod Date: Wed, 11 Sep 2024 20:13:21 -0400 Subject: [PATCH 05/21] idek where I am going --- Cargo.lock | 19 +- projects/ssddOnTop/Cargo.toml | 2 + projects/ssddOnTop/src/app_ctx.rs | 1 - projects/ssddOnTop/src/blueprint/blueprint.rs | 15 +- .../ssddOnTop/src/blueprint/operators/http.rs | 2 - projects/ssddOnTop/src/dl/dedupe.rs | 399 ++++++++++++++++++ projects/ssddOnTop/src/dl/mod.rs | 1 + projects/ssddOnTop/src/http/headers.rs | 35 ++ projects/ssddOnTop/src/http/method.rs | 13 + projects/ssddOnTop/src/http/mod.rs | 3 + projects/ssddOnTop/src/http/query_encoder.rs | 258 +++++++++++ projects/ssddOnTop/src/http/req_template.rs | 158 ++++++- .../ssddOnTop/src/http/request_handler.rs | 23 +- projects/ssddOnTop/src/http/response.rs | 114 +++++ projects/ssddOnTop/src/ir/eval_ctx.rs | 53 +++ projects/ssddOnTop/src/ir/eval_http.rs | 54 +++ projects/ssddOnTop/src/ir/eval_io.rs | 31 ++ projects/ssddOnTop/src/ir/mod.rs | 3 + projects/ssddOnTop/src/ir/model.rs | 24 +- projects/ssddOnTop/src/jit/mod.rs | 1 + projects/ssddOnTop/src/jit/model.rs | 9 + projects/ssddOnTop/src/lib.rs | 3 + projects/ssddOnTop/src/path.rs | 57 ++- projects/ssddOnTop/src/request_context.rs | 129 ++---- projects/ssddOnTop/src/run/http1.rs | 14 +- projects/ssddOnTop/src/run/run.rs | 8 +- projects/ssddOnTop/src/target_runtime.rs | 123 +++--- projects/ssddOnTop/src/value/value.rs | 25 +- 28 files changed, 1363 insertions(+), 214 deletions(-) create mode 100644 projects/ssddOnTop/src/dl/dedupe.rs create mode 100644 projects/ssddOnTop/src/dl/mod.rs create mode 100644 projects/ssddOnTop/src/http/headers.rs create mode 100644 projects/ssddOnTop/src/http/query_encoder.rs create mode 100644 projects/ssddOnTop/src/http/response.rs create mode 100644 projects/ssddOnTop/src/ir/eval_ctx.rs create mode 100644 projects/ssddOnTop/src/ir/eval_http.rs create mode 100644 projects/ssddOnTop/src/ir/eval_io.rs create mode 100644 projects/ssddOnTop/src/jit/mod.rs create mode 100644 projects/ssddOnTop/src/jit/model.rs diff --git a/Cargo.lock b/Cargo.lock index 2c37e86..8c50865 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1706,6 +1706,12 @@ version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" +[[package]] +name = "linked-hash-map" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" + [[package]] name = "linux-raw-sys" version = "0.3.8" @@ -2891,6 +2897,7 @@ dependencies = [ "derive-getters", "derive_more", "derive_setters", + "futures-util", "fxhash", "http 1.1.0", "http-body-util", @@ -2917,6 +2924,7 @@ dependencies = [ "tokio", "tracing", "tracing-subscriber", + "ttl_cache", "url", ] @@ -3369,6 +3377,15 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" +[[package]] +name = "ttl_cache" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4189890526f0168710b6ee65ceaedf1460c48a14318ceec933cb26baa492096a" +dependencies = [ + "linked-hash-map", +] + [[package]] name = "typenum" version = "1.17.0" @@ -3610,7 +3627,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.59.0", ] [[package]] diff --git a/projects/ssddOnTop/Cargo.toml b/projects/ssddOnTop/Cargo.toml index 5d606f3..fc9bcb2 100644 --- a/projects/ssddOnTop/Cargo.toml +++ b/projects/ssddOnTop/Cargo.toml @@ -41,6 +41,8 @@ moka = { version = "0.12.7", default-features = false, features = [ "future", ]} async-trait = "0.1.82" +ttl_cache = "0.5.1" +futures-util = "0.3.30" [dev-dependencies] http-cache = "0.18.0" diff --git a/projects/ssddOnTop/src/app_ctx.rs b/projects/ssddOnTop/src/app_ctx.rs index c5a30fd..8cc0ba1 100644 --- a/projects/ssddOnTop/src/app_ctx.rs +++ b/projects/ssddOnTop/src/app_ctx.rs @@ -12,5 +12,4 @@ impl AppCtx { pub fn new(runtime: TargetRuntime, blueprint: Arc) -> Self { Self { runtime, blueprint } } - } \ No newline at end of file diff --git a/projects/ssddOnTop/src/blueprint/blueprint.rs b/projects/ssddOnTop/src/blueprint/blueprint.rs index 5f13f45..ec37494 100644 --- a/projects/ssddOnTop/src/blueprint/blueprint.rs +++ b/projects/ssddOnTop/src/blueprint/blueprint.rs @@ -1,7 +1,7 @@ use crate::blueprint::definitions::to_definitions; use crate::blueprint::model::{Arg, ArgId, Field, FieldId, FieldName, TypeName}; use crate::blueprint::wrapping_type::Type; -use crate::config::Config; +use crate::config::{Config, RootSchema}; use crate::ir::IR; use derive_setters::Setters; use serde_json::Value; @@ -19,6 +19,7 @@ pub struct Blueprint { pub fields: HashMap, pub server: Server, pub upstream: Upstream, + pub schema: RootSchema, } #[derive(Clone, Debug)] @@ -74,12 +75,21 @@ pub struct Server { pub port: u16, } +impl Default for Server { + fn default() -> Self { + Self { + host: IpAddr::from([127, 0, 0, 1]), + port: 8000, + } + } +} + impl Server { pub fn addr(&self) -> SocketAddr { SocketAddr::new(self.host, self.port) } } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default)] pub struct Upstream { pub base_url: Option, pub http_cache: u64, @@ -110,6 +120,7 @@ impl TryFrom<&Config> for Blueprint { fields, server, upstream, + schema: config.schema.clone(), }) } } diff --git a/projects/ssddOnTop/src/blueprint/operators/http.rs b/projects/ssddOnTop/src/blueprint/operators/http.rs index c2d2e57..805e20c 100644 --- a/projects/ssddOnTop/src/blueprint/operators/http.rs +++ b/projects/ssddOnTop/src/blueprint/operators/http.rs @@ -49,12 +49,10 @@ fn compile_http(config_module: &config::Config, http: &config::Http) -> anyhow:: }); IR::IO(IO::Http { req_template, - dl_id: None, }) } else { IR::IO(IO::Http { req_template, - dl_id: None, }) }; diff --git a/projects/ssddOnTop/src/dl/dedupe.rs b/projects/ssddOnTop/src/dl/dedupe.rs new file mode 100644 index 0000000..07251f8 --- /dev/null +++ b/projects/ssddOnTop/src/dl/dedupe.rs @@ -0,0 +1,399 @@ +use std::collections::HashMap; +use std::hash::Hash; +use std::sync::{Arc, Mutex, Weak}; + +use futures_util::Future; +use tokio::sync::broadcast; +use crate::ir::IoId; + +pub trait Key: Send + Sync + Eq + Hash + Clone {} +impl Key for A {} + +pub trait Value: Send + Sync + Clone {} +impl Value for A {} + +/// +/// Allows deduplication of async operations based on a key. +pub struct Dedupe { + /// Cache storage for the operations. + cache: Arc>>>, + /// Initial size of the multi-producer, multi-consumer channel. + size: usize, + /// When enabled allows the operations to be cached forever. + persist: bool, +} + +/// Represents the current state of the operation. +enum State { + /// Means that the operation has been executed and the result is stored. + Ready(Value), + + /// Means that the operation is in progress and the result can be sent via + /// the stored sender whenever it's available in the future. + Pending(Weak>), +} + +/// Represents the next steps +enum Step { + /// The operation has been executed and the result must be returned. + Return(Value), + + /// The operation is in progress and the result must be awaited on the + /// receiver. + Await(broadcast::Receiver), + + /// The operation needs to be executed and the result needs to be sent to + /// the provided sender. + Init(Arc>), +} + +impl Dedupe { + pub fn new(size: usize, persist: bool) -> Self { + Self { cache: Arc::new(Mutex::new(HashMap::new())), size, persist } + } + + pub async fn dedupe<'a, Fn, Fut>(&'a self, key: &'a K, or_else: Fn) -> V + where + Fn: FnOnce() -> Fut, + Fut: Future, + { + loop { + let value = match self.step(key) { + Step::Return(value) => value, + Step::Await(mut rx) => match rx.recv().await { + Ok(value) => value, + Err(_) => { + // If we get an error that means the task with + // owned tx (sender) was dropped.i.e. there is no result in cache + // and we can try another attempt because probably another + // task will do the execution + continue; + } + }, + Step::Init(tx) => { + let value = or_else().await; + let mut guard = self.cache.lock().unwrap(); + if self.persist { + guard.insert(key.to_owned(), State::Ready(value.clone())); + } else { + guard.remove(key); + } + let _ = tx.send(value.clone()); + value + } + }; + + return value; + } + } + + fn step(&self, key: &K) -> Step { + let mut this = self.cache.lock().unwrap(); + + if let Some(state) = this.get(key) { + match state { + State::Ready(value) => return Step::Return(value.clone()), + State::Pending(tx) => { + // We can upgrade from Weak to Arc only in case when + // original tx is still alive + // otherwise we will create in the code below + if let Some(tx) = tx.upgrade() { + return Step::Await(tx.subscribe()); + } + } + } + } + + let (tx, _) = broadcast::channel(self.size); + let tx = Arc::new(tx); + // Store a Weak version of tx and pass actual tx to further handling + // to control if tx is still alive and will be able to handle the request. + // Only single `strong` reference to tx should exist so we can + // understand when the execution is still alive and we'll get the response + this.insert(key.to_owned(), State::Pending(Arc::downgrade(&tx))); + Step::Init(tx) + } +} + +pub struct DedupeResult(Dedupe>); + +impl DedupeResult { + pub fn new(persist: bool) -> Self { + Self(Dedupe::new(1, persist)) + } +} + +impl DedupeResult { + pub async fn dedupe<'a, Fn, Fut>(&'a self, key: &'a K, or_else: Fn) -> Result + where + Fn: FnOnce() -> Fut, + Fut: Future>, + { + self.0.dedupe(key, or_else).await + } +} + +#[cfg(test)] +mod tests { + use std::ops::Deref; + use std::sync::atomic::{AtomicUsize, Ordering}; + use std::time::Duration; + + use assert_eq; + use tokio::join; + use tokio::time::{sleep, timeout_at, Instant}; + + use super::*; + + #[tokio::test] + async fn test_no_key() { + let cache = Arc::new(Dedupe::::new(1000, true)); + let actual = cache.dedupe(&1, || Box::pin(async { 1 })).await; + assert_eq!(actual, 1); + } + + #[tokio::test] + async fn test_with_key() { + let cache = Arc::new(Dedupe::::new(1000, true)); + cache.dedupe(&1, || Box::pin(async { 1 })).await; + + let actual = cache.dedupe(&1, || Box::pin(async { 2 })).await; + assert_eq!(actual, 1); + } + + #[tokio::test] + async fn test_with_multi_get() { + let cache = Arc::new(Dedupe::::new(1000, true)); + + for i in 0..100 { + cache.dedupe(&1, || Box::pin(async move { i })).await; + } + + let actual = cache.dedupe(&1, || Box::pin(async { 2 })).await; + assert_eq!(actual, 0); + } + + #[tokio::test] + async fn test_with_multi_async_get() { + let cache = Arc::new(Dedupe::::new(1000, true)); + + let a = cache.dedupe(&1, || { + Box::pin(async move { + sleep(Duration::from_millis(1)).await; + 1 + }) + }); + let b = cache.dedupe(&1, || { + Box::pin(async move { + sleep(Duration::from_millis(1)).await; + 2 + }) + }); + let (a, b) = join!(a, b); + + assert_eq!(a, b); + } + + async fn compute_value(counter: Arc) -> String { + counter.fetch_add(1, Ordering::SeqCst); + sleep(Duration::from_millis(1)).await; + format!("value_{}", counter.load(Ordering::SeqCst)) + } + + #[tokio::test(worker_threads = 16, flavor = "multi_thread")] + async fn test_deadlock_scenario() { + let _ = tracing_subscriber::fmt(); + let cache = Arc::new(Dedupe::::new(1000, true)); + let key = 1; + let counter = Arc::new(AtomicUsize::new(0)); + let mut handles = Vec::new(); + + // Spawn multiple tasks to simulate concurrent access + for i in 0..1000000 { + let cache = cache.clone(); + let counter = counter.clone(); + let handle = tokio::task::spawn(async move { + let result = cache + .dedupe(&key, || Box::pin(compute_value(counter))) + .await; + (i, result) + }); + handles.push(handle); + } + // Await each task for any potential deadlocks + for handle in handles.into_iter() { + let _ = handle.await.unwrap(); + } + // Check that compute_value was called exactly once + assert_eq!( + counter.load(Ordering::SeqCst), + 1, + "compute_value was called more than once" + ); + } + + #[tokio::test] + async fn test_hanging_after_dropped() { + let cache = Arc::new(Dedupe::::new(100, true)); + + let task = cache.dedupe(&1, move || async move { + sleep(Duration::from_millis(100)).await; + }); + + // drops the task since the underlying sleep timeout is higher than the + // timeout here + + timeout_at(Instant::now() + Duration::from_millis(10), task) + .await + .expect_err("Should throw timeout error"); + + cache + .dedupe(&1, move || async move { + sleep(Duration::from_millis(100)).await; + }) + .await; + } + + #[tokio::test] + async fn test_hanging_dropped_while_in_use() { + let cache = Arc::new(Dedupe::::new(100, true)); + let cache_1 = cache.clone(); + let cache_2 = cache.clone(); + + let task_1 = tokio::spawn(async move { + cache_1 + .dedupe(&1, move || async move { + sleep(Duration::from_millis(100)).await; + 100 + }) + .await + }); + + let task_2 = tokio::spawn(async move { + cache_2 + .dedupe(&1, move || async move { + sleep(Duration::from_millis(100)).await; + 200 + }) + .await + }); + + sleep(Duration::from_millis(10)).await; + + // drop the first task + task_1.abort(); + + let actual = task_2.await.unwrap(); + assert_eq!(actual, 200) + } + + // TODO: This is a failing test + #[tokio::test] + #[ignore] + async fn test_should_not_abort_call_1() { + #[derive(Debug, PartialEq, Clone)] + struct Status { + // Set this in the first call + call_1: bool, + + // Set this in the second call + call_2: bool, + } + + let status = Arc::new(Mutex::new(Status { call_1: false, call_2: false })); + + let cache = Arc::new(Dedupe::::new(100, true)); + let cache_1 = cache.clone(); + let cache_2 = cache.clone(); + let status_1 = status.clone(); + let status_2 = status.clone(); + + // Task 1 completed in 100ms + let task_1 = tokio::spawn(async move { + cache_1 + .dedupe(&1, move || async move { + sleep(Duration::from_millis(100)).await; + status_1.lock().unwrap().call_1 = true; + }) + .await + }); + + // Wait for 10ms + sleep(Duration::from_millis(10)).await; + + // Task 2 completed in 200ms + tokio::spawn(async move { + cache_2 + .dedupe(&1, move || async move { + sleep(Duration::from_millis(120)).await; + status_2.lock().unwrap().call_2 = true; + }) + .await + }); + + // Wait for 10ms + sleep(Duration::from_millis(10)).await; + + // Abort the task_1 + task_1.abort(); + + sleep(Duration::from_millis(300)).await; + + // Task 1 should still have completed because others are dependent on it. + let actual = status.lock().unwrap().deref().to_owned(); + assert_eq!(actual, Status { call_1: true, call_2: false }) + } + + #[tokio::test] + async fn test_should_abort_all() { + #[derive(Debug, PartialEq, Clone)] + struct Status { + // Set this in the first call + call_1: bool, + + // Set this in the second call + call_2: bool, + } + + let status = Arc::new(Mutex::new(Status { call_1: false, call_2: false })); + + let cache = Arc::new(Dedupe::::new(100, true)); + let cache_1 = cache.clone(); + let cache_2 = cache.clone(); + let status_1 = status.clone(); + let status_2 = status.clone(); + + // Task 1 completed in 100ms + let task_1 = tokio::spawn(async move { + cache_1 + .dedupe(&1, move || async move { + sleep(Duration::from_millis(100)).await; + status_1.lock().unwrap().call_1 = true; + }) + .await + }); + + // Task 2 completed in 150ms + let task_2 = tokio::spawn(async move { + cache_2 + .dedupe(&1, move || async move { + sleep(Duration::from_millis(150)).await; + status_2.lock().unwrap().call_2 = true; + }) + .await + }); + + // Wait for 10ms + sleep(Duration::from_millis(50)).await; + + // Abort the task_1 & task_2 + task_1.abort(); + task_2.abort(); + + sleep(Duration::from_millis(300)).await; + + // No task should have completed + let actual = status.lock().unwrap().deref().to_owned(); + assert_eq!(actual, Status { call_1: false, call_2: false }) + } +} diff --git a/projects/ssddOnTop/src/dl/mod.rs b/projects/ssddOnTop/src/dl/mod.rs new file mode 100644 index 0000000..da5d458 --- /dev/null +++ b/projects/ssddOnTop/src/dl/mod.rs @@ -0,0 +1 @@ +pub mod dedupe; \ No newline at end of file diff --git a/projects/ssddOnTop/src/http/headers.rs b/projects/ssddOnTop/src/http/headers.rs new file mode 100644 index 0000000..979797a --- /dev/null +++ b/projects/ssddOnTop/src/http/headers.rs @@ -0,0 +1,35 @@ +use std::str::FromStr; + +#[derive(Clone, Debug, Default)] +pub struct HeaderMap(hyper::header::HeaderMap); + +impl Into for HeaderMap { + fn into(self) -> hyper::header::HeaderMap { + self.0 + } +} + +/*impl Into for HeaderMap { + fn into(self) -> reqwest::header::HeaderMap { + let mut map = reqwest::header::HeaderMap::new(); + for (k, v) in self.0.iter() { + map.insert(k.as_str().parse().unwrap(),v.as_bytes().to_vec().into()); + } + map + } +}*/ + +impl From for HeaderMap { + fn from(value: http::HeaderMap) -> Self { + Self(value) + } +} +impl From for HeaderMap { + fn from(value: reqwest::header::HeaderMap) -> Self { + let mut map = hyper::header::HeaderMap::new(); + for (k, v) in value.iter() { + map.insert(hyper::header::HeaderName::from_str(k.as_str()).unwrap(),hyper::header::HeaderValue::from_str(v.to_str().unwrap()).unwrap()); + } + Self(map) + } +} \ No newline at end of file diff --git a/projects/ssddOnTop/src/http/method.rs b/projects/ssddOnTop/src/http/method.rs index b8a1481..18e2e22 100644 --- a/projects/ssddOnTop/src/http/method.rs +++ b/projects/ssddOnTop/src/http/method.rs @@ -33,6 +33,19 @@ impl From for Method { } impl Method { + pub fn into_reqwest(self) -> reqwest::Method { + match self { + Method::GET => reqwest::Method::GET, + Method::POST => reqwest::Method::POST, + Method::PUT => reqwest::Method::PUT, + Method::PATCH => reqwest::Method::PATCH, + Method::DELETE => reqwest::Method::DELETE, + Method::HEAD => reqwest::Method::HEAD, + Method::OPTIONS => reqwest::Method::OPTIONS, + Method::CONNECT => reqwest::Method::CONNECT, + Method::TRACE => reqwest::Method::TRACE, + } + } pub fn to_hyper(self) -> hyper::Method { match self { Method::GET => hyper::Method::GET, diff --git a/projects/ssddOnTop/src/http/mod.rs b/projects/ssddOnTop/src/http/mod.rs index ecb4d3c..348e688 100644 --- a/projects/ssddOnTop/src/http/mod.rs +++ b/projects/ssddOnTop/src/http/mod.rs @@ -2,5 +2,8 @@ pub mod method; mod req_template; pub mod request; pub mod request_handler; +mod query_encoder; +pub mod response; +mod headers; pub use req_template::*; diff --git a/projects/ssddOnTop/src/http/query_encoder.rs b/projects/ssddOnTop/src/http/query_encoder.rs new file mode 100644 index 0000000..a92d14a --- /dev/null +++ b/projects/ssddOnTop/src/http/query_encoder.rs @@ -0,0 +1,258 @@ +use crate::path::ValueString; +use crate::value::Value; + +/// Defines different strategies for encoding query parameters. +#[derive(Default, Debug, Clone)] +pub enum QueryEncoder { + /// Encodes the query list as key=value1,value2,value3,... + CommaSeparated, + /// Encodes the query list by repeating the key for each value: + /// key=value1&key=value2&key=value3&... + #[default] + RepeatedKey, +} + +impl QueryEncoder { + pub fn encode(&self, key: &str, raw_value: Option) -> String { + if let Some(value) = raw_value { + match &value { + ValueString::Value(val) => self.encode_const_value(key, val.serde()), + ValueString::String(val) => format!("{}={}", key, val), + } + } else { + key.to_owned() + } + } + fn encode_const_value(&self, key: &str, value: &serde_json::Value) -> String { + match self { + QueryEncoder::CommaSeparated => match value { + serde_json::Value::Array(list) if !list.is_empty() => { + let encoded_values: Vec = + list.iter().filter_map(convert_value).collect(); + + if encoded_values.is_empty() { + key.to_string() + } else { + format!("{}={}", key, encoded_values.join(",")) + } + } + _ => convert_value(value) + .map(|val| format!("{}={}", key, val)) + .unwrap_or(key.to_string()), + }, + QueryEncoder::RepeatedKey => match value { + serde_json::Value::Array(list) if !list.is_empty() => { + let encoded_values: Vec = list + .iter() + .map(|val| self.encode_const_value(key, val)) + .collect(); + if encoded_values.is_empty() { + key.to_string() + } else { + encoded_values.join("&") + } + } + _ => convert_value(value) + .map(|val| format!("{}={}", key, val)) + .unwrap_or(key.to_string()), + }, + } + } +} + +pub fn convert_value(value: &serde_json::Value) -> Option { + match value { + serde_json::Value::String(s) => Some(s.to_string()), + serde_json::Value::Number(n) => Some(n.to_string()), + serde_json::Value::Bool(b) => Some(b.to_string()), + _ => None, + } +} + +#[cfg(test)] +mod tests { + use std::borrow::Cow; + + use serde_json::Value; + + use super::*; + + #[test] + fn test_encode_comma_separated_arg() { + let encoder = QueryEncoder::CommaSeparated; + let values = Value::Array(vec![ + Value::Number(12.into()), + Value::Number(42.into()), + Value::Number(13.into()), + ]); + let binding = crate::value::Value::new(values); + let arg_raw_value = Some(ValueString::Value(Cow::Borrowed(&binding))); + + let actual = encoder.encode("key", arg_raw_value); + let expected = "key=12,42,13".to_string(); + + assert_eq!(actual, expected); + } + + #[test] + fn test_encode_repeated_key_value_arg() { + let encoder = QueryEncoder::RepeatedKey; + let values = Value::Array(vec![ + Value::Number(12.into()), + Value::Number(42.into()), + Value::Number(13.into()), + ]); + let binding = crate::value::Value::new(values); + let arg_raw_value = Some(ValueString::Value(Cow::Borrowed(&binding))); + + let actual = encoder.encode("key", arg_raw_value); + let expected = "key=12&key=42&key=13".to_string(); + + assert_eq!(actual, expected); + } + + #[test] + fn test_encode_env_var() { + let encoder = QueryEncoder::default(); + let raw_value = Some(ValueString::String("env_value".into())); + + let actual = encoder.encode("key", raw_value); + let expected = "key=env_value".to_string(); + + assert_eq!(actual, expected); + } + + #[test] + fn test_encode_var() { + let encoder = QueryEncoder::default(); + let raw_value = Some(ValueString::String("var_value".into())); + + let actual = encoder.encode("key", raw_value); + let expected = "key=var_value".to_string(); + + assert_eq!(actual, expected); + } + + #[test] + fn test_encode_none() { + let encoder = QueryEncoder::default(); + let raw_value: Option = None; + + let actual = encoder.encode("key", raw_value); + let expected = "key".to_owned(); + + assert_eq!(actual, expected); + } + + #[test] + fn test_encode_comma_separated_strategy() { + let key = "ids"; + let values = Value::Array(vec![ + Value::String("1".to_string()), + Value::String("2".to_string()), + Value::String("3".to_string()), + ]); + let strategy = QueryEncoder::CommaSeparated; + + let actual = strategy.encode_const_value(key, &values); + let expected = "ids=1,2,3".to_string(); + + assert_eq!(actual, expected); + } + + #[test] + fn test_encode_repeated_key_strategy() { + let key = "ids"; + let values = Value::Array(vec![ + Value::String("1".to_string()), + Value::String("2".to_string()), + Value::String("3".to_string()), + ]); + let strategy = QueryEncoder::RepeatedKey; + + let actual = strategy.encode_const_value(key, &values); + let expected = "ids=1&ids=2&ids=3".to_string(); + + assert_eq!(actual, expected); + } + + #[test] + fn test_encode_mixed_values_comma_separated() { + let key = "values"; + let values = Value::Array(vec![ + Value::String("string".to_string()), + Value::Number(42.into()), + Value::Bool(true), + ]); + let strategy = QueryEncoder::CommaSeparated; + + let actual = strategy.encode_const_value(key, &values); + let expected = "values=string,42,true".to_string(); + + assert_eq!(actual, expected); + } + + #[test] + fn test_encode_mixed_values_repeated_key() { + let key = "values"; + let values = Value::Array(vec![ + Value::String("string".to_string()), + Value::Number(42.into()), + Value::Bool(true), + ]); + let strategy = QueryEncoder::RepeatedKey; + + let actual = strategy.encode_const_value(key, &values); + let expected = "values=string&values=42&values=true".to_string(); + + assert_eq!(actual, expected); + } + + #[test] + fn test_encode_empty_list_comma_separated() { + let key = "empty"; + let values = Value::Array(vec![]); + let strategy = QueryEncoder::CommaSeparated; + + let actual = strategy.encode_const_value(key, &values); + let expected = "empty".to_string(); + + assert_eq!(actual, expected); + } + + #[test] + fn test_encode_empty_list_repeated_key() { + let key = "empty"; + let values = Value::Array(vec![]); + let strategy = QueryEncoder::RepeatedKey; + + let actual = strategy.encode_const_value(key, &values); + let expected = "empty".to_string(); + + assert_eq!(actual, expected); + } + + #[test] + fn test_encode_single_value_comma_separated() { + let key = "single"; + let values = Value::Array(vec![Value::String("value".to_string())]); + let strategy = QueryEncoder::CommaSeparated; + + let actual = strategy.encode_const_value(key, &values); + let expected = "single=value".to_string(); + + assert_eq!(actual, expected); + } + + #[test] + fn test_encode_single_value_repeated_key() { + let key = "single"; + let values = Value::Array(vec![Value::String("value".to_string())]); + let strategy = QueryEncoder::RepeatedKey; + + let actual = strategy.encode_const_value(key, &values); + let expected = "single=value".to_string(); + + assert_eq!(actual, expected); + } +} diff --git a/projects/ssddOnTop/src/http/req_template.rs b/projects/ssddOnTop/src/http/req_template.rs index a9a0470..e5e5d41 100644 --- a/projects/ssddOnTop/src/http/req_template.rs +++ b/projects/ssddOnTop/src/http/req_template.rs @@ -1,13 +1,23 @@ use crate::endpoint::Endpoint; -use crate::mustache::model::Mustache; -use std::hash::Hash; +use crate::hasher::MyHasher; +use crate::http::query_encoder::QueryEncoder; +use crate::ir::eval_ctx::EvalContext; +use crate::ir::IoId; +use crate::mustache::model::{Mustache, Segment}; +use crate::path::{PathString, PathValue, ValueString}; use hyper::Method; +use reqwest::header::HeaderValue; +use std::borrow::Cow; +use std::hash::{Hash, Hasher}; +use url::Url; +use crate::value::Value; #[derive(Debug, Clone)] pub struct RequestTemplate { pub root_url: Mustache, pub query: Vec, pub method: Method, + pub query_encoder: QueryEncoder, // pub headers: MustacheHeaders, } @@ -45,30 +55,156 @@ impl TryFrom for RequestTemplate { query, method, // headers, + query_encoder: Default::default(), }) } } -/*impl RequestTemplate { +impl RequestTemplate { pub fn cache_key(&self, ctx: &EvalContext) -> IoId { let mut hasher = MyHasher::default(); let state = &mut hasher; self.method.hash(state); - for (name, mustache) in self.headers.iter() { - name.hash(state); - mustache.render(ctx).hash(state); - } - - for (name, value) in ctx.headers().iter() { + /* for (name, value) in ctx.headers().iter() { name.hash(state); value.hash(state); - } + }*/ let url = self.create_url(ctx).unwrap(); url.hash(state); IoId::new(hasher.finish()) } -}*/ +} + +struct ValueStringEval(std::marker::PhantomData); +impl Default for ValueStringEval { + fn default() -> Self { + Self(std::marker::PhantomData) + } +} + +impl<'a, A: PathValue> ValueStringEval { + fn eval(&self, mustache: &Mustache, in_value: &'a A) -> Option> { + mustache + .segments() + .iter() + .filter_map(|segment| match segment { + Segment::Literal(text) => Some(ValueString::Value(Cow::Owned( + Value::new(serde_json::Value::String(text.to_owned())), + ))), + Segment::Expression(parts) => in_value.raw_value(parts), + }) + .next() // Return the first value that is found + } +} + +impl RequestTemplate { + /// Creates a URL for the context + /// Fills in all the mustache templates with required values. + fn create_url(&self, ctx: &C) -> anyhow::Result { + let mut url = url::Url::parse(self.root_url.render(ctx).as_str())?; + if self.query.is_empty() && self.root_url.is_const() { + return Ok(url); + } + + // evaluates mustache template and returns the values evaluated by mustache + // template. + let mustache_eval = ValueStringEval::default(); + + let extra_qp = self.query.iter().filter_map(|query| { + let key = &query.key; + let value = &query.value; + let skip = query.skip_empty; + let parsed_value = mustache_eval.eval(value, ctx); + if skip && parsed_value.is_none() { + None + } else { + Some(self.query_encoder.encode(key, parsed_value)) + } + }); + + let base_qp = url + .query_pairs() + .filter_map(|(k, v)| if v.is_empty() { None } else { Some((k, v)) }); + + let qp_string = base_qp.map(|(k, v)| format!("{}={}", k, v)); + let qp_string = qp_string.chain(extra_qp).fold("".to_string(), |str, item| { + if str.is_empty() { + item + } else if item.is_empty() { + str + } else { + format!("{}&{}", str, item) + } + }); + + if qp_string.is_empty() { + url.set_query(None); + Ok(url) + } else { + url.set_query(Some(qp_string.as_str())); + Ok(url) + } + } + + /// Checks if the template has any mustache templates or not + /// Returns true if there are not templates + pub fn is_const(&self) -> bool { + self.root_url.is_const() + && self.query.iter().all(|query| query.value.is_const()) + } + + /// Creates a Request for the given context + pub fn to_request( + &self, + ctx: &C, + ) -> anyhow::Result { + // Create url + let url = self.create_url(ctx)?; + let method = self.method.clone(); + let req = reqwest::Request::new(crate::http::method::Method::from(method).into_reqwest(), url); + // req = self.set_headers(req, ctx); + // req = self.set_body(req, ctx)?; + + Ok(req) + } + +/* /// Sets the headers for the request + fn set_headers( + &self, + mut req: reqwest::Request, + ctx: &C, + ) -> reqwest::Request { + let headers = self.create_headers(ctx); + if !headers.is_empty() { + req.headers_mut().extend(headers); + } + + let headers = req.headers_mut(); + // We want to set the header value based on encoding + // TODO: potential of optimizations. + // Can set content-type headers while creating the request template + if self.method != reqwest::Method::GET { + headers.insert( + reqwest::header::CONTENT_TYPE, + HeaderValue::from_static("application/json"), + ); + } + + headers.extend(ctx.headers().to_owned()); + req + }*/ + + pub fn new(root_url: &str) -> anyhow::Result { + Ok(Self { + root_url: Mustache::parse(root_url), + query: Default::default(), + method: Method::GET, + query_encoder: Default::default(), + }) + } + +} \ No newline at end of file diff --git a/projects/ssddOnTop/src/http/request_handler.rs b/projects/ssddOnTop/src/http/request_handler.rs index 1ec479c..022f4c3 100644 --- a/projects/ssddOnTop/src/http/request_handler.rs +++ b/projects/ssddOnTop/src/http/request_handler.rs @@ -1,13 +1,16 @@ +use std::ops::Deref; use crate::blueprint::Blueprint; use crate::http::request::Request; use bytes::Bytes; use http_body_util::Full; use std::sync::Arc; +use crate::app_ctx::AppCtx; use crate::http::method::Method; +use crate::request_context::RequestContext; pub async fn handle_request( req: Request, - blueprint: Arc, + app_ctx: AppCtx, ) -> anyhow::Result>> { let resp = match req.method { Method::GET => { @@ -16,7 +19,7 @@ pub async fn handle_request( ))) } Method::POST => { - handle_gql_req(req, blueprint).await? + handle_gql_req(req, app_ctx).await? } _ => { hyper::Response::builder() @@ -28,8 +31,18 @@ pub async fn handle_request( } async fn handle_gql_req( - _request: Request, - _blueprint: Arc, + request: Request, + app_ctx: AppCtx, ) -> anyhow::Result>> { - todo!() + let gql_req: async_graphql::Request = serde_json::from_slice(&request.body)?; + let doc = async_graphql::parser::parse_query(&gql_req.query)?; + if let Some(query) = app_ctx.blueprint.schema.query.as_ref() { + todo!() + } else { + Ok( + hyper::Response::new(Full::new(Bytes::from_static( + b"Only queries are suppored", + ))) + ) + } } \ No newline at end of file diff --git a/projects/ssddOnTop/src/http/response.rs b/projects/ssddOnTop/src/http/response.rs new file mode 100644 index 0000000..af465b0 --- /dev/null +++ b/projects/ssddOnTop/src/http/response.rs @@ -0,0 +1,114 @@ +use anyhow::Result; +use async_graphql_value::{ConstValue, Name}; +use derive_setters::Setters; +use http::StatusCode; +use http_body_util::{BodyExt, Full}; +use hyper::body::Bytes; +use indexmap::IndexMap; +use crate::http::headers::HeaderMap; + +#[derive(Clone, Debug, Default, Setters)] +pub struct Response { + pub status: StatusCode, + pub headers: HeaderMap, + pub body: Body, +} + +// Trait to convert a serde_json_borrow::Value to a ConstValue. +// serde_json_borrow::Value is a borrowed version of serde_json::Value. +// It has a limited lifetime tied to the input JSON, making it more +// efficient. Benchmarking is required to determine the performance If any +// change is made. + +pub trait FromValue { + fn from_value(value: serde_json_borrow::Value) -> Self; +} + +impl FromValue for ConstValue { + fn from_value(value: serde_json_borrow::Value) -> Self { + match value { + serde_json_borrow::Value::Null => ConstValue::Null, + serde_json_borrow::Value::Bool(b) => ConstValue::Boolean(b), + serde_json_borrow::Value::Number(n) => ConstValue::Number(n.into()), + serde_json_borrow::Value::Str(s) => ConstValue::String(s.into()), + serde_json_borrow::Value::Array(a) => { + ConstValue::List(a.into_iter().map(|v| Self::from_value(v)).collect()) + } + serde_json_borrow::Value::Object(o) => ConstValue::Object( + o.into_vec() + .into_iter() + .map(|(k, v)| (Name::new(k), Self::from_value(v))) + .collect(), + ), + } + } +} + +impl Response { + pub async fn from_reqwest(resp: reqwest::Response) -> Result { + let status = StatusCode::from_u16(resp.status().as_u16())?; + let headers = HeaderMap::from(resp.headers().to_owned()); + let body = resp.bytes().await?; + Ok(Response { status, headers, body }) + } + + pub async fn from_hyper(resp: hyper::Response>) -> Result { + let status = resp.status(); + let headers = HeaderMap::from(resp.headers().to_owned()); + let body = resp.into_body().collect().await?.to_bytes(); + Ok(Response { status, headers, body }) + } + + pub fn empty() -> Self { + Response { + status: StatusCode::OK, + headers: HeaderMap::default(), + body: Bytes::new(), + } + } + pub fn to_serde_json(self) -> Result>{ + if self.body.is_empty() { + return Ok(Response { + status: self.status, + headers: self.headers, + body: serde_json::Value::Null, + }); + } + let body: serde_json::Value = serde_json::from_slice(&self.body)?; + Ok(Response { status: self.status, headers: self.headers, body }) + } + + pub fn to_json(self) -> Result> { + if self.body.is_empty() { + return Ok(Response { + status: self.status, + headers: self.headers, + body: Default::default(), + }); + } + // Note: We convert the body to a serde_json_borrow::Value for better + // performance. Warning: Do not change this to direct conversion to `T` + // without benchmarking the performance impact. + let body: serde_json_borrow::Value = serde_json::from_slice(&self.body)?; + let body = T::from_value(body); + Ok(Response { status: self.status, headers: self.headers, body }) + } + + + pub fn to_resp_string(self) -> Result> { + Ok(Response:: { + body: String::from_utf8(self.body.to_vec())?, + status: self.status, + headers: self.headers, + }) + } +} + +impl From> for hyper::Response> { + fn from(resp: Response) -> Self { + let mut response = hyper::Response::new(Full::new(resp.body)); + *response.headers_mut() = resp.headers.into(); + *response.status_mut() = resp.status; + response + } +} diff --git a/projects/ssddOnTop/src/ir/eval_ctx.rs b/projects/ssddOnTop/src/ir/eval_ctx.rs new file mode 100644 index 0000000..ec17015 --- /dev/null +++ b/projects/ssddOnTop/src/ir/eval_ctx.rs @@ -0,0 +1,53 @@ +use std::borrow::Cow; +use std::sync::Arc; +use crate::request_context::RequestContext; +use crate::value::Value; + +#[derive(Clone)] +pub struct EvalContext<'a> { + // Context create for each GraphQL Request + pub request_ctx: &'a RequestContext, + + // graphql_ctx: &'a Ctx, + + graphql_ctx_value: Option>, + + graphql_ctx_args: Option>, +} + + +impl<'a> EvalContext<'a> { + pub fn path_arg>(&self, path: &[T]) -> Option> { + let args = self.graphql_ctx_args.as_ref()?; + get_path_value(args.as_ref(), path).map(|a| Cow::Owned(a.clone())) + } + + pub fn path_value>(&self, path: &[T]) -> Option> { + // TODO: add unit tests for this + if let Some(value) = self.graphql_ctx_value.as_ref() { + get_path_value(value.as_ref(), path).map(|a| Cow::Owned(a)) + } else { + Some(Cow::Owned(Value::new(serde_json::Value::Null))) + // get_path_value(self.graphql_ctx.value()?, path).map(Cow::Borrowed) + } + } +} + +pub fn get_path_value<'a, T: AsRef>(input: &'a Value, path: &[T]) -> Option { + let mut value = Some(input.serde()); + for name in path { + match value { + Some(serde_json::Value::Object(map)) => { + value = map.get(name.as_ref()); + } + + Some(serde_json::Value::Array(list)) => { + value = list.get(name.as_ref().parse::().ok()?); + } + _ => return None, + } + } + + value.map(|v| Value::new(v.clone())) +} + diff --git a/projects/ssddOnTop/src/ir/eval_http.rs b/projects/ssddOnTop/src/ir/eval_http.rs new file mode 100644 index 0000000..5582769 --- /dev/null +++ b/projects/ssddOnTop/src/ir/eval_http.rs @@ -0,0 +1,54 @@ +use bytes::Bytes; +use reqwest::Request; +use crate::http::RequestTemplate; +use crate::http::response::Response; +use crate::ir::eval_ctx::EvalContext; +use crate::value::Value; + +pub struct EvalHttp<'a, 'ctx> { + evaluation_ctx: &'ctx EvalContext<'a>, + request_template: &'a RequestTemplate, +} + + +impl<'a, 'ctx> EvalHttp<'a, 'ctx> { + pub fn new( + evaluation_ctx: &'ctx EvalContext<'a>, + request_template: &'a RequestTemplate, + ) -> Self { + Self { + evaluation_ctx, + request_template, + } + } + pub fn init_request(&self) -> anyhow::Result { + Ok(self.request_template.to_request(self.evaluation_ctx)?) + } + + pub async fn execute(&self, req: Request) -> anyhow::Result> { + let ctx = &self.evaluation_ctx; + let response = execute_raw_request(ctx, req).await?; + + Ok(response) + } +} + +pub async fn execute_raw_request( + ctx: &EvalContext<'_>, + req: Request, +) -> anyhow::Result> { + let response = ctx + .request_ctx + .runtime + .http + .execute(req) + .await? + .to_serde_json()?; + + let resp = Response { + status: response.status, + headers: response.headers, + body: Value::new(response.body), + }; + Ok(resp) +} \ No newline at end of file diff --git a/projects/ssddOnTop/src/ir/eval_io.rs b/projects/ssddOnTop/src/ir/eval_io.rs new file mode 100644 index 0000000..6c25d30 --- /dev/null +++ b/projects/ssddOnTop/src/ir/eval_io.rs @@ -0,0 +1,31 @@ +use crate::ir::eval_ctx::EvalContext; +use crate::ir::eval_http::EvalHttp; +use crate::ir::IO; +use crate::request_context::CacheErr; +use crate::value::Value; + +pub async fn eval_io(io: &IO, ctx: &mut EvalContext<'_>) -> anyhow::Result { + let key = io.cache_key(ctx); + + ctx.request_ctx + .cache + .dedupe(&key, || async { + ctx.request_ctx + .cache + .dedupe(&key, || eval_io_inner(io, ctx)) + .await + }) + .await.map_err(|v| v.into()) +} + +async fn eval_io_inner(io: &IO, ctx: &mut EvalContext<'_>) -> Result { + match io { + IO::Http { req_template, .. } => { + let eval_http = EvalHttp::new(ctx, req_template); + let request = eval_http.init_request()?; + let response = eval_http.execute(request).await?; + + Ok(response.body) + } + } +} \ No newline at end of file diff --git a/projects/ssddOnTop/src/ir/mod.rs b/projects/ssddOnTop/src/ir/mod.rs index 90a9ec9..321df7b 100644 --- a/projects/ssddOnTop/src/ir/mod.rs +++ b/projects/ssddOnTop/src/ir/mod.rs @@ -1,5 +1,8 @@ mod discriminator; mod model; +pub mod eval_ctx; +mod eval_io; +mod eval_http; pub use discriminator::*; pub use model::*; diff --git a/projects/ssddOnTop/src/ir/model.rs b/projects/ssddOnTop/src/ir/model.rs index fc8d49d..2269589 100644 --- a/projects/ssddOnTop/src/ir/model.rs +++ b/projects/ssddOnTop/src/ir/model.rs @@ -1,5 +1,8 @@ use crate::http; use std::num::NonZeroU64; +use crate::ir::eval_ctx::EvalContext; +use crate::ir::eval_io::eval_io; +use crate::value::Value; // use crate::jit::eval_ctx::EvalContext; #[derive(Clone, Debug)] @@ -44,14 +47,27 @@ impl IoId { pub enum IO { Http { req_template: http::RequestTemplate, - dl_id: Option, }, } -/*impl<'a> IO { - fn cache_key(&self, ctx: &EvalContext<'a>) -> IoId { +impl IR { + pub async fn eval<'a, 'b, Ctx>( + &'a self, + ctx: &'b mut EvalContext<'a>, + ) -> anyhow::Result { + match self { + IR::IO(io) => { + eval_io(io, ctx).await + } + IR::Cache(_) => todo!() + } + } +} + +impl<'a> IO { + pub fn cache_key(&self, ctx: &EvalContext<'a>) -> IoId { match self { IO::Http { req_template, .. } => req_template.cache_key(ctx), } } -}*/ +} diff --git a/projects/ssddOnTop/src/jit/mod.rs b/projects/ssddOnTop/src/jit/mod.rs new file mode 100644 index 0000000..e3ce5fc --- /dev/null +++ b/projects/ssddOnTop/src/jit/mod.rs @@ -0,0 +1 @@ +mod model; \ No newline at end of file diff --git a/projects/ssddOnTop/src/jit/model.rs b/projects/ssddOnTop/src/jit/model.rs new file mode 100644 index 0000000..0230dae --- /dev/null +++ b/projects/ssddOnTop/src/jit/model.rs @@ -0,0 +1,9 @@ +use std::collections::HashMap; +use crate::value::Value; + +pub struct Field { + args: HashMap, +} +pub struct Operation { + +} \ No newline at end of file diff --git a/projects/ssddOnTop/src/lib.rs b/projects/ssddOnTop/src/lib.rs index 8337016..0a4a8f9 100644 --- a/projects/ssddOnTop/src/lib.rs +++ b/projects/ssddOnTop/src/lib.rs @@ -15,6 +15,9 @@ mod value; mod target_runtime; mod cache; mod app_ctx; +mod request_context; +mod jit; +mod dl; pub fn is_default(val: &T) -> bool { *val == T::default() diff --git a/projects/ssddOnTop/src/path.rs b/projects/ssddOnTop/src/path.rs index b6afe7b..96fb7dd 100644 --- a/projects/ssddOnTop/src/path.rs +++ b/projects/ssddOnTop/src/path.rs @@ -1,9 +1,9 @@ use std::borrow::Cow; use serde_json::json; - -// use crate::jit::eval_ctx::EvalContext; +use crate::ir::eval_ctx::EvalContext; use crate::json::JsonLike; +use crate::value::Value; /// /// The path module provides a trait for accessing values from a JSON-like @@ -40,18 +40,31 @@ impl PathString for serde_json::Value { } } -fn convert_value(value: Cow<'_, async_graphql::Value>) -> Option> { +fn convert_value(value: Cow<'_, Value>) -> Option> { + // let value = value.serde(); match value { - Cow::Owned(async_graphql::Value::String(s)) => Some(Cow::Owned(s)), - Cow::Owned(async_graphql::Value::Number(n)) => Some(Cow::Owned(n.to_string())), - Cow::Owned(async_graphql::Value::Boolean(b)) => Some(Cow::Owned(b.to_string())), - Cow::Owned(async_graphql::Value::Object(map)) => Some(json!(map).to_string().into()), - Cow::Owned(async_graphql::Value::List(list)) => Some(json!(list).to_string().into()), - Cow::Borrowed(async_graphql::Value::String(s)) => Some(Cow::Borrowed(s.as_str())), - Cow::Borrowed(async_graphql::Value::Number(n)) => Some(Cow::Owned(n.to_string())), - Cow::Borrowed(async_graphql::Value::Boolean(b)) => Some(Cow::Owned(b.to_string())), - Cow::Borrowed(async_graphql::Value::Object(map)) => Some(json!(map).to_string().into()), - Cow::Borrowed(async_graphql::Value::List(list)) => Some(json!(list).to_string().into()), + Cow::Owned(val) => { + let val = val.into_serde(); + match val { + serde_json::Value::String(s) => Some(Cow::Owned(s)), + serde_json::Value::Number(n) => Some(Cow::Owned(n.to_string())), + serde_json::Value::Bool(b) => Some(Cow::Owned(b.to_string())), + serde_json::Value::Object(map) => Some(json!(map).to_string().into()), + serde_json::Value::Array(list) => Some(json!(list).to_string().into()), + _ => None, + } + }, + Cow::Borrowed(val) => { + let val = val.serde(); + match val { + serde_json::Value::String(s) => Some(Cow::Borrowed(s)), + serde_json::Value::Number(n) => Some(Cow::Owned(n.to_string())), + serde_json::Value::Bool(b) => Some(Cow::Owned(b.to_string())), + serde_json::Value::Object(map) => Some(json!(map).to_string().into()), + serde_json::Value::Array(list) => Some(json!(list).to_string().into()), + _ => None, + } + }, _ => None, } } @@ -59,13 +72,13 @@ fn convert_value(value: Cow<'_, async_graphql::Value>) -> Option> { /// /// An optimized version of async_graphql::Value that handles strings in a more /// efficient manner. -#[derive(Clone, Debug, PartialEq)] +#[derive(Debug)] pub enum ValueString<'a> { - Value(Cow<'a, async_graphql::Value>), + Value(Cow<'a, Value>), String(Cow<'a, str>), } -/*impl<'a> EvalContext<'a> { +impl<'a> EvalContext<'a> { fn to_raw_value>(&self, path: &[T]) -> Option> { let ctx = self; @@ -77,9 +90,9 @@ pub enum ValueString<'a> { return match path[0].as_ref() { "value" => Some(ValueString::Value(ctx.path_value(&[] as &[T])?)), "args" => Some(ValueString::Value(ctx.path_arg::<&str>(&[])?)), - "vars" => Some(ValueString::String(Cow::Owned( + /* "vars" => Some(ValueString::String(Cow::Owned( json!(ctx.vars()).to_string(), - ))), + ))),*/ _ => None, }; } @@ -88,13 +101,13 @@ pub enum ValueString<'a> { .and_then(move |(head, tail)| match head.as_ref() { "value" => Some(ValueString::Value(ctx.path_value(tail)?)), "args" => Some(ValueString::Value(ctx.path_arg(tail)?)), - "headers" => Some(ValueString::String(Cow::Borrowed( + /* "headers" => Some(ValueString::String(Cow::Borrowed( ctx.header(tail[0].as_ref())?, ))), "vars" => Some(ValueString::String(Cow::Borrowed( ctx.var(tail[0].as_ref())?, - ))), - "env" => Some(ValueString::String(ctx.env_var(tail[0].as_ref())?)), + ))),*/ + // "env" => Some(ValueString::String(ctx.env_var(tail[0].as_ref())?)), _ => None, }) } @@ -126,7 +139,7 @@ impl<'a> PathGraphql for EvalContext<'a> { ValueString::String(val) => format!(r#""{val}""#), }) } -}*/ +} /*#[cfg(test)] mod tests { diff --git a/projects/ssddOnTop/src/request_context.rs b/projects/ssddOnTop/src/request_context.rs index bc2fd8e..b438497 100644 --- a/projects/ssddOnTop/src/request_context.rs +++ b/projects/ssddOnTop/src/request_context.rs @@ -1,29 +1,38 @@ use std::num::NonZeroU64; -use std::str::FromStr; use std::sync::{Arc, Mutex}; - -use async_graphql_value::ConstValue; -use cache_control::{Cachability, CacheControl}; -use derive_setters::Setters; -use reqwest::header::{HeaderMap, HeaderName, HeaderValue}; -use crate::blueprint::{Blueprint, Server, Upstream}; +use anyhow::Error; +use crate::app_ctx::AppCtx; +use crate::blueprint::{Server, Upstream}; use crate::ir::IoId; +use crate::target_runtime::TargetRuntime; +use crate::value::Value; +use derive_setters::Setters; +use crate::dl::dedupe::Dedupe; + +#[derive(Clone)] +pub struct CacheErr(String); + +impl From for CacheErr { + fn from(value: Error) -> Self { + CacheErr(value.to_string()) + } +} + +impl From for anyhow::Error { + fn from(value: CacheErr) -> Self { + anyhow::Error::msg(value.0) + } +} #[derive(Setters)] pub struct RequestContext { pub server: Server, pub upstream: Upstream, - pub x_response_headers: Arc>, - pub cookie_headers: Option>>, - // A subset of all the headers received in the GraphQL Request that will be sent to the - // upstream. - pub allowed_headers: HeaderMap, - pub http_data_loaders: Arc>>, pub min_max_age: Arc>>, pub cache_public: Arc>>, pub runtime: TargetRuntime, - pub cache: DedupeResult, - pub dedupe_handler: Arc>, + // pub cache: DedupeResult, + pub cache: Dedupe>, } impl RequestContext { @@ -31,15 +40,10 @@ impl RequestContext { RequestContext { server: Default::default(), upstream: Default::default(), - x_response_headers: Arc::new(Mutex::new(HeaderMap::new())), - cookie_headers: None, - http_data_loaders: Arc::new(vec![]), min_max_age: Arc::new(Mutex::new(None)), cache_public: Arc::new(Mutex::new(None)), runtime: target_runtime, - cache: DedupeResult::new(true), - dedupe_handler: Arc::new(DedupeResult::new(false)), - allowed_headers: HeaderMap::new(), + cache: Dedupe::new(1, true), } } fn set_min_max_age_conc(&self, min_max_age: i32) { @@ -70,58 +74,7 @@ impl RequestContext { } } - pub fn set_cache_visibility(&self, cachability: &Option) { - if let Some(Cachability::Private) = cachability { - self.set_cache_public_false() - } - } - - pub fn set_cache_control(&self, cache_policy: CacheControl) { - if let Some(max_age) = cache_policy.max_age { - self.set_min_max_age(max_age.as_secs() as i32); - } - self.set_cache_visibility(&cache_policy.cachability); - if Some(Cachability::NoCache) == cache_policy.cachability { - self.set_min_max_age(-1); - } - } - - pub fn set_cookie_headers(&self, headers: &HeaderMap) { - // TODO fix execution_spec test and use append method - // to allow multiple set cookie - if let Some(map) = &self.cookie_headers { - let map = &mut map.lock().unwrap(); - - // Check if the incoming headers contain 'set-cookie' - if let Some(new_cookies) = headers.get("set-cookie") { - let cookie_name = HeaderName::from_str("set-cookie").unwrap(); - - // Check if 'set-cookie' already exists in our map - if let Some(existing_cookies) = map.get(&cookie_name) { - // Convert the existing HeaderValue to a str, append the new cookies, - // and then convert back to a HeaderValue. If the conversion fails, we skip - // appending. - if let Ok(existing_str) = existing_cookies.to_str() { - if let Ok(new_cookies_str) = new_cookies.to_str() { - // Create a new value by appending the new cookies to the existing ones - let combined_cookies = format!("{}; {}", existing_str, new_cookies_str); - - // Replace the old value with the new, combined value - map.insert( - cookie_name, - HeaderValue::from_str(&combined_cookies).unwrap(), - ); - } - } - } else { - // If 'set-cookie' does not already exist in our map, just insert the new value - map.insert(cookie_name, new_cookies.clone()); - } - } - } - } - - pub async fn cache_get(&self, key: &IoId) -> Result, anyhow::Error> { + pub async fn cache_get(&self, key: &IoId) -> Result>, anyhow::Error> { self.runtime.cache.get(key).await } @@ -129,38 +82,22 @@ impl RequestContext { pub async fn cache_insert( &self, key: IoId, - value: ConstValue, + value: Value, ttl: NonZeroU64, ) -> Result<(), anyhow::Error> { self.runtime.cache.set(key, value, ttl).await } - - - /// Modifies existing headers to include the experimental headers - pub fn extend_x_headers(&self, headers: &mut HeaderMap) { - if self.has_experimental_headers() { - let x_response_headers = &self.x_response_headers.lock().unwrap(); - for (header, value) in x_response_headers.iter() { - headers.insert(header, value.clone()); - } - } - } } -impl From<&Blueprint> for RequestContext { - fn from(blueprint: &Blueprint) -> Self { +impl From<&AppCtx> for RequestContext { + fn from(app_ctx: &AppCtx) -> Self { Self { - server: blueprint.server.clone(), - upstream: blueprint.upstream.clone(), - x_response_headers: Arc::new(Mutex::new(HeaderMap::new())), - cookie_headers, - allowed_headers: HeaderMap::new(), - http_data_loaders: app_ctx.http_data_loaders.clone(), - min_max_age: Arc::new(Mutex::new(None)), + server: app_ctx.blueprint.server.clone(), + upstream: app_ctx.blueprint.upstream.clone(), + min_max_age: Arc::new(Mutex::new(None)), cache_public: Arc::new(Mutex::new(None)), runtime: app_ctx.runtime.clone(), - cache: DedupeResult::new(true), - dedupe_handler: app_ctx.dedupe_handler.clone(), + cache: Dedupe::new(1, true), } } } diff --git a/projects/ssddOnTop/src/run/http1.rs b/projects/ssddOnTop/src/run/http1.rs index 60146be..acfa365 100644 --- a/projects/ssddOnTop/src/run/http1.rs +++ b/projects/ssddOnTop/src/run/http1.rs @@ -5,33 +5,33 @@ use std::net::SocketAddr; use std::sync::Arc; use tokio::net::TcpListener; use tokio::sync::oneshot; +use crate::app_ctx::AppCtx; -pub async fn start(blueprint: Blueprint) -> anyhow::Result<()> { - let blueprint = Arc::new(blueprint); - let addr = blueprint.server.addr(); +pub async fn start(app_ctx: AppCtx) -> anyhow::Result<()> { + let addr = app_ctx.blueprint.server.addr(); let listener = TcpListener::bind(addr).await?; tracing::info!("Listening on: http://{}", addr); loop { - let blueprint = blueprint.clone(); + let app_ctx = app_ctx.clone(); let stream_result = listener.accept().await; match stream_result { Ok((stream, _)) => { let io = hyper_util::rt::TokioIo::new(stream); tokio::spawn(async move { - let blueprint = blueprint.clone(); + let app_ctx = app_ctx.clone(); let server = hyper::server::conn::http1::Builder::new() .serve_connection( io, service_fn(move |req| { - let blueprint = blueprint.clone(); + let app_ctx = app_ctx.clone(); async move { let req = crate::http::request::Request::from_hyper(req).await?; - handle_request(req, blueprint).await + handle_request(req, app_ctx).await } }), ) diff --git a/projects/ssddOnTop/src/run/run.rs b/projects/ssddOnTop/src/run/run.rs index b76918a..7e6ffa7 100644 --- a/projects/ssddOnTop/src/run/run.rs +++ b/projects/ssddOnTop/src/run/run.rs @@ -1,6 +1,9 @@ +use std::sync::Arc; +use crate::app_ctx::AppCtx; use crate::blueprint::Blueprint; use crate::config::ConfigReader; use crate::run; +use crate::target_runtime::TargetRuntime; pub async fn run() -> anyhow::Result<()> { let config_reader = ConfigReader::init(); @@ -11,7 +14,10 @@ pub async fn run() -> anyhow::Result<()> { }); let config = config_reader.read(path)?; + let blueprint = Blueprint::try_from(&config)?; - run::http1::start(blueprint).await?; + let rt = TargetRuntime::new(&blueprint.upstream); + let app_ctx = AppCtx::new(rt, Arc::new(blueprint)); + run::http1::start(app_ctx).await?; Ok(()) } diff --git a/projects/ssddOnTop/src/target_runtime.rs b/projects/ssddOnTop/src/target_runtime.rs index 47fc05f..7b83d8d 100644 --- a/projects/ssddOnTop/src/target_runtime.rs +++ b/projects/ssddOnTop/src/target_runtime.rs @@ -1,93 +1,76 @@ -use std::sync::Arc; -use crate::target_runtime::cache::HttpCacheManager; use crate::target_runtime::http::NativeHttp; +use std::sync::Arc; +use crate::blueprint::Upstream; +use crate::ir::IoId; +use crate::value::Value; #[derive(Clone)] pub struct TargetRuntime { /// HTTP client for making standard HTTP requests. pub http: Arc, - pub cache: Arc, + pub cache: Arc>, } -mod cache { - use http_cache_reqwest::{CacheManager, HttpResponse}; - use http_cache_semantics::CachePolicy; - use serde::{Deserialize, Serialize}; - pub type BoxError = Box; - pub type Result = std::result::Result; - use std::sync::Arc; - - use moka::future::Cache; - use moka::policy::EvictionPolicy; - - pub struct HttpCacheManager { - pub cache: Arc>, +impl TargetRuntime { + pub fn new(upstream: &Upstream) -> Self { + let http = Arc::new(NativeHttp::init(upstream)); + let cache = Arc::new(cache::InMemoryCache::new()); + Self { http, cache } } +} - impl Default for HttpCacheManager { - fn default() -> Self { - Self::new(42) - } - } +mod cache { + use std::hash::Hash; + use std::num::NonZeroU64; + use std::sync::{Arc, RwLock}; + use std::time::Duration; + + use ttl_cache::TtlCache; + use crate::value::ToInner; - #[derive(Clone, Deserialize, Serialize)] - pub struct Store { - response: HttpResponse, - policy: CachePolicy, + pub struct InMemoryCache { + data: Arc>>, } - impl HttpCacheManager { - pub fn new(cache_size: u64) -> Self { - let cache = Cache::builder() - .eviction_policy(EvictionPolicy::lru()) - .max_capacity(cache_size) - .build(); - Self { cache: Arc::new(cache) } - } + const CACHE_CAPACITY: usize = 100000; - pub async fn clear(&self) -> Result<()> { - self.cache.invalidate_all(); - self.cache.run_pending_tasks().await; - Ok(()) + impl Default for InMemoryCache { + fn default() -> Self { + Self::new() } } - #[async_trait::async_trait] - impl CacheManager for HttpCacheManager { - async fn get(&self, cache_key: &str) -> Result> { - let store: Store = match self.cache.get(cache_key).await { - Some(d) => d, - None => return Ok(None), - }; - Ok(Some((store.response, store.policy))) + impl InMemoryCache { + pub fn new() -> Self { + InMemoryCache { + data: Arc::new(RwLock::new(TtlCache::new(CACHE_CAPACITY))), + } } + } - async fn put( - &self, - cache_key: String, - response: HttpResponse, - policy: CachePolicy, - ) -> Result { - let data = Store { response: response.clone(), policy }; - self.cache.insert(cache_key, data).await; - self.cache.run_pending_tasks().await; - Ok(response) + impl, Inner: Clone> InMemoryCache { + pub async fn set<'a>(&'a self, key: K, value: V, ttl: NonZeroU64) -> anyhow::Result<()> { + let ttl = Duration::from_millis(ttl.get()); + self.data.write().unwrap().insert(key, value, ttl); + Ok(()) } - async fn delete(&self, cache_key: &str) -> Result<()> { - self.cache.invalidate(cache_key).await; - self.cache.run_pending_tasks().await; - Ok(()) + pub async fn get<'a>(&'a self, key: &'a K) -> anyhow::Result> { + let val = self.data.read().unwrap().get(key).map(|v| v.to_inner()); + Ok(val) } } } mod http { + use bytes::Bytes; + use crate::blueprint::Upstream; + use crate::cache::HttpCacheManager; use http_cache_reqwest::{Cache, CacheMode, HttpCache, HttpCacheOptions}; use reqwest::Client; use reqwest_middleware::{ClientBuilder, ClientWithMiddleware}; - use crate::blueprint::Upstream; - use crate::cache::HttpCacheManager; + use crate::http::response::Response; + use anyhow::Result; pub struct NativeHttp { client: ClientWithMiddleware, @@ -107,5 +90,23 @@ mod http { client: client.build(), } } + pub async fn execute(&self, mut request: reqwest::Request) -> Result> { + tracing::info!( + "{} {} {:?}", + request.method(), + request.url(), + request.version() + ); + tracing::debug!("request: {:?}", request); + let response = self.client.execute(request).await; + tracing::debug!("response: {:?}", response); + + Ok(Response::from_reqwest( + response? + .error_for_status() + .map_err(|err| err.without_url())?, + ) + .await?) + } } } \ No newline at end of file diff --git a/projects/ssddOnTop/src/value/value.rs b/projects/ssddOnTop/src/value/value.rs index 651ad37..dd74401 100644 --- a/projects/ssddOnTop/src/value/value.rs +++ b/projects/ssddOnTop/src/value/value.rs @@ -1,17 +1,40 @@ +use std::fmt::{Display, Formatter}; use derive_getters::Getters; -#[derive(Clone, Getters)] +pub trait ToInner { + type Inner; + fn to_inner(&self) -> Self::Inner; +} + +impl ToInner for Value { + type Inner = serde_json_borrow::Value<'static>; + + fn to_inner(&self) -> Self::Inner { + self.borrowed.clone() + } +} + +#[derive(Getters, Debug, Clone, PartialEq, Eq, Hash)] pub struct Value { serde: serde_json::Value, borrowed: serde_json_borrow::Value<'static>, } +impl Display for Value { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.serde) + } +} + impl Value { pub fn new(serde: serde_json::Value) -> Self { let borrowed = serde_json_borrow::Value::from(&serde); let borrowed = extend_lifetime(borrowed); Self { serde, borrowed } } + pub fn into_serde(self) -> serde_json::Value { + self.serde + } } fn extend_lifetime<'b>(r: serde_json_borrow::Value<'b>) -> serde_json_borrow::Value<'static> { From 5fcdf1a2102f603aad4711faf0ccc1642f5fde2c Mon Sep 17 00:00:00 2001 From: Sandipsinh Rathod Date: Wed, 11 Sep 2024 21:44:24 -0400 Subject: [PATCH 06/21] partial --- Cargo.lock | 67 +- projects/ssddOnTop/Cargo.lock | 3120 +++++++++++++++++ projects/ssddOnTop/Cargo.toml | 7 +- projects/ssddOnTop/macros-common/Cargo.toml | 8 + .../ssddOnTop/macros-common/src/common.rs | 43 + .../macros-common/src/directive_definition.rs | 93 + .../macros-common/src/enum_definition.rs | 56 + .../macros-common/src/input_definition.rs | 177 + projects/ssddOnTop/macros-common/src/lib.rs | 53 + .../macros-common/src/scalar_definition.rs | 21 + projects/ssddOnTop/macros/Cargo.toml | 14 + .../macros/src/document_definition.rs | 93 + projects/ssddOnTop/macros/src/gen.rs | 100 + projects/ssddOnTop/macros/src/lib.rs | 54 + projects/ssddOnTop/macros/src/merge_right.rs | 151 + projects/ssddOnTop/macros/src/resolver.rs | 91 + projects/ssddOnTop/src/blueprint/blueprint.rs | 4 +- projects/ssddOnTop/src/blueprint/model.rs | 6 + .../ssddOnTop/src/blueprint/operators/http.rs | 6 - projects/ssddOnTop/src/config/config.rs | 29 +- projects/ssddOnTop/src/config/url_query.rs | 2 +- projects/ssddOnTop/src/directive.rs | 80 +- projects/ssddOnTop/src/from_doc.rs | 4 +- projects/ssddOnTop/src/http/method.rs | 2 +- .../ssddOnTop/src/http/request_handler.rs | 23 +- projects/ssddOnTop/src/ir/eval_ctx.rs | 7 + projects/ssddOnTop/src/ir/model.rs | 2 +- 27 files changed, 4278 insertions(+), 35 deletions(-) create mode 100644 projects/ssddOnTop/Cargo.lock create mode 100644 projects/ssddOnTop/macros-common/Cargo.toml create mode 100644 projects/ssddOnTop/macros-common/src/common.rs create mode 100644 projects/ssddOnTop/macros-common/src/directive_definition.rs create mode 100644 projects/ssddOnTop/macros-common/src/enum_definition.rs create mode 100644 projects/ssddOnTop/macros-common/src/input_definition.rs create mode 100644 projects/ssddOnTop/macros-common/src/lib.rs create mode 100644 projects/ssddOnTop/macros-common/src/scalar_definition.rs create mode 100644 projects/ssddOnTop/macros/Cargo.toml create mode 100644 projects/ssddOnTop/macros/src/document_definition.rs create mode 100644 projects/ssddOnTop/macros/src/gen.rs create mode 100644 projects/ssddOnTop/macros/src/lib.rs create mode 100644 projects/ssddOnTop/macros/src/merge_right.rs create mode 100644 projects/ssddOnTop/macros/src/resolver.rs diff --git a/Cargo.lock b/Cargo.lock index 8c50865..d27f25e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -102,9 +102,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.87" +version = "1.0.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10f00e1f6e58a40e807377c75c6a7f97bf9044fab57816f2414e6f5f4499d7b8" +checksum = "4e1496f8fb1fbf272686b8d37f523dab3e4a7443300055e74cdaa449f3114356" [[package]] name = "ascii_utils" @@ -882,6 +882,12 @@ dependencies = [ "crypto-common", ] +[[package]] +name = "dyn-clone" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" + [[package]] name = "easy_retry" version = "0.1.0" @@ -1743,6 +1749,25 @@ dependencies = [ "value-bag", ] +[[package]] +name = "macros" +version = "0.1.0" +dependencies = [ + "anyhow", + "macros_common", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "macros_common" +version = "0.1.0" +dependencies = [ + "async-graphql", + "schemars", +] + [[package]] name = "matchers" version = "0.1.0" @@ -2677,6 +2702,30 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "schemars" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09c024468a378b7e36765cd36702b7a90cc3cba11654f6685c8f233408e89e92" +dependencies = [ + "dyn-clone", + "schemars_derive", + "serde", + "serde_json", +] + +[[package]] +name = "schemars_derive" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1eee588578aff73f856ab961cd2f79e36bc45d7ded33a7562adba4667aecc0e" +dependencies = [ + "proc-macro2", + "quote", + "serde_derive_internals", + "syn", +] + [[package]] name = "scopeguard" version = "1.2.0" @@ -2732,6 +2781,17 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_derive_internals" +version = "0.29.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "serde_json" version = "1.0.127" @@ -2908,6 +2968,8 @@ dependencies = [ "hyper-util", "indenter", "indexmap", + "macros", + "macros_common", "moka", "nom", "num_cpus", @@ -2915,6 +2977,7 @@ dependencies = [ "prost-reflect", "reqwest 0.11.27", "reqwest-middleware", + "schemars", "serde", "serde_json", "serde_json_borrow", diff --git a/projects/ssddOnTop/Cargo.lock b/projects/ssddOnTop/Cargo.lock new file mode 100644 index 0000000..766906b --- /dev/null +++ b/projects/ssddOnTop/Cargo.lock @@ -0,0 +1,3120 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "Inflector" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" +dependencies = [ + "lazy_static", + "regex", +] + +[[package]] +name = "addr2line" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5fb1d8e4442bd405fdfd1dacb42792696b0cf9cb15882e5d097b742a676d375" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "anstream" +version = "0.6.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" + +[[package]] +name = "anstyle-parse" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + +[[package]] +name = "anyhow" +version = "1.0.88" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e1496f8fb1fbf272686b8d37f523dab3e4a7443300055e74cdaa449f3114356" + +[[package]] +name = "ascii_utils" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71938f30533e4d95a6d17aa530939da3842c2ab6f4f84b9dae68447e4129f74a" + +[[package]] +name = "async-channel" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81953c529336010edd6d8e358f886d9581267795c61b19475b71314bffa46d35" +dependencies = [ + "concurrent-queue", + "event-listener 2.5.3", + "futures-core", +] + +[[package]] +name = "async-channel" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89b47800b0be77592da0afd425cc03468052844aff33b84e33cc696f64e77b6a" +dependencies = [ + "concurrent-queue", + "event-listener-strategy", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-executor" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30ca9a001c1e8ba5149f91a74362376cc6bc5b919d92d988668657bd570bdcec" +dependencies = [ + "async-task", + "concurrent-queue", + "fastrand", + "futures-lite", + "slab", +] + +[[package]] +name = "async-global-executor" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05b1b633a2115cd122d73b955eadd9916c18c8f510ec9cd1686404c60ad1c29c" +dependencies = [ + "async-channel 2.3.1", + "async-executor", + "async-io", + "async-lock", + "blocking", + "futures-lite", + "once_cell", +] + +[[package]] +name = "async-graphql" +version = "7.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d37c3e9ba322eb00e9e5e997d58f08e8b6de037325b9367ac59bca8e3cd46af" +dependencies = [ + "async-graphql-derive", + "async-graphql-parser", + "async-graphql-value", + "async-stream", + "async-trait", + "base64 0.22.1", + "bytes", + "fast_chemail", + "fnv", + "futures-timer", + "futures-util", + "handlebars", + "http 1.1.0", + "indexmap", + "mime", + "multer", + "num-traits", + "once_cell", + "pin-project-lite", + "regex", + "serde", + "serde_json", + "serde_urlencoded", + "static_assertions_next", + "tempfile", + "thiserror", +] + +[[package]] +name = "async-graphql-derive" +version = "7.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1141703c11c6ad4fa9b3b0e1e476dea01dbd18a44db00f949b804afaab2f344" +dependencies = [ + "Inflector", + "async-graphql-parser", + "darling", + "proc-macro-crate", + "proc-macro2", + "quote", + "strum", + "syn", + "thiserror", +] + +[[package]] +name = "async-graphql-parser" +version = "7.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f66edcce4c38c18f7eb181fdf561c3d3aa2d644ce7358fc7a928c00a4ffef17" +dependencies = [ + "async-graphql-value", + "pest", + "serde", + "serde_json", +] + +[[package]] +name = "async-graphql-value" +version = "7.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0206011cad065420c27988f17dd7fe201a0e056b20c262209b7bffcd6fa176" +dependencies = [ + "bytes", + "indexmap", + "serde", + "serde_json", +] + +[[package]] +name = "async-io" +version = "2.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "444b0228950ee6501b3568d3c93bf1176a1fdbc3b758dcd9475046d30f4dc7e8" +dependencies = [ + "async-lock", + "cfg-if", + "concurrent-queue", + "futures-io", + "futures-lite", + "parking", + "polling", + "rustix", + "slab", + "tracing", + "windows-sys 0.59.0", +] + +[[package]] +name = "async-lock" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff6e472cdea888a4bd64f342f09b3f50e1886d32afe8df3d663c01140b811b18" +dependencies = [ + "event-listener 5.3.1", + "event-listener-strategy", + "pin-project-lite", +] + +[[package]] +name = "async-process" +version = "2.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8a07789659a4d385b79b18b9127fc27e1a59e1e89117c78c5ea3b806f016374" +dependencies = [ + "async-channel 2.3.1", + "async-io", + "async-lock", + "async-signal", + "async-task", + "blocking", + "cfg-if", + "event-listener 5.3.1", + "futures-lite", + "rustix", + "tracing", + "windows-sys 0.59.0", +] + +[[package]] +name = "async-signal" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "637e00349800c0bdf8bfc21ebbc0b6524abea702b0da4168ac00d070d0c0b9f3" +dependencies = [ + "async-io", + "async-lock", + "atomic-waker", + "cfg-if", + "futures-core", + "futures-io", + "rustix", + "signal-hook-registry", + "slab", + "windows-sys 0.59.0", +] + +[[package]] +name = "async-std" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c634475f29802fde2b8f0b505b1bd00dfe4df7d4a000f0b36f7671197d5c3615" +dependencies = [ + "async-channel 1.9.0", + "async-global-executor", + "async-io", + "async-lock", + "async-process", + "crossbeam-utils", + "futures-channel", + "futures-core", + "futures-io", + "futures-lite", + "gloo-timers", + "kv-log-macro", + "log", + "memchr", + "once_cell", + "pin-project-lite", + "pin-utils", + "slab", + "wasm-bindgen-futures", +] + +[[package]] +name = "async-stream" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd56dd203fef61ac097dd65721a419ddccb106b2d2b70ba60a6b529f03961a51" +dependencies = [ + "async-stream-impl", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-stream-impl" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "async-task" +version = "4.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de" + +[[package]] +name = "async-trait" +version = "0.1.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a27b8a3a6e1a44fa4c8baf1f653e4172e81486d4941f2237e20dc2d0cf4ddff1" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" +dependencies = [ + "addr2line", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", + "windows-targets 0.52.6", +] + +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "blocking" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "703f41c54fc768e63e091340b424302bb1c29ef4aa0c7f10fe849dfb114d29ea" +dependencies = [ + "async-channel 2.3.1", + "async-task", + "futures-io", + "futures-lite", + "piper", +] + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" +dependencies = [ + "serde", +] + +[[package]] +name = "cacache" +version = "12.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "142316461ed3a3dfcba10417317472da5bfd0461e4d276bf7c07b330766d9490" +dependencies = [ + "async-std", + "digest", + "either", + "futures", + "hex", + "libc", + "memmap2", + "miette", + "reflink-copy", + "serde", + "serde_derive", + "serde_json", + "sha1", + "sha2", + "ssri", + "tempfile", + "thiserror", + "walkdir", +] + +[[package]] +name = "cc" +version = "1.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b62ac837cdb5cb22e10a256099b4fc502b1dfe560cb282963a974d7abd80e476" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "colorchoice" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" + +[[package]] +name = "concurrent-queue" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + +[[package]] +name = "convert_case" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cpufeatures" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" +dependencies = [ + "libc", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33480d6946193aa8033910124896ca395333cae7e2d1113d1fef6c3272217df2" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "darling" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" +dependencies = [ + "darling_core", + "quote", + "syn", +] + +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", +] + +[[package]] +name = "derive-getters" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74ef43543e701c01ad77d3a5922755c6a1d71b22d942cb8042be4994b380caff" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "convert_case 0.4.0", + "proc-macro2", + "quote", + "rustc_version", + "syn", +] + +[[package]] +name = "derive_setters" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e8ef033054e131169b8f0f9a7af8f5533a9436fadf3c500ed547f730f07090d" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "diff" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "env_filter" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f2c92ceda6ceec50f43169f9ee8424fe2db276791afde7b2cd8bc084cb376ab" +dependencies = [ + "log", +] + +[[package]] +name = "env_logger" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13fa619b91fb2381732789fc5de83b45675e882f66623b7d8cb4f643017018d" +dependencies = [ + "anstream", + "anstyle", + "env_filter", + "log", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "event-listener" +version = "2.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" + +[[package]] +name = "event-listener" +version = "5.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6032be9bd27023a771701cc49f9f053c751055f71efb2e0ae5c15809093675ba" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite", +] + +[[package]] +name = "event-listener-strategy" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f214dc438f977e6d4e3500aaa277f5ad94ca83fbbd9b1a15713ce2344ccc5a1" +dependencies = [ + "event-listener 5.3.1", + "pin-project-lite", +] + +[[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 = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-lite" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52527eb5074e35e9339c6b4e8d12600c7128b68fb25dcb9fa9dec18f7c25f3a5" +dependencies = [ + "fastrand", + "futures-core", + "futures-io", + "parking", + "pin-project-lite", +] + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-timer" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "gimli" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64" + +[[package]] +name = "gloo-timers" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbb143cf96099802033e0d4f4963b19fd2e0b728bcf076cd9cf7f6634f092994" +dependencies = [ + "futures-channel", + "futures-core", + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "h2" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http 0.2.12", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "handlebars" +version = "5.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d08485b96a0e6393e9e4d1b8d48cf74ad6c063cd905eb33f42c1ce3f0377539b" +dependencies = [ + "log", + "pest", + "pest_derive", + "serde", + "serde_json", + "thiserror", +] + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "hermit-abi" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "http" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" +dependencies = [ + "bytes", + "http 0.2.12", + "pin-project-lite", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http 1.1.0", +] + +[[package]] +name = "http-body-util" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http 1.1.0", + "http-body 1.0.1", + "pin-project-lite", +] + +[[package]] +name = "http-cache" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b5ab65432bbdfe8490dfde21d0366353a8d39f2bc24aca0146889f931b0b4b5" +dependencies = [ + "async-trait", + "bincode", + "cacache", + "http 0.2.12", + "http-cache-semantics", + "httpdate", + "moka", + "serde", + "url", +] + +[[package]] +name = "http-cache-reqwest" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8285341ce7e709c56a0f259ff1c789c70edfbaa88acd69d27e4d63980b92dc" +dependencies = [ + "anyhow", + "async-trait", + "http 0.2.12", + "http-cache", + "http-cache-semantics", + "reqwest", + "reqwest-middleware", + "serde", + "task-local-extensions", + "url", +] + +[[package]] +name = "http-cache-semantics" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7aec9f678bca3f4a15194b980f20ed9bfe0dd38e8d298c65c559a93dfbd6380a" +dependencies = [ + "http 0.2.12", + "http-serde", + "reqwest", + "serde", + "time", +] + +[[package]] +name = "http-serde" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f560b665ad9f1572cfcaf034f7fb84338a7ce945216d64a90fd81f046a3caee" +dependencies = [ + "http 0.2.12", + "serde", +] + +[[package]] +name = "httparse" +version = "1.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "hyper" +version = "0.14.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a152ddd61dfaec7273fe8419ab357f33aee0d914c5f4efbf0d96fa749eea5ec9" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http 0.2.12", + "http-body 0.4.6", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "hyper" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http 1.1.0", + "http-body 1.0.1", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", +] + +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes", + "hyper 0.14.30", + "native-tls", + "tokio", + "tokio-native-tls", +] + +[[package]] +name = "hyper-util" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da62f120a8a37763efb0cf8fdf264b884c7b8b9ac8660b900c8661030c00e6ba" +dependencies = [ + "bytes", + "futures-util", + "http 1.1.0", + "http-body 1.0.1", + "hyper 1.4.1", + "pin-project-lite", + "tokio", +] + +[[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.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "indenter" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" + +[[package]] +name = "indexmap" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" +dependencies = [ + "equivalent", + "hashbrown", + "serde", +] + +[[package]] +name = "ipnet" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "187674a687eed5fe42285b40c6291f9a01517d415fad1c3cbc6a9f778af7fcd4" + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + +[[package]] +name = "itertools" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "kv-log-macro" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" +dependencies = [ + "log", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" + +[[package]] +name = "linked-hash-map" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" +dependencies = [ + "value-bag", +] + +[[package]] +name = "macros" +version = "0.1.0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata 0.1.10", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "memmap2" +version = "0.5.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83faa42c0a078c393f6b29d5db232d8be22776a891f8f56e5284faee4a20b327" +dependencies = [ + "libc", +] + +[[package]] +name = "miette" +version = "5.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59bb584eaeeab6bd0226ccf3509a69d7936d148cf3d036ad350abe35e8c6856e" +dependencies = [ + "miette-derive", + "once_cell", + "thiserror", + "unicode-width", +] + +[[package]] +name = "miette-derive" +version = "5.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49e7bc1560b95a3c4a25d03de42fe76ca718ab92d1a22a55b9b4cf67b3ae635c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mime_guess" +version = "2.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e" +dependencies = [ + "mime", + "unicase", +] + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "miniz_oxide" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" +dependencies = [ + "adler2", +] + +[[package]] +name = "mio" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" +dependencies = [ + "hermit-abi 0.3.9", + "libc", + "wasi", + "windows-sys 0.52.0", +] + +[[package]] +name = "moka" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32cf62eb4dd975d2dde76432fb1075c49e3ee2331cf36f1f8fd4b66550d32b6f" +dependencies = [ + "async-lock", + "async-trait", + "crossbeam-channel", + "crossbeam-epoch", + "crossbeam-utils", + "event-listener 5.3.1", + "futures-util", + "once_cell", + "parking_lot", + "quanta", + "rustc_version", + "smallvec", + "tagptr", + "thiserror", + "triomphe", + "uuid", +] + +[[package]] +name = "multer" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83e87776546dc87511aa5ee218730c92b666d7264ab6ed41f9d215af9cd5224b" +dependencies = [ + "bytes", + "encoding_rs", + "futures-util", + "http 1.1.0", + "httparse", + "memchr", + "mime", + "spin", + "version_check", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[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-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi 0.3.9", + "libc", +] + +[[package]] +name = "object" +version = "0.36.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags 2.6.0", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + +[[package]] +name = "parking" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "pest" +version = "2.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c73c26c01b8c87956cea613c907c9d6ecffd8d18a2a5908e5de0adfaa185cea" +dependencies = [ + "memchr", + "thiserror", + "ucd-trie", +] + +[[package]] +name = "pest_derive" +version = "2.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "664d22978e2815783adbdd2c588b455b1bd625299ce36b2a99881ac9627e6d8d" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2d5487022d5d33f4c30d91c22afa240ce2a644e87fe08caad974d4eab6badbe" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pest_meta" +version = "2.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0091754bbd0ea592c4deb3a122ce8ecbb0753b738aa82bc055fcc2eccc8d8174" +dependencies = [ + "once_cell", + "pest", + "sha2", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "piper" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96c8c490f422ef9a4efd2cb5b42b76c8613d7e7dfc1caf667b8a3350a5acc066" +dependencies = [ + "atomic-waker", + "fastrand", + "futures-io", +] + +[[package]] +name = "pkg-config" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" + +[[package]] +name = "polling" +version = "3.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc2790cd301dec6cd3b7a025e4815cf825724a51c98dccfe6a3e55f05ffb6511" +dependencies = [ + "cfg-if", + "concurrent-queue", + "hermit-abi 0.4.0", + "pin-project-lite", + "rustix", + "tracing", + "windows-sys 0.59.0", +] + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "pretty_assertions" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af7cee1a6c8a5b9208b3cb1061f10c0cb689087b3d8ce85fb9d2dd7a29b6ba66" +dependencies = [ + "diff", + "yansi", +] + +[[package]] +name = "proc-macro-crate" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecf48c7ca261d60b74ab1a7b20da18bede46776b2e55535cb958eb595c5fa7b" +dependencies = [ + "toml_edit", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "prost" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b2ecbe40f08db5c006b5764a2645f7f3f141ce756412ac9e1dd6087e6d32995" +dependencies = [ + "bytes", + "prost-derive", +] + +[[package]] +name = "prost-derive" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acf0c195eebb4af52c752bec4f52f645da98b6e92077a04110c7f349477ae5ac" +dependencies = [ + "anyhow", + "itertools", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "prost-reflect" +version = "0.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b7535b02f0e5efe3e1dbfcb428be152226ed0c66cad9541f2274c8ba8d4cd40" +dependencies = [ + "once_cell", + "prost", + "prost-types", +] + +[[package]] +name = "prost-types" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60caa6738c7369b940c3d49246a8d1749323674c65cb13010134f5c9bad5b519" +dependencies = [ + "prost", +] + +[[package]] +name = "quanta" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5167a477619228a0b284fac2674e3c388cba90631d7b7de620e6f1fcd08da5" +dependencies = [ + "crossbeam-utils", + "libc", + "once_cell", + "raw-cpuid", + "wasi", + "web-sys", + "winapi", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "raw-cpuid" +version = "11.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb9ee317cfe3fbd54b36a511efc1edd42e216903c9cd575e686dd68a2ba90d8d" +dependencies = [ + "bitflags 2.6.0", +] + +[[package]] +name = "redox_syscall" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0884ad60e090bf1345b93da0a5de8923c93884cd03f40dfcfddd3b4bee661853" +dependencies = [ + "bitflags 2.6.0", +] + +[[package]] +name = "reflink-copy" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc31414597d1cd7fdd2422798b7652a6329dda0fe0219e6335a13d5bcaa9aeb6" +dependencies = [ + "cfg-if", + "rustix", + "windows", +] + +[[package]] +name = "regex" +version = "1.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata 0.4.7", + "regex-syntax 0.8.4", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax 0.6.29", +] + +[[package]] +name = "regex-automata" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax 0.8.4", +] + +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + +[[package]] +name = "regex-syntax" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" + +[[package]] +name = "reqwest" +version = "0.11.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd67538700a17451e7cba03ac727fb961abb7607553461627b97de0b89cf4a62" +dependencies = [ + "base64 0.21.7", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http 0.2.12", + "http-body 0.4.6", + "hyper 0.14.30", + "hyper-tls", + "ipnet", + "js-sys", + "log", + "mime", + "mime_guess", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", +] + +[[package]] +name = "reqwest-middleware" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a735987236a8e238bf0296c7e351b999c188ccc11477f311b82b55c93984216" +dependencies = [ + "anyhow", + "async-trait", + "http 0.2.12", + "reqwest", + "serde", + "task-local-extensions", + "thiserror", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + +[[package]] +name = "rustix" +version = "0.38.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +dependencies = [ + "bitflags 2.6.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls-pemfile" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" +dependencies = [ + "base64 0.21.7", +] + +[[package]] +name = "rustversion" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "schannel" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9aaafd5a2b6e3d657ff009d82fbd630b6bd54dd4eb06f21693925cdf80f9b8b" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags 2.6.0", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75da29fe9b9b08fe9d6b22b5b4bcbc75d8db3aa31e639aa56bb62e9d46bfceaf" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "semver" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_json_borrow" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "176a77dea19cf9b2cfe7f9e31966112ef8282a709af7c0a0fb28fc6347c7ba78" +dependencies = [ + "serde", + "serde_json", +] + +[[package]] +name = "serde_path_to_error" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af99884400da37c88f5e9146b7f1fd0fbcae8f6eec4e9da38b67d05486f814a6" +dependencies = [ + "itoa", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha-1" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5058ada175748e33390e40e872bd0fe59a19f265d0158daa551c5a88a76009c" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "ssddOnTop" +version = "0.1.0" +dependencies = [ + "anyhow", + "async-graphql", + "async-graphql-value", + "async-trait", + "bytes", + "convert_case 0.6.0", + "derive-getters", + "derive_more", + "derive_setters", + "futures-util", + "fxhash", + "http 1.1.0", + "http-body-util", + "http-cache", + "http-cache-reqwest", + "http-cache-semantics", + "hyper 1.4.1", + "hyper-util", + "indenter", + "indexmap", + "moka", + "nom", + "num_cpus", + "pretty_assertions", + "prost-reflect", + "reqwest", + "reqwest-middleware", + "serde", + "serde_json", + "serde_json_borrow", + "serde_path_to_error", + "strum_macros", + "test-log", + "tokio", + "tracing", + "tracing-subscriber", + "ttl_cache", + "url", +] + +[[package]] +name = "ssri" +version = "9.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da7a2b3c2bc9693bcb40870c4e9b5bf0d79f9cb46273321bf855ec513e919082" +dependencies = [ + "base64 0.21.7", + "digest", + "hex", + "miette", + "serde", + "sha-1", + "sha2", + "thiserror", + "xxhash-rust", +] + +[[package]] +name = "static_assertions_next" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7beae5182595e9a8b683fa98c4317f956c9a2dec3b9716990d20023cc60c766" + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "strum" +version = "0.26.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn", +] + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" + +[[package]] +name = "system-configuration" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tagptr" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b2093cf4c8eb1e67749a6762251bc9cd836b6fc171623bd0a9d324d37af2417" + +[[package]] +name = "task-local-extensions" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba323866e5d033818e3240feeb9f7db2c4296674e4d9e16b97b7bf8f490434e8" +dependencies = [ + "pin-utils", +] + +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "test-log" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dffced63c2b5c7be278154d76b479f9f9920ed34e7574201407f0b14e2bbb93" +dependencies = [ + "env_logger", + "test-log-macros", + "tracing-subscriber", +] + +[[package]] +name = "test-log-macros" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5999e24eaa32083191ba4e425deb75cdf25efefabe5aaccb7446dd0d4122a3f5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thiserror" +version = "1.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thread_local" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" +dependencies = [ + "cfg-if", + "once_cell", +] + +[[package]] +name = "time" +version = "0.3.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "time-macros" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" +dependencies = [ + "num-conv", + "time-core", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.40.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.52.0", +] + +[[package]] +name = "tokio-macros" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "toml_datetime" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" + +[[package]] +name = "toml_edit" +version = "0.22.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" +dependencies = [ + "indexmap", + "toml_datetime", + "winnow", +] + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", +] + +[[package]] +name = "triomphe" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "859eb650cfee7434994602c3a68b25d77ad9e68c8a6cd491616ef86661382eb3" + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "ttl_cache" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4189890526f0168710b6ee65ceaedf1460c48a14318ceec933cb26baa492096a" +dependencies = [ + "linked-hash-map", +] + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "ucd-trie" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" + +[[package]] +name = "unicase" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" +dependencies = [ + "version_check", +] + +[[package]] +name = "unicode-bidi" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "unicode-normalization" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-segmentation" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" + +[[package]] +name = "unicode-width" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] +name = "uuid" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81dfa00651efa65069b0b6b651f4aaa31ba9e3c3ce0137aaad053604ee7e0314" +dependencies = [ + "getrandom", +] + +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + +[[package]] +name = "value-bag" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a84c137d37ab0142f0f2ddfe332651fdbf252e7b7dbb4e67b6c1f1b2e925101" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd04d41d93c4992d421894c18c8b43496aa748dd4c081bac0dc93eb0489272b6" +dependencies = [ + "windows-core", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-core" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-implement" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "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.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "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.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[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.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[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.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[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.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[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.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[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.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "winnow" +version = "0.6.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" +dependencies = [ + "memchr", +] + +[[package]] +name = "winreg" +version = "0.50.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" +dependencies = [ + "cfg-if", + "windows-sys 0.48.0", +] + +[[package]] +name = "xxhash-rust" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a5cbf750400958819fb6178eaa83bee5cd9c29a26a40cc241df8c70fdd46984" + +[[package]] +name = "yansi" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" diff --git a/projects/ssddOnTop/Cargo.toml b/projects/ssddOnTop/Cargo.toml index fc9bcb2..1e7bf38 100644 --- a/projects/ssddOnTop/Cargo.toml +++ b/projects/ssddOnTop/Cargo.toml @@ -4,6 +4,8 @@ version = "0.1.0" edition = "2021" [dependencies] +macros = {path = "./macros"} +macros_common = {path = "./macros-common"} tokio = {version = "1.40.0", features = ["full"]} tracing = "0.1.40" hyper = {version = "1.4.1",features = ["http1","server"]} @@ -43,8 +45,9 @@ moka = { version = "0.12.7", default-features = false, features = [ async-trait = "0.1.82" ttl_cache = "0.5.1" futures-util = "0.3.30" +http = "1.1.0" +url = "2.5.2" +schemars = {version = "0.8.17", features = ["derive"]} [dev-dependencies] http-cache = "0.18.0" -url = "2.5.2" -http = "1.1.0" \ No newline at end of file diff --git a/projects/ssddOnTop/macros-common/Cargo.toml b/projects/ssddOnTop/macros-common/Cargo.toml new file mode 100644 index 0000000..dd822b4 --- /dev/null +++ b/projects/ssddOnTop/macros-common/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "macros_common" +version = "0.1.0" +edition = "2021" + +[dependencies] +async-graphql = "7.0.9" +schemars = { version = "0.8.17" } diff --git a/projects/ssddOnTop/macros-common/src/common.rs b/projects/ssddOnTop/macros-common/src/common.rs new file mode 100644 index 0000000..a033d95 --- /dev/null +++ b/projects/ssddOnTop/macros-common/src/common.rs @@ -0,0 +1,43 @@ + +use async_graphql::{Pos, Positioned}; +use schemars::schema::SchemaObject; + +pub fn get_description(schema: &SchemaObject) -> Option<&String> { + schema + .metadata + .as_ref() + .and_then(|metadata| metadata.description.as_ref()) +} + +pub fn first_char_to_upper(name: &mut String) { + if let Some(first_char) = name.chars().next() { + // Remove the first character and make it uppercase + let first_char_upper = first_char.to_uppercase().to_string(); + + // Remove the first character from the original string + let mut chars = name.chars(); + chars.next(); + + // Replace the original string with the new one + *name = first_char_upper + chars.as_str(); + } +} + +pub fn first_char_to_lower(name: &str) -> String { + if let Some(first_char) = name.chars().next() { + // Remove the first character and make it uppercase + let first_char_upper = first_char.to_lowercase().to_string(); + + // Remove the first character from the original string + let mut chars = name.chars(); + chars.next(); + + return format!("{}{}", first_char_upper, chars.collect::()); + } + + String::new() +} + +pub fn pos(a: A) -> Positioned { + Positioned::new(a, Pos::default()) +} diff --git a/projects/ssddOnTop/macros-common/src/directive_definition.rs b/projects/ssddOnTop/macros-common/src/directive_definition.rs new file mode 100644 index 0000000..908e908 --- /dev/null +++ b/projects/ssddOnTop/macros-common/src/directive_definition.rs @@ -0,0 +1,93 @@ +use std::collections::{BTreeMap, HashSet}; + +use async_graphql::parser::types::{DirectiveLocation, TypeSystemDefinition}; +use async_graphql::Name; +use schemars::schema::{RootSchema, Schema, SchemaObject}; + +use crate::common::{first_char_to_lower, first_char_to_upper, get_description, pos}; +use crate::enum_definition::{into_enum_definition, into_enum_value}; +use crate::input_definition::{into_input_definition, into_input_value_definition}; + +pub trait DirectiveDefinition { + fn directive_definition(generated_types: &mut HashSet) -> Vec; +} + +#[derive(Clone)] +pub struct Attrs { + pub name: &'static str, + pub repeatable: bool, + pub locations: Vec<&'static str>, + pub is_lowercase_name: bool, +} + +pub fn from_directive_location(str: DirectiveLocation) -> String { + match str { + DirectiveLocation::Schema => String::from("SCHEMA"), + DirectiveLocation::Object => String::from("OBJECT"), + DirectiveLocation::FieldDefinition => String::from("FIELD_DEFINITION"), + DirectiveLocation::EnumValue => String::from("ENUM_VALUE"), + _ => String::from("FIELD_DEFINITION"), + } +} + +fn into_directive_location(str: &str) -> DirectiveLocation { + match str { + "Schema" => DirectiveLocation::Schema, + "Object" => DirectiveLocation::Object, + "FieldDefinition" => DirectiveLocation::FieldDefinition, + "EnumValue" => DirectiveLocation::EnumValue, + _ => DirectiveLocation::FieldDefinition, + } +} + +pub fn into_directive_definition( + root_schema: RootSchema, + attrs: Attrs, + generated_types: &mut HashSet, +) -> Vec { + let mut service_doc_definitions = vec![]; + let definitions: BTreeMap = root_schema.definitions; + let schema: SchemaObject = root_schema.schema; + let description = get_description(&schema); + + for (mut name, schema) in definitions.into_iter() { + if generated_types.contains(&name) { + continue; + } + // the definition could either be an enum or a type + // we don't know which one is it, so we first try to get an EnumValue + // if into_enum_value return Some we can be sure it's an Enum + if let Some(enum_values) = into_enum_value(&schema) { + service_doc_definitions.push(into_enum_definition(enum_values, &name)); + generated_types.insert(name.to_string()); + } else { + generated_types.insert(name.to_string()); + first_char_to_upper(&mut name); + service_doc_definitions.push(into_input_definition( + schema.clone().into_object(), + name.as_str(), + )); + } + } + + let name = if attrs.is_lowercase_name { + attrs.name.to_lowercase() + } else { + first_char_to_lower(attrs.name) + }; + + let directve_definition = + TypeSystemDefinition::Directive(pos(async_graphql::parser::types::DirectiveDefinition { + description: description.map(|inner| pos(inner.clone())), + name: pos(Name::new(name)), + arguments: into_input_value_definition(&schema), + is_repeatable: attrs.repeatable, + locations: attrs + .locations + .into_iter() + .map(|val| pos(into_directive_location(val))) + .collect(), + })); + service_doc_definitions.push(directve_definition); + service_doc_definitions +} diff --git a/projects/ssddOnTop/macros-common/src/enum_definition.rs b/projects/ssddOnTop/macros-common/src/enum_definition.rs new file mode 100644 index 0000000..59b9641 --- /dev/null +++ b/projects/ssddOnTop/macros-common/src/enum_definition.rs @@ -0,0 +1,56 @@ +use async_graphql::parser::types::{ + EnumType, EnumValueDefinition, TypeDefinition, TypeKind, TypeSystemDefinition, +}; +use async_graphql::{Name, Positioned}; +use schemars::schema::Schema; + +#[derive(Debug)] +pub struct EnumValue { + pub variants: Vec, + pub description: Option>, +} + +use crate::common::{get_description, pos}; + +pub fn into_enum_definition(enum_value: EnumValue, name: &str) -> TypeSystemDefinition { + let mut enum_value_definition = vec![]; + for enum_value in enum_value.variants { + let formatted_value: String = enum_value + .to_string() + .chars() + .filter(|ch| ch != &'"') + .collect(); + enum_value_definition.push(pos(EnumValueDefinition { + value: pos(Name::new(formatted_value)), + description: None, + directives: vec![], + })); + } + + TypeSystemDefinition::Type(pos(TypeDefinition { + name: pos(Name::new(name)), + kind: TypeKind::Enum(EnumType { values: enum_value_definition }), + description: enum_value.description, + directives: vec![], + extend: false, + })) +} + +pub fn into_enum_value(obj: &Schema) -> Option { + match obj { + Schema::Object(schema_object) => { + let description = get_description(schema_object); + if let Some(enum_values) = &schema_object.enum_values { + return Some(EnumValue { + variants: enum_values + .iter() + .map(|val| val.to_string()) + .collect::>(), + description: description.map(|description| pos(description.to_owned())), + }); + } + None + } + _ => None, + } +} diff --git a/projects/ssddOnTop/macros-common/src/input_definition.rs b/projects/ssddOnTop/macros-common/src/input_definition.rs new file mode 100644 index 0000000..0d8819c --- /dev/null +++ b/projects/ssddOnTop/macros-common/src/input_definition.rs @@ -0,0 +1,177 @@ +use async_graphql::parser::types::{ + BaseType, InputObjectType, InputValueDefinition, Type, TypeDefinition, TypeKind, + TypeSystemDefinition, +}; +use async_graphql::{Name, Positioned}; +use schemars::schema::{ + ArrayValidation, InstanceType, ObjectValidation, Schema, SchemaObject, SingleOrVec, +}; + +use crate::common::{first_char_to_upper, get_description, pos}; + +pub trait InputDefinition { + fn input_definition() -> TypeSystemDefinition; +} + +pub fn into_input_definition(schema: SchemaObject, name: &str) -> TypeSystemDefinition { + let description = get_description(&schema); + + TypeSystemDefinition::Type(pos(TypeDefinition { + name: pos(Name::new(name)), + kind: TypeKind::InputObject(InputObjectType { + fields: into_input_value_definition(&schema), + }), + description: description.map(|inner| pos(inner.clone())), + directives: vec![], + extend: false, + })) +} + +pub fn into_input_value_definition(schema: &SchemaObject) -> Vec> { + let mut arguments_type = vec![]; + if let Some(subschema) = schema.subschemas.clone() { + let list = subschema.any_of.or(subschema.all_of).or(subschema.one_of); + if let Some(list) = list { + for schema in list { + let schema_object = schema.into_object(); + arguments_type.extend(build_arguments_type(&schema_object)); + } + + return arguments_type; + } + } + + build_arguments_type(schema) +} + +fn build_arguments_type(schema: &SchemaObject) -> Vec> { + let mut arguments = vec![]; + if let Some(properties) = schema + .object + .as_ref() + .map(|object| object.properties.clone()) + { + for (name, property) in properties.into_iter() { + let property = property.into_object(); + let description = get_description(&property); + let definition = pos(InputValueDefinition { + description: description.map(|inner| pos(inner.to_owned())), + name: pos(Name::new(&name)), + ty: pos(determine_input_value_type_from_schema( + name, + property.clone(), + )), + default_value: None, + directives: Vec::new(), + }); + + arguments.push(definition); + } + } + + arguments +} + +fn determine_input_value_type_from_schema(mut name: String, schema: SchemaObject) -> Type { + first_char_to_upper(&mut name); + if let Some(instance_type) = &schema.instance_type { + match instance_type { + SingleOrVec::Single(typ) => match **typ { + InstanceType::Null + | InstanceType::Boolean + | InstanceType::Number + | InstanceType::String + | InstanceType::Integer => Type { + nullable: false, + base: BaseType::Named(Name::new(get_instance_type_name(typ))), + }, + _ => determine_type_from_schema(name, &schema), + }, + SingleOrVec::Vec(typ) => match typ.first().unwrap() { + InstanceType::Null + | InstanceType::Boolean + | InstanceType::Number + | InstanceType::String + | InstanceType::Integer => Type { + nullable: true, + base: BaseType::Named(Name::new(get_instance_type_name(typ.first().unwrap()))), + }, + _ => determine_type_from_schema(name, &schema), + }, + } + } else { + determine_type_from_schema(name, &schema) + } +} + +fn determine_type_from_schema(name: String, schema: &SchemaObject) -> Type { + if let Some(arr_valid) = &schema.array { + return determine_type_from_arr_valid(name, arr_valid); + } + + if let Some(typ) = &schema.object { + return determine_type_from_object_valid(name, typ); + } + + if let Some(subschema) = schema.subschemas.clone().into_iter().next() { + let list = subschema.any_of.or(subschema.all_of).or(subschema.one_of); + + if let Some(list) = list { + if let Some(Schema::Object(obj)) = list.first() { + if let Some(reference) = &obj.reference { + return determine_type_from_reference(reference); + } + } + } + } + + if let Some(reference) = &schema.reference { + return determine_type_from_reference(reference); + } + + Type { nullable: true, base: BaseType::Named(Name::new("JSON")) } +} + +fn determine_type_from_reference(reference: &str) -> Type { + let mut name = reference.split('/').last().unwrap().to_string(); + first_char_to_upper(&mut name); + Type { nullable: true, base: BaseType::Named(Name::new(name)) } +} + +fn determine_type_from_arr_valid(name: String, array_valid: &ArrayValidation) -> Type { + if let Some(items) = &array_valid.items { + match items { + SingleOrVec::Single(schema) => Type { + nullable: true, + base: BaseType::List(Box::new(determine_input_value_type_from_schema( + name, + schema.clone().into_object(), + ))), + }, + SingleOrVec::Vec(schemas) => Type { + nullable: true, + base: BaseType::List(Box::new(determine_input_value_type_from_schema( + name, + schemas[0].clone().into_object(), + ))), + }, + } + } else { + Type { nullable: true, base: BaseType::Named(Name::new("JSON")) } + } +} + +fn determine_type_from_object_valid(name: String, typ: &ObjectValidation) -> Type { + if !typ.properties.is_empty() { + Type { nullable: true, base: BaseType::Named(Name::new(name)) } + } else { + Type { nullable: true, base: BaseType::Named(Name::new("JSON")) } + } +} + +fn get_instance_type_name(typ: &InstanceType) -> String { + match typ { + &InstanceType::Integer => "Int".to_string(), + _ => format!("{:?}", typ), + } +} diff --git a/projects/ssddOnTop/macros-common/src/lib.rs b/projects/ssddOnTop/macros-common/src/lib.rs new file mode 100644 index 0000000..0089f72 --- /dev/null +++ b/projects/ssddOnTop/macros-common/src/lib.rs @@ -0,0 +1,53 @@ +use async_graphql::parser::types::{ServiceDocument, TypeSystemDefinition}; +use schemars::schema::RootSchema; +use schemars::JsonSchema; +mod common; +pub mod directive_definition; +mod enum_definition; +pub mod input_definition; +pub mod scalar_definition; + +pub fn into_schemars() -> RootSchema +where + T: JsonSchema, +{ + schemars::schema_for!(T) +} + +pub struct ServiceDocumentBuilder { + definitions: Vec, +} + +impl Default for ServiceDocumentBuilder { + fn default() -> Self { + Self::new() + } +} + +impl ServiceDocumentBuilder { + pub fn new() -> Self { + Self { definitions: vec![] } + } + + pub fn add_directive( + mut self, + definitions: Vec, + ) -> ServiceDocumentBuilder { + self.definitions.extend(definitions); + self + } + + pub fn add_scalar(mut self, definitions: TypeSystemDefinition) -> ServiceDocumentBuilder { + self.definitions.push(definitions); + self + } + + pub fn add_input(mut self, definitions: TypeSystemDefinition) -> ServiceDocumentBuilder { + self.definitions.push(definitions); + self + } + + pub fn build(self) -> ServiceDocument { + ServiceDocument { definitions: self.definitions } + } +} diff --git a/projects/ssddOnTop/macros-common/src/scalar_definition.rs b/projects/ssddOnTop/macros-common/src/scalar_definition.rs new file mode 100644 index 0000000..bdb3808 --- /dev/null +++ b/projects/ssddOnTop/macros-common/src/scalar_definition.rs @@ -0,0 +1,21 @@ +use async_graphql::parser::types::{TypeDefinition, TypeKind, TypeSystemDefinition}; +use async_graphql::Name; +use schemars::schema::{Schema, SchemaObject}; + +use crate::common::{get_description, pos}; + +pub trait ScalarDefinition { + fn scalar_definition() -> TypeSystemDefinition; +} + +pub fn into_scalar_definition(root_schema: Schema, name: &str) -> TypeSystemDefinition { + let schema: SchemaObject = root_schema.into_object(); + let description = get_description(&schema); + TypeSystemDefinition::Type(pos(TypeDefinition { + name: pos(Name::new(name)), + kind: TypeKind::Scalar, + description: description.map(|inner| pos(inner.clone())), + directives: vec![], + extend: false, + })) +} diff --git a/projects/ssddOnTop/macros/Cargo.toml b/projects/ssddOnTop/macros/Cargo.toml new file mode 100644 index 0000000..5885e09 --- /dev/null +++ b/projects/ssddOnTop/macros/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "macros" +version = "0.1.0" +edition = "2021" + +[lib] +proc-macro = true + +[dependencies] +syn = { version = "2.0.60", features = ["derive", "full"] } +quote = "1.0.36" +proc-macro2 = "1.0.81" +macros_common = {path = "../macros-common"} +anyhow = "1.0.88" \ No newline at end of file diff --git a/projects/ssddOnTop/macros/src/document_definition.rs b/projects/ssddOnTop/macros/src/document_definition.rs new file mode 100644 index 0000000..76c4bef --- /dev/null +++ b/projects/ssddOnTop/macros/src/document_definition.rs @@ -0,0 +1,93 @@ +extern crate proc_macro; +use proc_macro::TokenStream; +use quote::quote; +use syn::{parse_macro_input, DeriveInput}; + +#[derive(Default)] +struct DirectiveDefinitionAttr { + is_repeatable: bool, + is_lowercase_name: bool, + locations: Option, +} + +fn get_directive_definition_attr(input: &DeriveInput) -> syn::Result { + let mut directive_definition_attr: DirectiveDefinitionAttr = Default::default(); + for attr in input.attrs.iter() { + if attr.path().is_ident("directive_definition") { + attr.parse_nested_meta(|meta| { + if meta.path.is_ident("repeatable") { + directive_definition_attr.is_repeatable = true; + } + + if meta.path.is_ident("locations") { + let value = meta.value()?; + let s: syn::LitStr = value.parse()?; + directive_definition_attr.locations = Some(s.value()); + } + + if meta.path.is_ident("lowercase_name") { + directive_definition_attr.is_lowercase_name = true; + } + + Ok(()) + })?; + } + } + + Ok(directive_definition_attr) +} + +pub fn expand_directive_definition(input: TokenStream) -> TokenStream { + let input = parse_macro_input!(input as DeriveInput); + let struct_identifier = &input.ident; + + let directive_definition_attr = get_directive_definition_attr(&input); + if let Err(err) = directive_definition_attr { + panic!("{}", err); + } + + let directive_definition_attr = directive_definition_attr.unwrap(); + let is_repeatable = directive_definition_attr.is_repeatable; + let is_lowercase_name = directive_definition_attr.is_lowercase_name; + let locations = if let Some(locations) = directive_definition_attr.locations { + locations + .split(",") + .map(|location| location.trim().to_string()) + .collect::>() + } else { + vec![] + }; + + let expanded = quote! { + impl macros_common::directive_definition::DirectiveDefinition for #struct_identifier { + fn directive_definition(generated_types: &mut std::collections::HashSet) -> Vec { + let schemars = macros_common::into_schemars::(); + let attr = macros_common::directive_definition::Attrs { + name: stringify!(#struct_identifier), + repeatable: #is_repeatable, + locations: vec![#(#locations),*], + is_lowercase_name: #is_lowercase_name + }; + macros_common::directive_definition::into_directive_definition(schemars, attr, generated_types) + } + } + }; + + TokenStream::from(expanded) +} + +pub fn expand_input_definition(input: TokenStream) -> TokenStream { + let input = parse_macro_input!(input as DeriveInput); + let struct_identifier = &input.ident; + + let expanded = quote! { + impl macros_common::input_definition::InputDefinition for #struct_identifier { + fn input_definition() -> async_graphql::parser::types::TypeSystemDefinition { + let schemars = macros_common::into_schemars::(); + macros_common::input_definition::into_input_definition(schemars.schema, stringify!(#struct_identifier)) + } + } + }; + + TokenStream::from(expanded) +} diff --git a/projects/ssddOnTop/macros/src/gen.rs b/projects/ssddOnTop/macros/src/gen.rs new file mode 100644 index 0000000..f063551 --- /dev/null +++ b/projects/ssddOnTop/macros/src/gen.rs @@ -0,0 +1,100 @@ +use proc_macro::TokenStream; +use quote::quote; +use syn::{parse_macro_input, Attribute, Data, DeriveInput, Expr, Meta}; + +fn extract_gen_doc_ty(attrs: &[Attribute]) -> String { + attrs + .iter() + .filter_map(|attr| { + if attr.path().is_ident("gen_doc") { + let meta_list = attr.meta.require_list().ok()?; + let expr = meta_list.parse_args::().ok()?; + if let Expr::Assign(assign) = expr { + if let Expr::Path(expr_path) = assign.left.as_ref() { + let segment = expr_path.path.segments.first()?; + if segment.ident == "ty" { + if let Expr::Lit(expr_lit) = *assign.right { + if let syn::Lit::Str(lit_str) = expr_lit.lit { + return Some(lit_str.value().trim().to_string()); + } + } + } + } + } + } + None + }) + .collect::>() + .join("") + .to_string() +} + +pub fn doc(input: TokenStream) -> TokenStream { + let input = parse_macro_input!(input as DeriveInput); + + let name = input.ident; + + let variants = if let Data::Enum(data_enum) = input.data { + data_enum.variants + } else { + panic!("Doc can only be used on enums"); + }; + + let match_arms = variants.iter().map(|variant| { + let variant_name = &variant.ident; + let docs = variant + .attrs + .iter() + .filter_map(|attr| { + if attr.path().is_ident("doc") { + if let Meta::NameValue(value) = &attr.meta { + if let Expr::Lit(lit) = &value.value { + if let syn::Lit::Str(lit_str) = &lit.lit { + return Some(lit_str.value().trim().to_string()); + } + } + } + } + None + }) + .collect::>() + .join("\n"); + + quote! { + #name::#variant_name => #docs.to_string(), + } + }); + + let match_arms_ty = variants.iter().map(|variant| { + let variant_name = &variant.ident; + let ty = extract_gen_doc_ty(&variant.attrs).to_lowercase(); + + let instance_type = match ty.as_str() { + "integer" => quote! { InstanceType::Integer }, + "string" => quote! { InstanceType::String }, + "object" => quote! { InstanceType::Integer }, + _ => quote! { InstanceType::Null }, + }; + + quote! { + #name::#variant_name => #instance_type, + } + }); + + let expanded = quote! { + impl #name { + pub fn doc(&self) -> String { + match self { + #(#match_arms)* + } + } + pub fn ty(&self) -> InstanceType { + match self { + #(#match_arms_ty)* + } + } + } + }; + + TokenStream::from(expanded) +} diff --git a/projects/ssddOnTop/macros/src/lib.rs b/projects/ssddOnTop/macros/src/lib.rs new file mode 100644 index 0000000..377a4ef --- /dev/null +++ b/projects/ssddOnTop/macros/src/lib.rs @@ -0,0 +1,54 @@ +extern crate proc_macro; + +use proc_macro::TokenStream; + +mod document_definition; +mod gen; +mod merge_right; +mod resolver; + +use crate::document_definition::{expand_directive_definition, expand_input_definition}; +use crate::merge_right::expand_merge_right_derive; +use crate::resolver::expand_resolver_derive; + +#[proc_macro_derive(MergeRight, attributes(merge_right))] +pub fn merge_right_derive(input: TokenStream) -> TokenStream { + expand_merge_right_derive(input) +} + +#[proc_macro_derive(DirectiveDefinition, attributes(directive_definition))] +pub fn directive_definitions_derive(input: TokenStream) -> TokenStream { + expand_directive_definition(input) +} + +#[proc_macro_derive(Doc, attributes(gen_doc))] +pub fn scalar_definition_derive(input: TokenStream) -> TokenStream { + gen::doc(input) +} + +#[proc_macro] +pub fn gen_doc(item: TokenStream) -> TokenStream { + let input = syn::parse_macro_input!(item as syn::DeriveInput); + let name = &input.ident; + let gen = quote::quote! { + impl #name { + pub fn doc() -> &'static str { + stringify!(#name) + } + } + }; + TokenStream::from(quote::quote! { + #input + #gen + }) +} + +#[proc_macro_derive(InputDefinition)] +pub fn input_definition_derive(input: TokenStream) -> TokenStream { + expand_input_definition(input) +} + +#[proc_macro_derive(CustomResolver)] +pub fn resolver_derive(input: TokenStream) -> TokenStream { + expand_resolver_derive(input) +} diff --git a/projects/ssddOnTop/macros/src/merge_right.rs b/projects/ssddOnTop/macros/src/merge_right.rs new file mode 100644 index 0000000..dce5c42 --- /dev/null +++ b/projects/ssddOnTop/macros/src/merge_right.rs @@ -0,0 +1,151 @@ +extern crate proc_macro; + +use proc_macro::TokenStream; +use quote::quote; +use syn::spanned::Spanned; +use syn::{parse_macro_input, Data, DeriveInput, Fields}; + +const MERGE_RIGHT_FN: &str = "merge_right_fn"; +const MERGE_RIGHT: &str = "merge_right"; + +#[derive(Default)] +struct Attrs { + merge_right_fn: Option, +} + +fn get_attrs(attrs: &[syn::Attribute]) -> syn::Result { + let mut attrs_ret = Attrs::default(); + for attr in attrs { + if attr.path().is_ident(MERGE_RIGHT) { + attr.parse_nested_meta(|meta| { + if meta.path.is_ident(MERGE_RIGHT_FN) { + let p: syn::Expr = meta.value()?.parse()?; + let lit = + if let syn::Expr::Lit(syn::ExprLit { lit: syn::Lit::Str(lit), .. }) = p { + let suffix = lit.suffix(); + if !suffix.is_empty() { + return Err(syn::Error::new( + lit.span(), + format!("unexpected suffix `{}` on string literal", suffix), + )); + } + lit + } else { + return Err(syn::Error::new( + p.span(), + format!( + "expected merge_right {} attribute to be a string.", + MERGE_RIGHT_FN + ), + )); + }; + let expr_path: syn::ExprPath = lit.parse()?; + attrs_ret.merge_right_fn = Some(expr_path); + Ok(()) + } else { + Err(syn::Error::new(attr.span(), "Unknown helper attribute.")) + } + })?; + } + } + Ok(attrs_ret) +} + +pub fn expand_merge_right_derive(input: TokenStream) -> TokenStream { + let input = parse_macro_input!(input as DeriveInput); + + let name = input.ident.clone(); + let generics = input.generics.clone(); + let gen = match input.data { + // Implement for structs + Data::Struct(data) => { + let fields = if let Fields::Named(fields) = data.fields { + fields.named + } else { + // Adjust this match arm to handle other kinds of struct fields (unnamed/tuple + // structs, unit structs) + unimplemented!() + }; + + let merge_logic = fields.iter().map(|f| { + let attrs = get_attrs(&f.attrs); + if let Err(err) = attrs { + panic!("{}", err); + } + let attrs = attrs.unwrap(); + let name = &f.ident; + if let Some(merge_right_fn) = attrs.merge_right_fn { + quote! { + #name: #merge_right_fn(self.#name, other.#name), + } + } else { + quote! { + #name: self.#name.merge_right(other.#name), + } + } + }); + + let generics_lt = generics.lt_token; + let generics_gt = generics.gt_token; + let generics_params = generics.params; + + let generics_del = quote! { + #generics_lt #generics_params #generics_gt + }; + + quote! { + impl #generics_del MergeRight for #name #generics_del { + fn merge_right(self, other: Self) -> Self { + Self { + #(#merge_logic)* + } + } + } + } + } + // Implement for enums + Data::Enum(_) => quote! { + impl MergeRight for #name { + fn merge_right(self, other: Self) -> Self { + other + } + } + }, + // Optionally handle or disallow unions + Data::Union(_) => { + return syn::Error::new_spanned(input, "Union types are not supported by MergeRight") + .to_compile_error() + .into() + } + }; + + gen.into() +} + +#[cfg(test)] +mod tests { + use syn::{parse_quote, Attribute}; + + use super::*; + + #[test] + fn test_get_attrs_invalid_type() { + let attrs: Vec = vec![parse_quote!(#[merge_right(merge_right_fn = 123)])]; + let result = get_attrs(&attrs); + assert!( + result.is_err(), + "Expected error with non-string type for `merge_right_fn`" + ); + } + + #[test] + fn test_get_attrs_unexpected_suffix() { + let attrs: Vec = + vec![parse_quote!(#[merge_right(merge_right_fn = "some_fn()")])]; + let result = get_attrs(&attrs); + assert!( + result.is_err(), + "Expected error with unexpected suffix on string literal" + ); + } +} diff --git a/projects/ssddOnTop/macros/src/resolver.rs b/projects/ssddOnTop/macros/src/resolver.rs new file mode 100644 index 0000000..7f120c9 --- /dev/null +++ b/projects/ssddOnTop/macros/src/resolver.rs @@ -0,0 +1,91 @@ +use proc_macro::TokenStream; +use quote::quote; +use syn::{parse_macro_input, Data, DeriveInput, Fields}; + +pub fn expand_resolver_derive(input: TokenStream) -> TokenStream { + let input = parse_macro_input!(input as DeriveInput); + let name = &input.ident; + + let variants = if let Data::Enum(data_enum) = &input.data { + data_enum + .variants + .iter() + .map(|variant| { + let variant_name = &variant.ident; + let ty = match &variant.fields { + Fields::Unnamed(fields) if fields.unnamed.len() == 1 => &fields.unnamed[0].ty, + _ => panic!("Resolver variants must have exactly one unnamed field"), + }; + + (variant_name, ty) + }) + .collect::>() + } else { + panic!("Resolver can only be derived for enums"); + }; + + let variant_parsers = variants.iter().map(|(variant_name, ty)| { + quote! { + valid = valid.and(<#ty>::from_directives(directives.iter()).map(|resolver| { + if let Some(resolver) = resolver { + let directive_name = <#ty>::trace_name(); + if !resolvable_directives.contains(&directive_name) { + resolvable_directives.push(directive_name); + } + result = Some(Self::#variant_name(resolver)); + } + })); + } + }); + + let match_arms_to_directive = variants.iter().map(|(variant_name, _ty)| { + quote! { + Self::#variant_name(d) => d.to_directive(), + } + }); + + let match_arms_directive_name = variants.iter().map(|(variant_name, ty)| { + quote! { + Self::#variant_name(_) => <#ty>::directive_name(), + } + }); + + let expanded = quote! { + impl #name { + pub fn from_directives( + directives: &[Positioned], + ) -> anyhow::Result> { + let mut result = None; + let mut resolvable_directives = Vec::new(); + let mut valid = Ok(()); + + #(#variant_parsers)* + + valid.and_then(|_| { + if resolvable_directives.len() > 1 { + Err(anyhow::anyhow!( + "Multiple resolvers detected [{}]", + resolvable_directives.join(", ") + )) + } else { + Ok(result) + } + }) + } + + pub fn to_directive(&self) -> ConstDirective { + match self { + #(#match_arms_to_directive)* + } + } + + pub fn directive_name(&self) -> String { + match self { + #(#match_arms_directive_name)* + } + } + } + }; + + TokenStream::from(expanded) +} diff --git a/projects/ssddOnTop/src/blueprint/blueprint.rs b/projects/ssddOnTop/src/blueprint/blueprint.rs index ec37494..4a78955 100644 --- a/projects/ssddOnTop/src/blueprint/blueprint.rs +++ b/projects/ssddOnTop/src/blueprint/blueprint.rs @@ -165,7 +165,9 @@ fn populate_nested_field( ), Definition::InputObject(_) => None, }); - x.and_then(|x| x.resolver.clone()) + // println!("resolver for: {} is {:?}", field_name.0, x); + let x = x.and_then(|x| x.resolver.clone()); + x }, args: field .args diff --git a/projects/ssddOnTop/src/blueprint/model.rs b/projects/ssddOnTop/src/blueprint/model.rs index b4c4e6c..64fa53c 100644 --- a/projects/ssddOnTop/src/blueprint/model.rs +++ b/projects/ssddOnTop/src/blueprint/model.rs @@ -4,6 +4,12 @@ use std::fmt::{Debug, Formatter}; #[derive(Clone, Debug, Eq, Hash, PartialEq)] pub struct FieldName(pub String); +impl AsRef for FieldName { + fn as_ref(&self) -> &str { + &self.0 + } +} + #[derive(Clone, Debug, Eq, Hash, PartialEq)] pub struct TypeName(pub String); diff --git a/projects/ssddOnTop/src/blueprint/operators/http.rs b/projects/ssddOnTop/src/blueprint/operators/http.rs index 805e20c..e9776a7 100644 --- a/projects/ssddOnTop/src/blueprint/operators/http.rs +++ b/projects/ssddOnTop/src/blueprint/operators/http.rs @@ -41,12 +41,6 @@ fn compile_http(config_module: &config::Config, http: &config::Http) -> anyhow:: )?; let ir = if http.method == Method::GET { - // Find a query parameter that contains a reference to the {{.value}} key - let key = http.query.iter().find_map(|q| { - Mustache::parse(&q.value) - .expression_contains("value") - .then(|| q.key.clone()) - }); IR::IO(IO::Http { req_template, }) diff --git a/projects/ssddOnTop/src/config/config.rs b/projects/ssddOnTop/src/config/config.rs index 5a641b8..faf53c4 100644 --- a/projects/ssddOnTop/src/config/config.rs +++ b/projects/ssddOnTop/src/config/config.rs @@ -1,3 +1,6 @@ +use macros_common::directive_definition; +use crate::directive::DirectiveCodec; +use async_graphql::Positioned; use crate::blueprint::wrapping_type; use crate::config::url_query::URLQuery; use crate::http::method::Method; @@ -5,6 +8,9 @@ use crate::is_default; use serde::{Deserialize, Serialize}; use std::collections::BTreeMap; use std::num::NonZeroU64; +use async_graphql::parser::types::ConstDirective; +use macros::{CustomResolver, DirectiveDefinition, InputDefinition}; + #[derive(Serialize, Deserialize, Clone, Debug)] pub struct Config { @@ -70,20 +76,23 @@ pub struct Cache { pub max_age: NonZeroU64, } +#[derive( + Serialize, Deserialize, Clone, Debug, PartialEq, Eq, schemars::JsonSchema, macros::CustomResolver, +)] +pub enum Resolver { + Http(Http), +} + #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Default)] pub struct Field { pub ty_of: wrapping_type::Type, + #[serde(flatten, default, skip_serializing_if = "is_default")] pub resolver: Option, pub args: BTreeMap, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] -pub struct Arg { - pub type_of: wrapping_type::Type, - pub default_value: Option, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, schemars::JsonSchema, DirectiveDefinition, InputDefinition)] +#[directive_definition(locations = "FieldDefinition")] pub struct Http { pub path: String, #[serde(default, skip_serializing_if = "is_default")] @@ -95,10 +104,12 @@ pub struct Http { } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] -pub enum Resolver { - Http(Http), +pub struct Arg { + pub type_of: wrapping_type::Type, + pub default_value: Option, } + #[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(rename_all = "lowercase")] pub enum GraphQLOperationType { diff --git a/projects/ssddOnTop/src/config/url_query.rs b/projects/ssddOnTop/src/config/url_query.rs index df1410c..2c0a72f 100644 --- a/projects/ssddOnTop/src/config/url_query.rs +++ b/projects/ssddOnTop/src/config/url_query.rs @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize}; use crate::is_default; -#[derive(Serialize, Deserialize, Clone, Debug, Default, Eq, PartialEq)] +#[derive(Serialize, Deserialize, Clone, Debug, Default, Eq, PartialEq, schemars::JsonSchema)] #[serde(rename_all = "camelCase")] /// The URLQuery input type represents a query parameter to be included in a /// URL. diff --git a/projects/ssddOnTop/src/directive.rs b/projects/ssddOnTop/src/directive.rs index 16eb8c5..b513a47 100644 --- a/projects/ssddOnTop/src/directive.rs +++ b/projects/ssddOnTop/src/directive.rs @@ -1,24 +1,37 @@ -use anyhow::Result; use async_graphql::parser::types::ConstDirective; use async_graphql::{Name, Pos, Positioned}; use serde::{Deserialize, Serialize}; use serde_json::{Map, Value}; use serde_path_to_error::deserialize; +use crate::blueprint; fn pos(a: A) -> Positioned { Positioned::new(a, Pos::default()) } +#[allow(dead_code)] +fn to_const_directive(directive: &blueprint::Directive) -> anyhow::Result { + let mut arguments = Vec::new(); + for (k, v) in directive.arguments.iter() { + let name = pos(Name::new(k.clone())); + let x = serde_json::from_value(v.clone()).map(pos).map(|value| (name, value))?; + arguments.push(x); + } + Ok( + ConstDirective { name: pos(Name::new(directive.name.clone())), arguments } + ) +} + pub trait DirectiveCodec: Sized { fn directive_name() -> String; - fn from_directive(directive: &ConstDirective) -> Result; + fn from_directive(directive: &ConstDirective) -> anyhow::Result; fn to_directive(&self) -> ConstDirective; fn trace_name() -> String { format!("@{}", Self::directive_name()) } fn from_directives<'a>( directives: impl Iterator>, - ) -> Result> { + ) -> anyhow::Result> { for directive in directives { if directive.node.name.node == Self::directive_name() { return Self::from_directive(&directive.node).map(Some); @@ -47,14 +60,32 @@ impl<'a, A: Deserialize<'a> + Serialize + 'a> DirectiveCodec for A { ) } - fn from_directive(directive: &ConstDirective) -> Result { + fn from_directive(directive: &ConstDirective) -> anyhow::Result { let mut map = Map::new(); for (k, v) in directive.arguments.iter() { let (k, v) = serde_json::to_value(&v.node).map(|v| (k.node.as_str().to_string(), v))?; map.insert(k, v); } - Ok(deserialize(Value::Object(map))?) +/* Valid::from_iter(directive.arguments.iter(), |(k, v)| { + Valid::from(serde_json::to_value(&v.node).map_err(|e| { + ValidationError::new(e.to_string()) + .trace(format!("@{}", directive.name.node).as_str()) + })) + .map(|v| (k.node.as_str().to_string(), v)) + }) + .map(|items| { + items.iter().fold(Map::new(), |mut map, (k, v)| { + map.insert(k.clone(), v.clone()); + map + }) + }) + .and_then(|map| match deserialize(Value::Object(map)) { + Ok(a) => Valid::succeed(a), + Err(e) => Valid::from_validation_err( + ValidationError::from(e).trace(format!("@{}", directive.name.node).as_str()), + ), + })*/ } fn to_directive(&self) -> ConstDirective { @@ -71,9 +102,40 @@ impl<'a, A: Deserialize<'a> + Serialize + 'a> DirectiveCodec for A { )); } - ConstDirective { - name: pos(Name::new(name)), - arguments, - } + ConstDirective { name: pos(Name::new(name)), arguments } + } +} + +#[cfg(test)] +mod tests { + + use async_graphql::parser::types::ConstDirective; + use async_graphql_value::Name; + use pretty_assertions::assert_eq; + use crate::blueprint::Directive; + use crate::directive::{pos, to_const_directive}; + + #[test] + fn test_to_const_directive() { + let directive = Directive { + name: "test".to_string(), + arguments: vec![("a".to_string(), serde_json::json!(1.0))] + .into_iter() + .collect(), + index: 0, + }; + + let const_directive: ConstDirective = to_const_directive(&directive).unwrap(); + let expected_directive: ConstDirective = ConstDirective { + name: pos(Name::new("test")), + arguments: vec![(pos(Name::new("a")), pos(async_graphql::Value::from(1.0)))] + .into_iter() + .collect(), + }; + + assert_eq!( + format!("{:?}", const_directive), + format!("{:?}", expected_directive) + ); } } diff --git a/projects/ssddOnTop/src/from_doc.rs b/projects/ssddOnTop/src/from_doc.rs index a29e3a5..2a3c87d 100644 --- a/projects/ssddOnTop/src/from_doc.rs +++ b/projects/ssddOnTop/src/from_doc.rs @@ -1,5 +1,4 @@ use crate::config::{Arg, Cache, Config, Field, Resolver, RootSchema, Server, Type1, Upstream}; -use crate::directive::DirectiveCodec; use anyhow::Result; use async_graphql::parser::types::{ ConstDirective, FieldDefinition, InputObjectType, InputValueDefinition, InterfaceType, @@ -8,6 +7,7 @@ use async_graphql::parser::types::{ }; use async_graphql::{Name, Positioned}; use std::collections::BTreeMap; +use crate::directive::DirectiveCodec; const DEFAULT_SCHEMA_DEFINITION: &SchemaDefinition = &SchemaDefinition { extend: false, @@ -177,7 +177,7 @@ where let type_of = field.type_of(); let directives = field.directives(); - let resolver = Resolver::from_directives(directives.iter())?; + let resolver = Resolver::from_directives(directives)?; Ok(Field { ty_of: type_of.into(), args, diff --git a/projects/ssddOnTop/src/http/method.rs b/projects/ssddOnTop/src/http/method.rs index 18e2e22..053a19d 100644 --- a/projects/ssddOnTop/src/http/method.rs +++ b/projects/ssddOnTop/src/http/method.rs @@ -1,7 +1,7 @@ use serde::{Deserialize, Serialize}; use strum_macros::Display; -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash, Default, Display)] +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash, Default, Display, schemars::JsonSchema)] pub enum Method { #[default] GET, diff --git a/projects/ssddOnTop/src/http/request_handler.rs b/projects/ssddOnTop/src/http/request_handler.rs index 022f4c3..4e12565 100644 --- a/projects/ssddOnTop/src/http/request_handler.rs +++ b/projects/ssddOnTop/src/http/request_handler.rs @@ -6,6 +6,7 @@ use http_body_util::Full; use std::sync::Arc; use crate::app_ctx::AppCtx; use crate::http::method::Method; +use crate::ir::eval_ctx::EvalContext; use crate::request_context::RequestContext; pub async fn handle_request( @@ -30,14 +31,34 @@ pub async fn handle_request( Ok(resp) } +fn create_request_context(app_ctx: &AppCtx) -> RequestContext { + RequestContext::from(app_ctx) +} + + async fn handle_gql_req( request: Request, app_ctx: AppCtx, ) -> anyhow::Result>> { let gql_req: async_graphql::Request = serde_json::from_slice(&request.body)?; let doc = async_graphql::parser::parse_query(&gql_req.query)?; + let req_ctx = create_request_context(&app_ctx); if let Some(query) = app_ctx.blueprint.schema.query.as_ref() { - todo!() + let mut eval_ctx = EvalContext::new(&req_ctx); + + for (_,field) in app_ctx.blueprint.fields.iter() { + if let Some(ir) = field.ir.as_ref() { + println!("hx: {}", field.name.as_ref()); + println!("{}", ir.eval(&mut eval_ctx).await?); + }else { + println!("hx1: {}", field.name.as_ref()); + } + } + Ok( + hyper::Response::new(Full::new(Bytes::from_static( + b"Printed", + ))) + ) } else { Ok( hyper::Response::new(Full::new(Bytes::from_static( diff --git a/projects/ssddOnTop/src/ir/eval_ctx.rs b/projects/ssddOnTop/src/ir/eval_ctx.rs index ec17015..d580939 100644 --- a/projects/ssddOnTop/src/ir/eval_ctx.rs +++ b/projects/ssddOnTop/src/ir/eval_ctx.rs @@ -17,6 +17,13 @@ pub struct EvalContext<'a> { impl<'a> EvalContext<'a> { + pub fn new(request_ctx: &'a RequestContext) -> Self { + Self { + request_ctx, + graphql_ctx_value: None, + graphql_ctx_args: None, + } + } pub fn path_arg>(&self, path: &[T]) -> Option> { let args = self.graphql_ctx_args.as_ref()?; get_path_value(args.as_ref(), path).map(|a| Cow::Owned(a.clone())) diff --git a/projects/ssddOnTop/src/ir/model.rs b/projects/ssddOnTop/src/ir/model.rs index 2269589..f577a65 100644 --- a/projects/ssddOnTop/src/ir/model.rs +++ b/projects/ssddOnTop/src/ir/model.rs @@ -51,7 +51,7 @@ pub enum IO { } impl IR { - pub async fn eval<'a, 'b, Ctx>( + pub async fn eval<'a, 'b>( &'a self, ctx: &'b mut EvalContext<'a>, ) -> anyhow::Result { From 3ea7ac2fb2dac833a3ecaa0789b6a6bb5d6806cf Mon Sep 17 00:00:00 2001 From: Sandipsinh Rathod Date: Thu, 12 Sep 2024 00:17:34 -0400 Subject: [PATCH 07/21] in mem cache --- Cargo.lock | 1663 ++++++++++++++++- projects/ssddOnTop/src/blueprint/mod.rs | 2 +- .../ssddOnTop/src/http/request_handler.rs | 20 +- projects/ssddOnTop/src/ir/eval_ctx.rs | 20 +- projects/ssddOnTop/src/ir/eval_io.rs | 18 +- projects/ssddOnTop/src/path.rs | 15 +- projects/ssddOnTop/src/request_context.rs | 13 +- projects/ssddOnTop/src/target_runtime.rs | 9 +- projects/ssddOnTop/src/value/value.rs | 13 - 9 files changed, 1684 insertions(+), 89 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3730594..baa0dc7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,16 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "Inflector" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" +dependencies = [ + "lazy_static", + "regex", +] + [[package]] name = "addr2line" version = "0.22.0" @@ -92,15 +102,270 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.86" +version = "1.0.88" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e1496f8fb1fbf272686b8d37f523dab3e4a7443300055e74cdaa449f3114356" + +[[package]] +name = "ascii_utils" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71938f30533e4d95a6d17aa530939da3842c2ab6f4f84b9dae68447e4129f74a" + +[[package]] +name = "async-channel" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81953c529336010edd6d8e358f886d9581267795c61b19475b71314bffa46d35" +dependencies = [ + "concurrent-queue", + "event-listener 2.5.3", + "futures-core", +] + +[[package]] +name = "async-channel" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89b47800b0be77592da0afd425cc03468052844aff33b84e33cc696f64e77b6a" +dependencies = [ + "concurrent-queue", + "event-listener-strategy", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-executor" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30ca9a001c1e8ba5149f91a74362376cc6bc5b919d92d988668657bd570bdcec" +dependencies = [ + "async-task", + "concurrent-queue", + "fastrand", + "futures-lite", + "slab", +] + +[[package]] +name = "async-global-executor" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" +checksum = "05b1b633a2115cd122d73b955eadd9916c18c8f510ec9cd1686404c60ad1c29c" +dependencies = [ + "async-channel 2.3.1", + "async-executor", + "async-io", + "async-lock", + "blocking", + "futures-lite", + "once_cell", +] + +[[package]] +name = "async-graphql" +version = "7.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d37c3e9ba322eb00e9e5e997d58f08e8b6de037325b9367ac59bca8e3cd46af" +dependencies = [ + "async-graphql-derive", + "async-graphql-parser", + "async-graphql-value", + "async-stream", + "async-trait", + "base64 0.22.1", + "bytes", + "fast_chemail", + "fnv", + "futures-timer", + "futures-util", + "handlebars", + "http 1.1.0", + "indexmap", + "mime", + "multer", + "num-traits", + "once_cell", + "pin-project-lite", + "regex", + "serde", + "serde_json", + "serde_urlencoded", + "static_assertions_next", + "tempfile", + "thiserror", +] + +[[package]] +name = "async-graphql-derive" +version = "7.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1141703c11c6ad4fa9b3b0e1e476dea01dbd18a44db00f949b804afaab2f344" +dependencies = [ + "Inflector", + "async-graphql-parser", + "darling", + "proc-macro-crate", + "proc-macro2", + "quote", + "strum", + "syn", + "thiserror", +] + +[[package]] +name = "async-graphql-parser" +version = "7.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f66edcce4c38c18f7eb181fdf561c3d3aa2d644ce7358fc7a928c00a4ffef17" +dependencies = [ + "async-graphql-value", + "pest", + "serde", + "serde_json", +] + +[[package]] +name = "async-graphql-value" +version = "7.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0206011cad065420c27988f17dd7fe201a0e056b20c262209b7bffcd6fa176" +dependencies = [ + "bytes", + "indexmap", + "serde", + "serde_json", +] + +[[package]] +name = "async-io" +version = "2.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "444b0228950ee6501b3568d3c93bf1176a1fdbc3b758dcd9475046d30f4dc7e8" +dependencies = [ + "async-lock", + "cfg-if", + "concurrent-queue", + "futures-io", + "futures-lite", + "parking", + "polling", + "rustix", + "slab", + "tracing", + "windows-sys 0.59.0", +] + +[[package]] +name = "async-lock" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff6e472cdea888a4bd64f342f09b3f50e1886d32afe8df3d663c01140b811b18" +dependencies = [ + "event-listener 5.3.1", + "event-listener-strategy", + "pin-project-lite", +] + +[[package]] +name = "async-process" +version = "2.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8a07789659a4d385b79b18b9127fc27e1a59e1e89117c78c5ea3b806f016374" +dependencies = [ + "async-channel 2.3.1", + "async-io", + "async-lock", + "async-signal", + "async-task", + "blocking", + "cfg-if", + "event-listener 5.3.1", + "futures-lite", + "rustix", + "tracing", + "windows-sys 0.59.0", +] + +[[package]] +name = "async-signal" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "637e00349800c0bdf8bfc21ebbc0b6524abea702b0da4168ac00d070d0c0b9f3" +dependencies = [ + "async-io", + "async-lock", + "atomic-waker", + "cfg-if", + "futures-core", + "futures-io", + "rustix", + "signal-hook-registry", + "slab", + "windows-sys 0.59.0", +] + +[[package]] +name = "async-std" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c634475f29802fde2b8f0b505b1bd00dfe4df7d4a000f0b36f7671197d5c3615" +dependencies = [ + "async-channel 1.9.0", + "async-global-executor", + "async-io", + "async-lock", + "async-process", + "crossbeam-utils", + "futures-channel", + "futures-core", + "futures-io", + "futures-lite", + "gloo-timers", + "kv-log-macro", + "log", + "memchr", + "once_cell", + "pin-project-lite", + "pin-utils", + "slab", + "wasm-bindgen-futures", +] + +[[package]] +name = "async-stream" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd56dd203fef61ac097dd65721a419ddccb106b2d2b70ba60a6b529f03961a51" +dependencies = [ + "async-stream-impl", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-stream-impl" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "async-task" +version = "4.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de" [[package]] name = "async-trait" -version = "0.1.81" +version = "0.1.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107" +checksum = "a27b8a3a6e1a44fa4c8baf1f653e4172e81486d4941f2237e20dc2d0cf4ddff1" dependencies = [ "proc-macro2", "quote", @@ -129,10 +394,10 @@ dependencies = [ "axum-core", "bytes", "futures-util", - "http", - "http-body", + "http 1.1.0", + "http-body 1.0.1", "http-body-util", - "hyper", + "hyper 1.4.1", "hyper-util", "itoa", "matchit", @@ -162,8 +427,8 @@ dependencies = [ "async-trait", "bytes", "futures-util", - "http", - "http-body", + "http 1.1.0", + "http-body 1.0.1", "http-body-util", "mime", "pin-project-lite", @@ -201,12 +466,49 @@ version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + [[package]] name = "bitflags" version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "blocking" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "703f41c54fc768e63e091340b424302bb1c29ef4aa0c7f10fe849dfb114d29ea" +dependencies = [ + "async-channel 2.3.1", + "async-task", + "futures-io", + "futures-lite", + "piper", +] + [[package]] name = "bumpalo" version = "3.16.0" @@ -224,6 +526,35 @@ name = "bytes" version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" +dependencies = [ + "serde", +] + +[[package]] +name = "cacache" +version = "12.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "142316461ed3a3dfcba10417317472da5bfd0461e4d276bf7c07b330766d9490" +dependencies = [ + "async-std", + "digest", + "either", + "futures", + "hex", + "libc", + "memmap2", + "miette", + "reflink-copy", + "serde", + "serde_derive", + "serde_json", + "sha1", + "sha2", + "ssri", + "tempfile", + "thiserror", + "walkdir", +] [[package]] name = "cc" @@ -322,6 +653,30 @@ dependencies = [ "winapi", ] +[[package]] +name = "concurrent-queue" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + +[[package]] +name = "convert_case" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" +dependencies = [ + "unicode-segmentation", +] + [[package]] name = "core-foundation" version = "0.9.4" @@ -338,12 +693,84 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +[[package]] +name = "cpufeatures" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" +dependencies = [ + "libc", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33480d6946193aa8033910124896ca395333cae7e2d1113d1fef6c3272217df2" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "crossbeam-utils" version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "darling" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" +dependencies = [ + "darling_core", + "quote", + "syn", +] + [[package]] name = "dashmap" version = "5.5.3" @@ -366,6 +793,48 @@ dependencies = [ "powerfmt", ] +[[package]] +name = "derive-getters" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74ef43543e701c01ad77d3a5922755c6a1d71b22d942cb8042be4994b380caff" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "convert_case 0.4.0", + "proc-macro2", + "quote", + "rustc_version", + "syn", +] + +[[package]] +name = "derive_setters" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e8ef033054e131169b8f0f9a7af8f5533a9436fadf3c500ed547f730f07090d" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "diff" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" + [[package]] name = "diff_logger" version = "0.1.0" @@ -377,6 +846,22 @@ dependencies = [ "serde_json", ] +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "dyn-clone" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" + [[package]] name = "easy_retry" version = "0.1.0" @@ -387,6 +872,12 @@ dependencies = [ "tokio", ] +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + [[package]] name = "encoding_rs" version = "0.8.34" @@ -396,6 +887,27 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "env_filter" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f2c92ceda6ceec50f43169f9ee8424fe2db276791afde7b2cd8bc084cb376ab" +dependencies = [ + "log", +] + +[[package]] +name = "env_logger" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13fa619b91fb2381732789fc5de83b45675e882f66623b7d8cb4f643017018d" +dependencies = [ + "anstream", + "anstyle", + "env_filter", + "log", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -412,6 +924,42 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "event-listener" +version = "2.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" + +[[package]] +name = "event-listener" +version = "5.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6032be9bd27023a771701cc49f9f053c751055f71efb2e0ae5c15809093675ba" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite", +] + +[[package]] +name = "event-listener-strategy" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f214dc438f977e6d4e3500aaa277f5ad94ca83fbbd9b1a15713ce2344ccc5a1" +dependencies = [ + "event-listener 5.3.1", + "pin-project-lite", +] + +[[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 = "2.1.1" @@ -506,6 +1054,19 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" +[[package]] +name = "futures-lite" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52527eb5074e35e9339c6b4e8d12600c7128b68fb25dcb9fa9dec18f7c25f3a5" +dependencies = [ + "fastrand", + "futures-core", + "futures-io", + "parking", + "pin-project-lite", +] + [[package]] name = "futures-macro" version = "0.3.30" @@ -553,6 +1114,25 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + [[package]] name = "getrandom" version = "0.2.15" @@ -572,6 +1152,18 @@ version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" +[[package]] +name = "gloo-timers" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbb143cf96099802033e0d4f4963b19fd2e0b728bcf076cd9cf7f6634f092994" +dependencies = [ + "futures-channel", + "futures-core", + "js-sys", + "wasm-bindgen", +] + [[package]] name = "governor" version = "0.6.3" @@ -592,6 +1184,25 @@ dependencies = [ "spinning_top", ] +[[package]] +name = "h2" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http 0.2.12", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + [[package]] name = "h2" version = "0.4.6" @@ -603,7 +1214,7 @@ dependencies = [ "fnv", "futures-core", "futures-sink", - "http", + "http 1.1.0", "indexmap", "slab", "tokio", @@ -623,7 +1234,7 @@ dependencies = [ "mock_json", "octocrate", "regex", - "reqwest", + "reqwest 0.12.7", "serde", "serde_json", "tokio", @@ -631,6 +1242,20 @@ dependencies = [ "tracing-subscriber", ] +[[package]] +name = "handlebars" +version = "5.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d08485b96a0e6393e9e4d1b8d48cf74ad6c063cd905eb33f42c1ce3f0377539b" +dependencies = [ + "log", + "pest", + "pest_derive", + "serde", + "serde_json", + "thiserror", +] + [[package]] name = "hashbrown" version = "0.14.5" @@ -649,6 +1274,29 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +[[package]] +name = "hermit-abi" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "http" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + [[package]] name = "http" version = "1.1.0" @@ -660,6 +1308,17 @@ dependencies = [ "itoa", ] +[[package]] +name = "http-body" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" +dependencies = [ + "bytes", + "http 0.2.12", + "pin-project-lite", +] + [[package]] name = "http-body" version = "1.0.1" @@ -667,7 +1326,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ "bytes", - "http", + "http 1.1.0", ] [[package]] @@ -678,11 +1337,69 @@ checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" dependencies = [ "bytes", "futures-util", - "http", - "http-body", + "http 1.1.0", + "http-body 1.0.1", "pin-project-lite", ] +[[package]] +name = "http-cache" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b5ab65432bbdfe8490dfde21d0366353a8d39f2bc24aca0146889f931b0b4b5" +dependencies = [ + "async-trait", + "bincode", + "cacache", + "http 0.2.12", + "http-cache-semantics", + "httpdate", + "moka", + "serde", + "url", +] + +[[package]] +name = "http-cache-reqwest" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8285341ce7e709c56a0f259ff1c789c70edfbaa88acd69d27e4d63980b92dc" +dependencies = [ + "anyhow", + "async-trait", + "http 0.2.12", + "http-cache", + "http-cache-semantics", + "reqwest 0.11.27", + "reqwest-middleware", + "serde", + "task-local-extensions", + "url", +] + +[[package]] +name = "http-cache-semantics" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7aec9f678bca3f4a15194b980f20ed9bfe0dd38e8d298c65c559a93dfbd6380a" +dependencies = [ + "http 0.2.12", + "http-serde", + "reqwest 0.11.27", + "serde", + "time", +] + +[[package]] +name = "http-serde" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f560b665ad9f1572cfcaf034f7fb84338a7ce945216d64a90fd81f046a3caee" +dependencies = [ + "http 0.2.12", + "serde", +] + [[package]] name = "httparse" version = "1.9.4" @@ -695,6 +1412,30 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" +[[package]] +name = "hyper" +version = "0.14.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a152ddd61dfaec7273fe8419ab357f33aee0d914c5f4efbf0d96fa749eea5ec9" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2 0.3.26", + "http 0.2.12", + "http-body 0.4.6", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + [[package]] name = "hyper" version = "1.4.1" @@ -704,9 +1445,9 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", - "http", - "http-body", + "h2 0.4.6", + "http 1.1.0", + "http-body 1.0.1", "httparse", "httpdate", "itoa", @@ -723,14 +1464,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5ee4be2c948921a1a5320b629c4193916ed787a7f7f293fd3f7f5a6c9de74155" dependencies = [ "futures-util", - "http", - "hyper", + "http 1.1.0", + "hyper 1.4.1", "hyper-util", "rustls", "rustls-pki-types", "tokio", - "tokio-rustls", - "tower-service", + "tokio-rustls", + "tower-service", +] + +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes", + "hyper 0.14.30", + "native-tls", + "tokio", + "tokio-native-tls", ] [[package]] @@ -741,7 +1495,7 @@ checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" dependencies = [ "bytes", "http-body-util", - "hyper", + "hyper 1.4.1", "hyper-util", "native-tls", "tokio", @@ -751,16 +1505,16 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.7" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cde7055719c54e36e95e8719f95883f22072a48ede39db7fc17a4e1d5281e9b9" +checksum = "da62f120a8a37763efb0cf8fdf264b884c7b8b9ac8660b900c8661030c00e6ba" dependencies = [ "bytes", "futures-channel", "futures-util", - "http", - "http-body", - "hyper", + "http 1.1.0", + "http-body 1.0.1", + "hyper 1.4.1", "pin-project-lite", "socket2", "tokio", @@ -780,7 +1534,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core", + "windows-core 0.52.0", ] [[package]] @@ -792,6 +1546,12 @@ dependencies = [ "cc", ] +[[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.5.0" @@ -802,6 +1562,12 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "indenter" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" + [[package]] name = "indexmap" version = "2.5.0" @@ -810,6 +1576,7 @@ checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" dependencies = [ "equivalent", "hashbrown", + "serde", ] [[package]] @@ -824,6 +1591,15 @@ version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" +[[package]] +name = "itertools" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.11" @@ -854,6 +1630,15 @@ dependencies = [ "simple_asn1", ] +[[package]] +name = "kv-log-macro" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" +dependencies = [ + "log", +] + [[package]] name = "lazy_static" version = "1.5.0" @@ -866,6 +1651,12 @@ version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" +[[package]] +name = "linked-hash-map" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" + [[package]] name = "linux-raw-sys" version = "0.4.14" @@ -887,6 +1678,28 @@ name = "log" version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" +dependencies = [ + "value-bag", +] + +[[package]] +name = "macros" +version = "0.1.0" +dependencies = [ + "anyhow", + "macros_common", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "macros_common" +version = "0.1.0" +dependencies = [ + "async-graphql", + "schemars", +] [[package]] name = "matchers" @@ -909,12 +1722,60 @@ version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +[[package]] +name = "memmap2" +version = "0.5.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83faa42c0a078c393f6b29d5db232d8be22776a891f8f56e5284faee4a20b327" +dependencies = [ + "libc", +] + +[[package]] +name = "miette" +version = "5.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59bb584eaeeab6bd0226ccf3509a69d7936d148cf3d036ad350abe35e8c6856e" +dependencies = [ + "miette-derive", + "once_cell", + "thiserror", + "unicode-width", +] + +[[package]] +name = "miette-derive" +version = "5.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49e7bc1560b95a3c4a25d03de42fe76ca718ab92d1a22a55b9b4cf67b3ae635c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "mime" version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" +[[package]] +name = "mime_guess" +version = "2.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e" +dependencies = [ + "mime", + "unicase", +] + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "miniz_oxide" version = "0.7.4" @@ -930,7 +1791,7 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" dependencies = [ - "hermit-abi", + "hermit-abi 0.3.9", "libc", "wasi", "windows-sys 0.52.0", @@ -963,6 +1824,47 @@ dependencies = [ "serde_json", ] +[[package]] +name = "moka" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32cf62eb4dd975d2dde76432fb1075c49e3ee2331cf36f1f8fd4b66550d32b6f" +dependencies = [ + "async-lock", + "async-trait", + "crossbeam-channel", + "crossbeam-epoch", + "crossbeam-utils", + "event-listener 5.3.1", + "futures-util", + "once_cell", + "parking_lot", + "quanta", + "rustc_version", + "smallvec", + "tagptr", + "thiserror", + "triomphe", + "uuid", +] + +[[package]] +name = "multer" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83e87776546dc87511aa5ee218730c92b666d7264ab6ed41f9d215af9cd5224b" +dependencies = [ + "bytes", + "encoding_rs", + "futures-util", + "http 1.1.0", + "httparse", + "memchr", + "mime", + "spin", + "version_check", +] + [[package]] name = "native-tls" version = "0.2.12" @@ -986,7 +1888,7 @@ version = "0.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2eb04e9c688eff1c89d72b407f168cf79bb9e867a9d3323ed6c01519eb9cc053" dependencies = [ - "bitflags", + "bitflags 2.6.0", "cfg-if", "libc", ] @@ -997,6 +1899,16 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b93853da6d84c2e3c7d730d6473e8817692dd89be387eb01b94d7f108ecb5b8c" +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + [[package]] name = "nonempty" version = "0.7.0" @@ -1053,6 +1965,16 @@ dependencies = [ "autocfg", ] +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi 0.3.9", + "libc", +] + [[package]] name = "object" version = "0.36.4" @@ -1084,7 +2006,7 @@ dependencies = [ "chrono", "jsonwebtoken", "octocrate-types", - "reqwest", + "reqwest 0.12.7", "serde", "serde_json", "thiserror", @@ -1113,7 +2035,7 @@ version = "0.10.66" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" dependencies = [ - "bitflags", + "bitflags 2.6.0", "cfg-if", "foreign-types", "libc", @@ -1157,6 +2079,12 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" +[[package]] +name = "parking" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" + [[package]] name = "parking_lot" version = "0.12.3" @@ -1196,6 +2124,51 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" +[[package]] +name = "pest" +version = "2.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c73c26c01b8c87956cea613c907c9d6ecffd8d18a2a5908e5de0adfaa185cea" +dependencies = [ + "memchr", + "thiserror", + "ucd-trie", +] + +[[package]] +name = "pest_derive" +version = "2.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "664d22978e2815783adbdd2c588b455b1bd625299ce36b2a99881ac9627e6d8d" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2d5487022d5d33f4c30d91c22afa240ce2a644e87fe08caad974d4eab6badbe" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pest_meta" +version = "2.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0091754bbd0ea592c4deb3a122ce8ecbb0753b738aa82bc055fcc2eccc8d8174" +dependencies = [ + "once_cell", + "pest", + "sha2", +] + [[package]] name = "pin-project" version = "1.1.5" @@ -1228,12 +2201,38 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "piper" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96c8c490f422ef9a4efd2cb5b42b76c8613d7e7dfc1caf667b8a3350a5acc066" +dependencies = [ + "atomic-waker", + "fastrand", + "futures-io", +] + [[package]] name = "pkg-config" version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +[[package]] +name = "polling" +version = "3.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc2790cd301dec6cd3b7a025e4815cf825724a51c98dccfe6a3e55f05ffb6511" +dependencies = [ + "cfg-if", + "concurrent-queue", + "hermit-abi 0.4.0", + "pin-project-lite", + "rustix", + "tracing", + "windows-sys 0.59.0", +] + [[package]] name = "portable-atomic" version = "1.7.0" @@ -1255,6 +2254,25 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "pretty_assertions" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af7cee1a6c8a5b9208b3cb1061f10c0cb689087b3d8ce85fb9d2dd7a29b6ba66" +dependencies = [ + "diff", + "yansi", +] + +[[package]] +name = "proc-macro-crate" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecf48c7ca261d60b74ab1a7b20da18bede46776b2e55535cb958eb595c5fa7b" +dependencies = [ + "toml_edit", +] + [[package]] name = "proc-macro2" version = "1.0.86" @@ -1264,6 +2282,49 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "prost" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b2ecbe40f08db5c006b5764a2645f7f3f141ce756412ac9e1dd6087e6d32995" +dependencies = [ + "bytes", + "prost-derive", +] + +[[package]] +name = "prost-derive" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acf0c195eebb4af52c752bec4f52f645da98b6e92077a04110c7f349477ae5ac" +dependencies = [ + "anyhow", + "itertools", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "prost-reflect" +version = "0.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b7535b02f0e5efe3e1dbfcb428be152226ed0c66cad9541f2274c8ba8d4cd40" +dependencies = [ + "once_cell", + "prost", + "prost-types", +] + +[[package]] +name = "prost-types" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60caa6738c7369b940c3d49246a8d1749323674c65cb13010134f5c9bad5b519" +dependencies = [ + "prost", +] + [[package]] name = "quanta" version = "0.12.3" @@ -1324,7 +2385,7 @@ version = "11.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb9ee317cfe3fbd54b36a511efc1edd42e216903c9cd575e686dd68a2ba90d8d" dependencies = [ - "bitflags", + "bitflags 2.6.0", ] [[package]] @@ -1333,7 +2394,18 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" dependencies = [ - "bitflags", + "bitflags 2.6.0", +] + +[[package]] +name = "reflink-copy" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc31414597d1cd7fdd2422798b7652a6329dda0fe0219e6335a13d5bcaa9aeb6" +dependencies = [ + "cfg-if", + "rustix", + "windows", ] [[package]] @@ -1380,6 +2452,47 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" +[[package]] +name = "reqwest" +version = "0.11.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd67538700a17451e7cba03ac727fb961abb7607553461627b97de0b89cf4a62" +dependencies = [ + "base64 0.21.7", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2 0.3.26", + "http 0.2.12", + "http-body 0.4.6", + "hyper 0.14.30", + "hyper-tls 0.5.0", + "ipnet", + "js-sys", + "log", + "mime", + "mime_guess", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile 1.0.4", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper 0.1.2", + "system-configuration 0.5.1", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", +] + [[package]] name = "reqwest" version = "0.12.7" @@ -1391,13 +2504,13 @@ dependencies = [ "encoding_rs", "futures-core", "futures-util", - "h2", - "http", - "http-body", + "h2 0.4.6", + "http 1.1.0", + "http-body 1.0.1", "http-body-util", - "hyper", + "hyper 1.4.1", "hyper-rustls", - "hyper-tls", + "hyper-tls 0.6.0", "hyper-util", "ipnet", "js-sys", @@ -1407,12 +2520,12 @@ dependencies = [ "once_cell", "percent-encoding", "pin-project-lite", - "rustls-pemfile", + "rustls-pemfile 2.1.3", "serde", "serde_json", "serde_urlencoded", "sync_wrapper 1.0.1", - "system-configuration", + "system-configuration 0.6.1", "tokio", "tokio-native-tls", "tower-service", @@ -1423,6 +2536,21 @@ dependencies = [ "windows-registry", ] +[[package]] +name = "reqwest-middleware" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a735987236a8e238bf0296c7e351b999c188ccc11477f311b82b55c93984216" +dependencies = [ + "anyhow", + "async-trait", + "http 0.2.12", + "reqwest 0.11.27", + "serde", + "task-local-extensions", + "thiserror", +] + [[package]] name = "ring" version = "0.17.8" @@ -1444,13 +2572,22 @@ version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + [[package]] name = "rustix" version = "0.38.35" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a85d50532239da68e9addb745ba38ff4612a242c1c7ceea689c4bc7c2f43c36f" dependencies = [ - "bitflags", + "bitflags 2.6.0", "errno", "libc", "linux-raw-sys", @@ -1470,6 +2607,15 @@ dependencies = [ "zeroize", ] +[[package]] +name = "rustls-pemfile" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" +dependencies = [ + "base64 0.21.7", +] + [[package]] name = "rustls-pemfile" version = "2.1.3" @@ -1509,6 +2655,15 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + [[package]] name = "schannel" version = "0.1.23" @@ -1518,6 +2673,30 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "schemars" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09c024468a378b7e36765cd36702b7a90cc3cba11654f6685c8f233408e89e92" +dependencies = [ + "dyn-clone", + "schemars_derive", + "serde", + "serde_json", +] + +[[package]] +name = "schemars_derive" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1eee588578aff73f856ab961cd2f79e36bc45d7ded33a7562adba4667aecc0e" +dependencies = [ + "proc-macro2", + "quote", + "serde_derive_internals", + "syn", +] + [[package]] name = "scopeguard" version = "1.2.0" @@ -1530,7 +2709,7 @@ version = "2.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" dependencies = [ - "bitflags", + "bitflags 2.6.0", "core-foundation", "core-foundation-sys", "libc", @@ -1547,6 +2726,12 @@ dependencies = [ "libc", ] +[[package]] +name = "semver" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" + [[package]] name = "serde" version = "1.0.210" @@ -1567,6 +2752,17 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_derive_internals" +version = "0.29.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "serde_json" version = "1.0.127" @@ -1580,6 +2776,16 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_json_borrow" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "176a77dea19cf9b2cfe7f9e31966112ef8282a709af7c0a0fb28fc6347c7ba78" +dependencies = [ + "serde", + "serde_json", +] + [[package]] name = "serde_path_to_error" version = "0.1.16" @@ -1602,6 +2808,39 @@ dependencies = [ "serde", ] +[[package]] +name = "sha-1" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5058ada175748e33390e40e872bd0fe59a19f265d0158daa551c5a88a76009c" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + [[package]] name = "sharded-slab" version = "0.1.7" @@ -1678,12 +2917,104 @@ dependencies = [ "lock_api", ] +[[package]] +name = "ssddOnTop" +version = "0.1.0" +dependencies = [ + "anyhow", + "async-graphql", + "async-graphql-value", + "async-trait", + "bytes", + "convert_case 0.6.0", + "derive-getters", + "derive_more", + "derive_setters", + "futures-util", + "fxhash", + "http 1.1.0", + "http-body-util", + "http-cache", + "http-cache-reqwest", + "http-cache-semantics", + "hyper 1.4.1", + "hyper-util", + "indenter", + "indexmap", + "macros", + "macros_common", + "moka", + "nom", + "num_cpus", + "pretty_assertions", + "prost-reflect", + "reqwest 0.11.27", + "reqwest-middleware", + "schemars", + "serde", + "serde_json", + "serde_json_borrow", + "serde_path_to_error", + "strum_macros", + "test-log", + "tokio", + "tracing", + "tracing-subscriber", + "ttl_cache", + "url", +] + +[[package]] +name = "ssri" +version = "9.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da7a2b3c2bc9693bcb40870c4e9b5bf0d79f9cb46273321bf855ec513e919082" +dependencies = [ + "base64 0.21.7", + "digest", + "hex", + "miette", + "serde", + "sha-1", + "sha2", + "thiserror", + "xxhash-rust", +] + +[[package]] +name = "static_assertions_next" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7beae5182595e9a8b683fa98c4317f956c9a2dec3b9716990d20023cc60c766" + [[package]] name = "strsim" version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" +[[package]] +name = "strum" +version = "0.26.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn", +] + [[package]] name = "subtle" version = "2.6.1" @@ -1716,15 +3047,36 @@ dependencies = [ "futures-core", ] +[[package]] +name = "system-configuration" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "system-configuration-sys 0.5.0", +] + [[package]] name = "system-configuration" version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" dependencies = [ - "bitflags", + "bitflags 2.6.0", "core-foundation", - "system-configuration-sys", + "system-configuration-sys 0.6.0", +] + +[[package]] +name = "system-configuration-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" +dependencies = [ + "core-foundation-sys", + "libc", ] [[package]] @@ -1737,6 +3089,21 @@ dependencies = [ "libc", ] +[[package]] +name = "tagptr" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b2093cf4c8eb1e67749a6762251bc9cd836b6fc171623bd0a9d324d37af2417" + +[[package]] +name = "task-local-extensions" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba323866e5d033818e3240feeb9f7db2c4296674e4d9e16b97b7bf8f490434e8" +dependencies = [ + "pin-utils", +] + [[package]] name = "tempfile" version = "3.12.0" @@ -1750,6 +3117,28 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "test-log" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dffced63c2b5c7be278154d76b479f9f9920ed34e7574201407f0b14e2bbb93" +dependencies = [ + "env_logger", + "test-log-macros", + "tracing-subscriber", +] + +[[package]] +name = "test-log-macros" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5999e24eaa32083191ba4e425deb75cdf25efefabe5aaccb7446dd0d4122a3f5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "thiserror" version = "1.0.63" @@ -1889,6 +3278,23 @@ dependencies = [ "tokio", ] +[[package]] +name = "toml_datetime" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" + +[[package]] +name = "toml_edit" +version = "0.22.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" +dependencies = [ + "indexmap", + "toml_datetime", + "winnow", +] + [[package]] name = "tower" version = "0.4.13" @@ -1926,7 +3332,7 @@ dependencies = [ "axum", "forwarded-header-value", "governor", - "http", + "http 1.1.0", "pin-project", "thiserror", "tower", @@ -1995,12 +3401,27 @@ dependencies = [ "tracing-log", ] +[[package]] +name = "triomphe" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "859eb650cfee7434994602c3a68b25d77ad9e68c8a6cd491616ef86661382eb3" + [[package]] name = "try-lock" version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" +[[package]] +name = "ttl_cache" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4189890526f0168710b6ee65ceaedf1460c48a14318ceec933cb26baa492096a" +dependencies = [ + "linked-hash-map", +] + [[package]] name = "typed-builder" version = "0.18.2" @@ -2021,6 +3442,27 @@ dependencies = [ "syn", ] +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "ucd-trie" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" + +[[package]] +name = "unicase" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" +dependencies = [ + "version_check", +] + [[package]] name = "unicode-bidi" version = "0.3.15" @@ -2042,6 +3484,18 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "unicode-segmentation" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" + +[[package]] +name = "unicode-width" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" + [[package]] name = "untrusted" version = "0.9.0" @@ -2057,6 +3511,7 @@ dependencies = [ "form_urlencoded", "idna", "percent-encoding", + "serde", ] [[package]] @@ -2065,18 +3520,49 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" +[[package]] +name = "uuid" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81dfa00651efa65069b0b6b651f4aaa31ba9e3c3ce0137aaad053604ee7e0314" +dependencies = [ + "getrandom", +] + [[package]] name = "valuable" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[package]] +name = "value-bag" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a84c137d37ab0142f0f2ddfe332651fdbf252e7b7dbb4e67b6c1f1b2e925101" + [[package]] name = "vcpkg" version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + [[package]] name = "want" version = "0.3.1" @@ -2185,12 +3671,31 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +dependencies = [ + "windows-sys 0.59.0", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd04d41d93c4992d421894c18c8b43496aa748dd4c081bac0dc93eb0489272b6" +dependencies = [ + "windows-core 0.58.0", + "windows-targets 0.52.6", +] + [[package]] name = "windows-core" version = "0.52.0" @@ -2200,6 +3705,41 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-core" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-implement" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -2378,6 +3918,37 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "winnow" +version = "0.6.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" +dependencies = [ + "memchr", +] + +[[package]] +name = "winreg" +version = "0.50.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" +dependencies = [ + "cfg-if", + "windows-sys 0.48.0", +] + +[[package]] +name = "xxhash-rust" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a5cbf750400958819fb6178eaa83bee5cd9c29a26a40cc241df8c70fdd46984" + +[[package]] +name = "yansi" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" + [[package]] name = "zerocopy" version = "0.7.35" diff --git a/projects/ssddOnTop/src/blueprint/mod.rs b/projects/ssddOnTop/src/blueprint/mod.rs index 1d66931..459b235 100644 --- a/projects/ssddOnTop/src/blueprint/mod.rs +++ b/projects/ssddOnTop/src/blueprint/mod.rs @@ -1,6 +1,6 @@ mod blueprint; mod definitions; -mod model; +pub mod model; mod operators; pub mod wrapping_type; diff --git a/projects/ssddOnTop/src/http/request_handler.rs b/projects/ssddOnTop/src/http/request_handler.rs index 4e12565..d4148e8 100644 --- a/projects/ssddOnTop/src/http/request_handler.rs +++ b/projects/ssddOnTop/src/http/request_handler.rs @@ -1,13 +1,15 @@ use std::ops::Deref; -use crate::blueprint::Blueprint; +use crate::blueprint::{Blueprint, FieldHash}; use crate::http::request::Request; use bytes::Bytes; use http_body_util::Full; use std::sync::Arc; use crate::app_ctx::AppCtx; +use crate::blueprint::model::{FieldName, TypeName}; use crate::http::method::Method; use crate::ir::eval_ctx::EvalContext; use crate::request_context::RequestContext; +use crate::value::Value; pub async fn handle_request( req: Request, @@ -45,15 +47,27 @@ async fn handle_gql_req( let req_ctx = create_request_context(&app_ctx); if let Some(query) = app_ctx.blueprint.schema.query.as_ref() { let mut eval_ctx = EvalContext::new(&req_ctx); + let x = app_ctx.blueprint.fields.get(&FieldHash { + name: FieldName("post".to_string()), + id: TypeName(query.to_string()), + }); + let x = x.as_ref().unwrap().ir.as_ref().unwrap(); + let mut map = serde_json::Map::new(); + let key = "id".to_string(); + let val = serde_json::Value::Number(serde_json::Number::from(1)); + map.insert(key, val); + eval_ctx = eval_ctx.with_args(Value::new(serde_json::Value::Object(map))); - for (_,field) in app_ctx.blueprint.fields.iter() { + let x = x.eval(&mut eval_ctx).await?; + println!("{}", x); + /*for (_,field) in app_ctx.blueprint.fields.iter() { if let Some(ir) = field.ir.as_ref() { println!("hx: {}", field.name.as_ref()); println!("{}", ir.eval(&mut eval_ctx).await?); }else { println!("hx1: {}", field.name.as_ref()); } - } + }*/ Ok( hyper::Response::new(Full::new(Bytes::from_static( b"Printed", diff --git a/projects/ssddOnTop/src/ir/eval_ctx.rs b/projects/ssddOnTop/src/ir/eval_ctx.rs index d580939..3c30a6b 100644 --- a/projects/ssddOnTop/src/ir/eval_ctx.rs +++ b/projects/ssddOnTop/src/ir/eval_ctx.rs @@ -10,9 +10,9 @@ pub struct EvalContext<'a> { // graphql_ctx: &'a Ctx, - graphql_ctx_value: Option>, + graphql_ctx_value: Option, - graphql_ctx_args: Option>, + graphql_ctx_args: Option, } @@ -24,15 +24,27 @@ impl<'a> EvalContext<'a> { graphql_ctx_args: None, } } + pub fn with_value(self, value: Value) -> Self { + Self { + graphql_ctx_value: Some(value), + ..self + } + } + pub fn with_args(self, args: Value) -> Self { + Self { + graphql_ctx_args: Some(args), + ..self + } + } pub fn path_arg>(&self, path: &[T]) -> Option> { let args = self.graphql_ctx_args.as_ref()?; - get_path_value(args.as_ref(), path).map(|a| Cow::Owned(a.clone())) + get_path_value(args, path).map(|a| Cow::Owned(a.clone())) } pub fn path_value>(&self, path: &[T]) -> Option> { // TODO: add unit tests for this if let Some(value) = self.graphql_ctx_value.as_ref() { - get_path_value(value.as_ref(), path).map(|a| Cow::Owned(a)) + get_path_value(value, path).map(|a| Cow::Owned(a)) } else { Some(Cow::Owned(Value::new(serde_json::Value::Null))) // get_path_value(self.graphql_ctx.value()?, path).map(Cow::Borrowed) diff --git a/projects/ssddOnTop/src/ir/eval_io.rs b/projects/ssddOnTop/src/ir/eval_io.rs index 6c25d30..80e6974 100644 --- a/projects/ssddOnTop/src/ir/eval_io.rs +++ b/projects/ssddOnTop/src/ir/eval_io.rs @@ -1,3 +1,5 @@ +use std::num::NonZeroU64; +use futures_util::FutureExt; use crate::ir::eval_ctx::EvalContext; use crate::ir::eval_http::EvalHttp; use crate::ir::IO; @@ -7,15 +9,13 @@ use crate::value::Value; pub async fn eval_io(io: &IO, ctx: &mut EvalContext<'_>) -> anyhow::Result { let key = io.cache_key(ctx); - ctx.request_ctx - .cache - .dedupe(&key, || async { - ctx.request_ctx - .cache - .dedupe(&key, || eval_io_inner(io, ctx)) - .await - }) - .await.map_err(|v| v.into()) + if let Some(val) = ctx.request_ctx.cache.get(&key).await? { + Ok(val.clone()) + } else { + let val = eval_io_inner(io, ctx).await?; + ctx.request_ctx.cache.set(key, val.clone(), NonZeroU64::MAX).await?; + Ok(val) + } } async fn eval_io_inner(io: &IO, ctx: &mut EvalContext<'_>) -> Result { diff --git a/projects/ssddOnTop/src/path.rs b/projects/ssddOnTop/src/path.rs index 96fb7dd..f7c71bf 100644 --- a/projects/ssddOnTop/src/path.rs +++ b/projects/ssddOnTop/src/path.rs @@ -83,6 +83,7 @@ impl<'a> EvalContext<'a> { let ctx = self; if path.is_empty() { + println!("none0"); return None; } @@ -93,7 +94,10 @@ impl<'a> EvalContext<'a> { /* "vars" => Some(ValueString::String(Cow::Owned( json!(ctx.vars()).to_string(), ))),*/ - _ => None, + _ => { + println!("none"); + None + }, }; } @@ -108,7 +112,10 @@ impl<'a> EvalContext<'a> { ctx.var(tail[0].as_ref())?, ))),*/ // "env" => Some(ValueString::String(ctx.env_var(tail[0].as_ref())?)), - _ => None, + _ => { + println!("none1"); + None + }, }) } } @@ -122,7 +129,9 @@ impl<'a> PathValue for EvalContext<'a> { impl<'a> PathString for EvalContext<'a> { fn path_string>(&self, path: &[T]) -> Option> { self.to_raw_value(path).and_then(|value| match value { - ValueString::String(env) => Some(env), + ValueString::String(env) => { + Some(env) + }, ValueString::Value(value) => convert_value(value), }) } diff --git a/projects/ssddOnTop/src/request_context.rs b/projects/ssddOnTop/src/request_context.rs index b438497..44cdc9c 100644 --- a/projects/ssddOnTop/src/request_context.rs +++ b/projects/ssddOnTop/src/request_context.rs @@ -8,6 +8,7 @@ use crate::target_runtime::TargetRuntime; use crate::value::Value; use derive_setters::Setters; use crate::dl::dedupe::Dedupe; +use crate::target_runtime::cache::InMemoryCache; #[derive(Clone)] pub struct CacheErr(String); @@ -31,8 +32,8 @@ pub struct RequestContext { pub min_max_age: Arc>>, pub cache_public: Arc>>, pub runtime: TargetRuntime, - // pub cache: DedupeResult, - pub cache: Dedupe>, + pub cache: InMemoryCache, + // pub cache: Dedupe>, } impl RequestContext { @@ -43,7 +44,8 @@ impl RequestContext { min_max_age: Arc::new(Mutex::new(None)), cache_public: Arc::new(Mutex::new(None)), runtime: target_runtime, - cache: Dedupe::new(1, true), + // cache: Dedupe::new(1, true), + cache: InMemoryCache::new(), } } fn set_min_max_age_conc(&self, min_max_age: i32) { @@ -74,7 +76,7 @@ impl RequestContext { } } - pub async fn cache_get(&self, key: &IoId) -> Result>, anyhow::Error> { + pub async fn cache_get(&self, key: &IoId) -> Result, anyhow::Error> { self.runtime.cache.get(key).await } @@ -97,7 +99,8 @@ impl From<&AppCtx> for RequestContext { min_max_age: Arc::new(Mutex::new(None)), cache_public: Arc::new(Mutex::new(None)), runtime: app_ctx.runtime.clone(), - cache: Dedupe::new(1, true), + // cache: Dedupe::new(1, true), + cache: InMemoryCache::new(), } } } diff --git a/projects/ssddOnTop/src/target_runtime.rs b/projects/ssddOnTop/src/target_runtime.rs index 7b83d8d..e45faed 100644 --- a/projects/ssddOnTop/src/target_runtime.rs +++ b/projects/ssddOnTop/src/target_runtime.rs @@ -19,14 +19,13 @@ impl TargetRuntime { } } -mod cache { +pub mod cache { use std::hash::Hash; use std::num::NonZeroU64; use std::sync::{Arc, RwLock}; use std::time::Duration; use ttl_cache::TtlCache; - use crate::value::ToInner; pub struct InMemoryCache { data: Arc>>, @@ -48,15 +47,15 @@ mod cache { } } - impl, Inner: Clone> InMemoryCache { + impl InMemoryCache { pub async fn set<'a>(&'a self, key: K, value: V, ttl: NonZeroU64) -> anyhow::Result<()> { let ttl = Duration::from_millis(ttl.get()); self.data.write().unwrap().insert(key, value, ttl); Ok(()) } - pub async fn get<'a>(&'a self, key: &'a K) -> anyhow::Result> { - let val = self.data.read().unwrap().get(key).map(|v| v.to_inner()); + pub async fn get<'a>(&'a self, key: &'a K) -> anyhow::Result> { + let val = self.data.read().unwrap().get(key).cloned(); Ok(val) } } diff --git a/projects/ssddOnTop/src/value/value.rs b/projects/ssddOnTop/src/value/value.rs index dd74401..91cae94 100644 --- a/projects/ssddOnTop/src/value/value.rs +++ b/projects/ssddOnTop/src/value/value.rs @@ -1,19 +1,6 @@ use std::fmt::{Display, Formatter}; use derive_getters::Getters; -pub trait ToInner { - type Inner; - fn to_inner(&self) -> Self::Inner; -} - -impl ToInner for Value { - type Inner = serde_json_borrow::Value<'static>; - - fn to_inner(&self) -> Self::Inner { - self.borrowed.clone() - } -} - #[derive(Getters, Debug, Clone, PartialEq, Eq, Hash)] pub struct Value { serde: serde_json::Value, From 7c79b4e10e3c56ec11c4c86284818ef64e9a4fcb Mon Sep 17 00:00:00 2001 From: Sandipsinh Rathod Date: Thu, 12 Sep 2024 00:17:49 -0400 Subject: [PATCH 08/21] fmt --- .../ssddOnTop/macros-common/src/common.rs | 1 - .../macros-common/src/enum_definition.rs | 4 +- .../macros-common/src/input_definition.rs | 25 ++++++++-- projects/ssddOnTop/macros-common/src/lib.rs | 8 ++- projects/ssddOnTop/macros/src/merge_right.rs | 37 +++++++------- projects/ssddOnTop/src/app_ctx.rs | 4 +- .../ssddOnTop/src/blueprint/operators/http.rs | 8 +-- projects/ssddOnTop/src/cache.rs | 12 +++-- projects/ssddOnTop/src/config/config.rs | 33 +++++++++---- projects/ssddOnTop/src/directive.rs | 24 +++++---- projects/ssddOnTop/src/dl/dedupe.rs | 34 ++++++++++--- projects/ssddOnTop/src/dl/mod.rs | 2 +- projects/ssddOnTop/src/from_doc.rs | 2 +- projects/ssddOnTop/src/http/headers.rs | 7 ++- projects/ssddOnTop/src/http/method.rs | 13 ++++- projects/ssddOnTop/src/http/mod.rs | 4 +- projects/ssddOnTop/src/http/req_template.rs | 23 ++++----- projects/ssddOnTop/src/http/request.rs | 2 +- .../ssddOnTop/src/http/request_handler.rs | 49 +++++++------------ projects/ssddOnTop/src/http/response.rs | 29 ++++++++--- projects/ssddOnTop/src/ir/eval_ctx.rs | 7 +-- projects/ssddOnTop/src/ir/eval_http.rs | 9 ++-- projects/ssddOnTop/src/ir/eval_io.rs | 11 +++-- projects/ssddOnTop/src/ir/mod.rs | 4 +- projects/ssddOnTop/src/ir/model.rs | 17 ++----- projects/ssddOnTop/src/jit/mod.rs | 2 +- projects/ssddOnTop/src/jit/model.rs | 6 +-- projects/ssddOnTop/src/lib.rs | 12 ++--- projects/ssddOnTop/src/path.rs | 18 +++---- projects/ssddOnTop/src/request_context.rs | 10 ++-- projects/ssddOnTop/src/run/http1.rs | 2 +- projects/ssddOnTop/src/run/run.rs | 2 +- projects/ssddOnTop/src/target_runtime.rs | 24 ++++----- projects/ssddOnTop/src/value/value.rs | 2 +- 34 files changed, 259 insertions(+), 188 deletions(-) diff --git a/projects/ssddOnTop/macros-common/src/common.rs b/projects/ssddOnTop/macros-common/src/common.rs index a033d95..b5f5508 100644 --- a/projects/ssddOnTop/macros-common/src/common.rs +++ b/projects/ssddOnTop/macros-common/src/common.rs @@ -1,4 +1,3 @@ - use async_graphql::{Pos, Positioned}; use schemars::schema::SchemaObject; diff --git a/projects/ssddOnTop/macros-common/src/enum_definition.rs b/projects/ssddOnTop/macros-common/src/enum_definition.rs index 59b9641..de06522 100644 --- a/projects/ssddOnTop/macros-common/src/enum_definition.rs +++ b/projects/ssddOnTop/macros-common/src/enum_definition.rs @@ -29,7 +29,9 @@ pub fn into_enum_definition(enum_value: EnumValue, name: &str) -> TypeSystemDefi TypeSystemDefinition::Type(pos(TypeDefinition { name: pos(Name::new(name)), - kind: TypeKind::Enum(EnumType { values: enum_value_definition }), + kind: TypeKind::Enum(EnumType { + values: enum_value_definition, + }), description: enum_value.description, directives: vec![], extend: false, diff --git a/projects/ssddOnTop/macros-common/src/input_definition.rs b/projects/ssddOnTop/macros-common/src/input_definition.rs index 0d8819c..eea4bc4 100644 --- a/projects/ssddOnTop/macros-common/src/input_definition.rs +++ b/projects/ssddOnTop/macros-common/src/input_definition.rs @@ -129,13 +129,19 @@ fn determine_type_from_schema(name: String, schema: &SchemaObject) -> Type { return determine_type_from_reference(reference); } - Type { nullable: true, base: BaseType::Named(Name::new("JSON")) } + Type { + nullable: true, + base: BaseType::Named(Name::new("JSON")), + } } fn determine_type_from_reference(reference: &str) -> Type { let mut name = reference.split('/').last().unwrap().to_string(); first_char_to_upper(&mut name); - Type { nullable: true, base: BaseType::Named(Name::new(name)) } + Type { + nullable: true, + base: BaseType::Named(Name::new(name)), + } } fn determine_type_from_arr_valid(name: String, array_valid: &ArrayValidation) -> Type { @@ -157,15 +163,24 @@ fn determine_type_from_arr_valid(name: String, array_valid: &ArrayValidation) -> }, } } else { - Type { nullable: true, base: BaseType::Named(Name::new("JSON")) } + Type { + nullable: true, + base: BaseType::Named(Name::new("JSON")), + } } } fn determine_type_from_object_valid(name: String, typ: &ObjectValidation) -> Type { if !typ.properties.is_empty() { - Type { nullable: true, base: BaseType::Named(Name::new(name)) } + Type { + nullable: true, + base: BaseType::Named(Name::new(name)), + } } else { - Type { nullable: true, base: BaseType::Named(Name::new("JSON")) } + Type { + nullable: true, + base: BaseType::Named(Name::new("JSON")), + } } } diff --git a/projects/ssddOnTop/macros-common/src/lib.rs b/projects/ssddOnTop/macros-common/src/lib.rs index 0089f72..8a908eb 100644 --- a/projects/ssddOnTop/macros-common/src/lib.rs +++ b/projects/ssddOnTop/macros-common/src/lib.rs @@ -26,7 +26,9 @@ impl Default for ServiceDocumentBuilder { impl ServiceDocumentBuilder { pub fn new() -> Self { - Self { definitions: vec![] } + Self { + definitions: vec![], + } } pub fn add_directive( @@ -48,6 +50,8 @@ impl ServiceDocumentBuilder { } pub fn build(self) -> ServiceDocument { - ServiceDocument { definitions: self.definitions } + ServiceDocument { + definitions: self.definitions, + } } } diff --git a/projects/ssddOnTop/macros/src/merge_right.rs b/projects/ssddOnTop/macros/src/merge_right.rs index dce5c42..073f47b 100644 --- a/projects/ssddOnTop/macros/src/merge_right.rs +++ b/projects/ssddOnTop/macros/src/merge_right.rs @@ -20,25 +20,28 @@ fn get_attrs(attrs: &[syn::Attribute]) -> syn::Result { attr.parse_nested_meta(|meta| { if meta.path.is_ident(MERGE_RIGHT_FN) { let p: syn::Expr = meta.value()?.parse()?; - let lit = - if let syn::Expr::Lit(syn::ExprLit { lit: syn::Lit::Str(lit), .. }) = p { - let suffix = lit.suffix(); - if !suffix.is_empty() { - return Err(syn::Error::new( - lit.span(), - format!("unexpected suffix `{}` on string literal", suffix), - )); - } - lit - } else { + let lit = if let syn::Expr::Lit(syn::ExprLit { + lit: syn::Lit::Str(lit), + .. + }) = p + { + let suffix = lit.suffix(); + if !suffix.is_empty() { return Err(syn::Error::new( - p.span(), - format!( - "expected merge_right {} attribute to be a string.", - MERGE_RIGHT_FN - ), + lit.span(), + format!("unexpected suffix `{}` on string literal", suffix), )); - }; + } + lit + } else { + return Err(syn::Error::new( + p.span(), + format!( + "expected merge_right {} attribute to be a string.", + MERGE_RIGHT_FN + ), + )); + }; let expr_path: syn::ExprPath = lit.parse()?; attrs_ret.merge_right_fn = Some(expr_path); Ok(()) diff --git a/projects/ssddOnTop/src/app_ctx.rs b/projects/ssddOnTop/src/app_ctx.rs index 8cc0ba1..eecf49c 100644 --- a/projects/ssddOnTop/src/app_ctx.rs +++ b/projects/ssddOnTop/src/app_ctx.rs @@ -1,6 +1,6 @@ -use std::sync::Arc; use crate::blueprint::Blueprint; use crate::target_runtime::TargetRuntime; +use std::sync::Arc; #[derive(Clone)] pub struct AppCtx { @@ -12,4 +12,4 @@ impl AppCtx { pub fn new(runtime: TargetRuntime, blueprint: Arc) -> Self { Self { runtime, blueprint } } -} \ No newline at end of file +} diff --git a/projects/ssddOnTop/src/blueprint/operators/http.rs b/projects/ssddOnTop/src/blueprint/operators/http.rs index e9776a7..75bd295 100644 --- a/projects/ssddOnTop/src/blueprint/operators/http.rs +++ b/projects/ssddOnTop/src/blueprint/operators/http.rs @@ -41,13 +41,9 @@ fn compile_http(config_module: &config::Config, http: &config::Http) -> anyhow:: )?; let ir = if http.method == Method::GET { - IR::IO(IO::Http { - req_template, - }) + IR::IO(IO::Http { req_template }) } else { - IR::IO(IO::Http { - req_template, - }) + IR::IO(IO::Http { req_template }) }; Ok(ir) diff --git a/projects/ssddOnTop/src/cache.rs b/projects/ssddOnTop/src/cache.rs index c06b89c..1fc9004 100644 --- a/projects/ssddOnTop/src/cache.rs +++ b/projects/ssddOnTop/src/cache.rs @@ -1,13 +1,12 @@ use http_cache_reqwest::{CacheManager, HttpResponse}; use http_cache_semantics::CachePolicy; -use serde::{Deserialize, Serialize}; use moka::future::Cache; use moka::policy::EvictionPolicy; +use serde::{Deserialize, Serialize}; pub type BoxError = Box; pub type Result = std::result::Result; use std::sync::Arc; - pub struct HttpCacheManager { pub cache: Arc>, } @@ -30,7 +29,9 @@ impl HttpCacheManager { .eviction_policy(EvictionPolicy::lru()) .max_capacity(cache_size) .build(); - Self { cache: Arc::new(cache) } + Self { + cache: Arc::new(cache), + } } pub async fn clear(&self) -> Result<()> { @@ -56,7 +57,10 @@ impl CacheManager for HttpCacheManager { response: HttpResponse, policy: CachePolicy, ) -> Result { - let data = Store { response: response.clone(), policy }; + let data = Store { + response: response.clone(), + policy, + }; self.cache.insert(cache_key, data).await; self.cache.run_pending_tasks().await; Ok(response) diff --git a/projects/ssddOnTop/src/config/config.rs b/projects/ssddOnTop/src/config/config.rs index faf53c4..07b3585 100644 --- a/projects/ssddOnTop/src/config/config.rs +++ b/projects/ssddOnTop/src/config/config.rs @@ -1,16 +1,15 @@ -use macros_common::directive_definition; -use crate::directive::DirectiveCodec; -use async_graphql::Positioned; use crate::blueprint::wrapping_type; use crate::config::url_query::URLQuery; +use crate::directive::DirectiveCodec; use crate::http::method::Method; use crate::is_default; +use async_graphql::parser::types::ConstDirective; +use async_graphql::Positioned; +use macros::{CustomResolver, DirectiveDefinition, InputDefinition}; +use macros_common::directive_definition; use serde::{Deserialize, Serialize}; use std::collections::BTreeMap; use std::num::NonZeroU64; -use async_graphql::parser::types::ConstDirective; -use macros::{CustomResolver, DirectiveDefinition, InputDefinition}; - #[derive(Serialize, Deserialize, Clone, Debug)] pub struct Config { @@ -77,7 +76,14 @@ pub struct Cache { } #[derive( - Serialize, Deserialize, Clone, Debug, PartialEq, Eq, schemars::JsonSchema, macros::CustomResolver, + Serialize, + Deserialize, + Clone, + Debug, + PartialEq, + Eq, + schemars::JsonSchema, + macros::CustomResolver, )] pub enum Resolver { Http(Http), @@ -91,7 +97,17 @@ pub struct Field { pub args: BTreeMap, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, schemars::JsonSchema, DirectiveDefinition, InputDefinition)] +#[derive( + Serialize, + Deserialize, + Clone, + Debug, + PartialEq, + Eq, + schemars::JsonSchema, + DirectiveDefinition, + InputDefinition, +)] #[directive_definition(locations = "FieldDefinition")] pub struct Http { pub path: String, @@ -109,7 +125,6 @@ pub struct Arg { pub default_value: Option, } - #[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(rename_all = "lowercase")] pub enum GraphQLOperationType { diff --git a/projects/ssddOnTop/src/directive.rs b/projects/ssddOnTop/src/directive.rs index b513a47..327b4ce 100644 --- a/projects/ssddOnTop/src/directive.rs +++ b/projects/ssddOnTop/src/directive.rs @@ -1,9 +1,9 @@ +use crate::blueprint; use async_graphql::parser::types::ConstDirective; use async_graphql::{Name, Pos, Positioned}; use serde::{Deserialize, Serialize}; use serde_json::{Map, Value}; use serde_path_to_error::deserialize; -use crate::blueprint; fn pos(a: A) -> Positioned { Positioned::new(a, Pos::default()) @@ -14,12 +14,15 @@ fn to_const_directive(directive: &blueprint::Directive) -> anyhow::Result + Serialize + 'a> DirectiveCodec for A { map.insert(k, v); } Ok(deserialize(Value::Object(map))?) -/* Valid::from_iter(directive.arguments.iter(), |(k, v)| { + /* Valid::from_iter(directive.arguments.iter(), |(k, v)| { Valid::from(serde_json::to_value(&v.node).map_err(|e| { ValidationError::new(e.to_string()) .trace(format!("@{}", directive.name.node).as_str()) @@ -102,18 +105,21 @@ impl<'a, A: Deserialize<'a> + Serialize + 'a> DirectiveCodec for A { )); } - ConstDirective { name: pos(Name::new(name)), arguments } + ConstDirective { + name: pos(Name::new(name)), + arguments, + } } } #[cfg(test)] mod tests { + use crate::blueprint::Directive; + use crate::directive::{pos, to_const_directive}; use async_graphql::parser::types::ConstDirective; use async_graphql_value::Name; use pretty_assertions::assert_eq; - use crate::blueprint::Directive; - use crate::directive::{pos, to_const_directive}; #[test] fn test_to_const_directive() { diff --git a/projects/ssddOnTop/src/dl/dedupe.rs b/projects/ssddOnTop/src/dl/dedupe.rs index 07251f8..5aa6864 100644 --- a/projects/ssddOnTop/src/dl/dedupe.rs +++ b/projects/ssddOnTop/src/dl/dedupe.rs @@ -2,9 +2,9 @@ use std::collections::HashMap; use std::hash::Hash; use std::sync::{Arc, Mutex, Weak}; +use crate::ir::IoId; use futures_util::Future; use tokio::sync::broadcast; -use crate::ir::IoId; pub trait Key: Send + Sync + Eq + Hash + Clone {} impl Key for A {} @@ -49,7 +49,11 @@ enum Step { impl Dedupe { pub fn new(size: usize, persist: bool) -> Self { - Self { cache: Arc::new(Mutex::new(HashMap::new())), size, persist } + Self { + cache: Arc::new(Mutex::new(HashMap::new())), + size, + persist, + } } pub async fn dedupe<'a, Fn, Fut>(&'a self, key: &'a K, or_else: Fn) -> V @@ -300,7 +304,10 @@ mod tests { call_2: bool, } - let status = Arc::new(Mutex::new(Status { call_1: false, call_2: false })); + let status = Arc::new(Mutex::new(Status { + call_1: false, + call_2: false, + })); let cache = Arc::new(Dedupe::::new(100, true)); let cache_1 = cache.clone(); @@ -341,7 +348,13 @@ mod tests { // Task 1 should still have completed because others are dependent on it. let actual = status.lock().unwrap().deref().to_owned(); - assert_eq!(actual, Status { call_1: true, call_2: false }) + assert_eq!( + actual, + Status { + call_1: true, + call_2: false + } + ) } #[tokio::test] @@ -355,7 +368,10 @@ mod tests { call_2: bool, } - let status = Arc::new(Mutex::new(Status { call_1: false, call_2: false })); + let status = Arc::new(Mutex::new(Status { + call_1: false, + call_2: false, + })); let cache = Arc::new(Dedupe::::new(100, true)); let cache_1 = cache.clone(); @@ -394,6 +410,12 @@ mod tests { // No task should have completed let actual = status.lock().unwrap().deref().to_owned(); - assert_eq!(actual, Status { call_1: false, call_2: false }) + assert_eq!( + actual, + Status { + call_1: false, + call_2: false + } + ) } } diff --git a/projects/ssddOnTop/src/dl/mod.rs b/projects/ssddOnTop/src/dl/mod.rs index da5d458..f60f1a8 100644 --- a/projects/ssddOnTop/src/dl/mod.rs +++ b/projects/ssddOnTop/src/dl/mod.rs @@ -1 +1 @@ -pub mod dedupe; \ No newline at end of file +pub mod dedupe; diff --git a/projects/ssddOnTop/src/from_doc.rs b/projects/ssddOnTop/src/from_doc.rs index 2a3c87d..73bc0e9 100644 --- a/projects/ssddOnTop/src/from_doc.rs +++ b/projects/ssddOnTop/src/from_doc.rs @@ -1,4 +1,5 @@ use crate::config::{Arg, Cache, Config, Field, Resolver, RootSchema, Server, Type1, Upstream}; +use crate::directive::DirectiveCodec; use anyhow::Result; use async_graphql::parser::types::{ ConstDirective, FieldDefinition, InputObjectType, InputValueDefinition, InterfaceType, @@ -7,7 +8,6 @@ use async_graphql::parser::types::{ }; use async_graphql::{Name, Positioned}; use std::collections::BTreeMap; -use crate::directive::DirectiveCodec; const DEFAULT_SCHEMA_DEFINITION: &SchemaDefinition = &SchemaDefinition { extend: false, diff --git a/projects/ssddOnTop/src/http/headers.rs b/projects/ssddOnTop/src/http/headers.rs index 979797a..b71e398 100644 --- a/projects/ssddOnTop/src/http/headers.rs +++ b/projects/ssddOnTop/src/http/headers.rs @@ -28,8 +28,11 @@ impl From for HeaderMap { fn from(value: reqwest::header::HeaderMap) -> Self { let mut map = hyper::header::HeaderMap::new(); for (k, v) in value.iter() { - map.insert(hyper::header::HeaderName::from_str(k.as_str()).unwrap(),hyper::header::HeaderValue::from_str(v.to_str().unwrap()).unwrap()); + map.insert( + hyper::header::HeaderName::from_str(k.as_str()).unwrap(), + hyper::header::HeaderValue::from_str(v.to_str().unwrap()).unwrap(), + ); } Self(map) } -} \ No newline at end of file +} diff --git a/projects/ssddOnTop/src/http/method.rs b/projects/ssddOnTop/src/http/method.rs index 053a19d..95242cc 100644 --- a/projects/ssddOnTop/src/http/method.rs +++ b/projects/ssddOnTop/src/http/method.rs @@ -1,7 +1,18 @@ use serde::{Deserialize, Serialize}; use strum_macros::Display; -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash, Default, Display, schemars::JsonSchema)] +#[derive( + Clone, + Debug, + Serialize, + Deserialize, + PartialEq, + Eq, + Hash, + Default, + Display, + schemars::JsonSchema, +)] pub enum Method { #[default] GET, diff --git a/projects/ssddOnTop/src/http/mod.rs b/projects/ssddOnTop/src/http/mod.rs index 348e688..d926908 100644 --- a/projects/ssddOnTop/src/http/mod.rs +++ b/projects/ssddOnTop/src/http/mod.rs @@ -1,9 +1,9 @@ +mod headers; pub mod method; +mod query_encoder; mod req_template; pub mod request; pub mod request_handler; -mod query_encoder; pub mod response; -mod headers; pub use req_template::*; diff --git a/projects/ssddOnTop/src/http/req_template.rs b/projects/ssddOnTop/src/http/req_template.rs index e5e5d41..c1b81e2 100644 --- a/projects/ssddOnTop/src/http/req_template.rs +++ b/projects/ssddOnTop/src/http/req_template.rs @@ -5,12 +5,12 @@ use crate::ir::eval_ctx::EvalContext; use crate::ir::IoId; use crate::mustache::model::{Mustache, Segment}; use crate::path::{PathString, PathValue, ValueString}; +use crate::value::Value; use hyper::Method; use reqwest::header::HeaderValue; use std::borrow::Cow; use std::hash::{Hash, Hasher}; use url::Url; -use crate::value::Value; #[derive(Debug, Clone)] pub struct RequestTemplate { @@ -67,7 +67,7 @@ impl RequestTemplate { self.method.hash(state); - /* for (name, value) in ctx.headers().iter() { + /* for (name, value) in ctx.headers().iter() { name.hash(state); value.hash(state); }*/ @@ -92,9 +92,9 @@ impl<'a, A: PathValue> ValueStringEval { .segments() .iter() .filter_map(|segment| match segment { - Segment::Literal(text) => Some(ValueString::Value(Cow::Owned( - Value::new(serde_json::Value::String(text.to_owned())), - ))), + Segment::Literal(text) => Some(ValueString::Value(Cow::Owned(Value::new( + serde_json::Value::String(text.to_owned()), + )))), Segment::Expression(parts) => in_value.raw_value(parts), }) .next() // Return the first value that is found @@ -153,8 +153,7 @@ impl RequestTemplate { /// Checks if the template has any mustache templates or not /// Returns true if there are not templates pub fn is_const(&self) -> bool { - self.root_url.is_const() - && self.query.iter().all(|query| query.value.is_const()) + self.root_url.is_const() && self.query.iter().all(|query| query.value.is_const()) } /// Creates a Request for the given context @@ -165,14 +164,17 @@ impl RequestTemplate { // Create url let url = self.create_url(ctx)?; let method = self.method.clone(); - let req = reqwest::Request::new(crate::http::method::Method::from(method).into_reqwest(), url); + let req = reqwest::Request::new( + crate::http::method::Method::from(method).into_reqwest(), + url, + ); // req = self.set_headers(req, ctx); // req = self.set_body(req, ctx)?; Ok(req) } -/* /// Sets the headers for the request + /* /// Sets the headers for the request fn set_headers( &self, mut req: reqwest::Request, @@ -206,5 +208,4 @@ impl RequestTemplate { query_encoder: Default::default(), }) } - -} \ No newline at end of file +} diff --git a/projects/ssddOnTop/src/http/request.rs b/projects/ssddOnTop/src/http/request.rs index d927491..bc9227e 100644 --- a/projects/ssddOnTop/src/http/request.rs +++ b/projects/ssddOnTop/src/http/request.rs @@ -1,6 +1,6 @@ +use crate::http::method::Method; use http_body_util::BodyExt; use hyper::body::Incoming; -use crate::http::method::Method; pub struct Request { pub method: Method, diff --git a/projects/ssddOnTop/src/http/request_handler.rs b/projects/ssddOnTop/src/http/request_handler.rs index d4148e8..f9e7b5c 100644 --- a/projects/ssddOnTop/src/http/request_handler.rs +++ b/projects/ssddOnTop/src/http/request_handler.rs @@ -1,34 +1,26 @@ -use std::ops::Deref; -use crate::blueprint::{Blueprint, FieldHash}; -use crate::http::request::Request; -use bytes::Bytes; -use http_body_util::Full; -use std::sync::Arc; use crate::app_ctx::AppCtx; use crate::blueprint::model::{FieldName, TypeName}; +use crate::blueprint::{Blueprint, FieldHash}; use crate::http::method::Method; +use crate::http::request::Request; use crate::ir::eval_ctx::EvalContext; use crate::request_context::RequestContext; use crate::value::Value; +use bytes::Bytes; +use http_body_util::Full; +use std::ops::Deref; +use std::sync::Arc; pub async fn handle_request( req: Request, app_ctx: AppCtx, ) -> anyhow::Result>> { let resp = match req.method { - Method::GET => { - hyper::Response::new(Full::new(Bytes::from_static( - b"Hello, World!", - ))) - } - Method::POST => { - handle_gql_req(req, app_ctx).await? - } - _ => { - hyper::Response::builder() - .status(hyper::StatusCode::METHOD_NOT_ALLOWED) - .body(Full::new(Bytes::from_static(b"Method Not Allowed")))? - } + Method::GET => hyper::Response::new(Full::new(Bytes::from_static(b"Hello, World!"))), + Method::POST => handle_gql_req(req, app_ctx).await?, + _ => hyper::Response::builder() + .status(hyper::StatusCode::METHOD_NOT_ALLOWED) + .body(Full::new(Bytes::from_static(b"Method Not Allowed")))?, }; Ok(resp) } @@ -37,7 +29,6 @@ fn create_request_context(app_ctx: &AppCtx) -> RequestContext { RequestContext::from(app_ctx) } - async fn handle_gql_req( request: Request, app_ctx: AppCtx, @@ -68,16 +59,12 @@ async fn handle_gql_req( println!("hx1: {}", field.name.as_ref()); } }*/ - Ok( - hyper::Response::new(Full::new(Bytes::from_static( - b"Printed", - ))) - ) + Ok(hyper::Response::new(Full::new(Bytes::from_static( + b"Printed", + )))) } else { - Ok( - hyper::Response::new(Full::new(Bytes::from_static( - b"Only queries are suppored", - ))) - ) + Ok(hyper::Response::new(Full::new(Bytes::from_static( + b"Only queries are suppored", + )))) } -} \ No newline at end of file +} diff --git a/projects/ssddOnTop/src/http/response.rs b/projects/ssddOnTop/src/http/response.rs index af465b0..9adab68 100644 --- a/projects/ssddOnTop/src/http/response.rs +++ b/projects/ssddOnTop/src/http/response.rs @@ -1,3 +1,4 @@ +use crate::http::headers::HeaderMap; use anyhow::Result; use async_graphql_value::{ConstValue, Name}; use derive_setters::Setters; @@ -5,7 +6,6 @@ use http::StatusCode; use http_body_util::{BodyExt, Full}; use hyper::body::Bytes; use indexmap::IndexMap; -use crate::http::headers::HeaderMap; #[derive(Clone, Debug, Default, Setters)] pub struct Response { @@ -49,14 +49,22 @@ impl Response { let status = StatusCode::from_u16(resp.status().as_u16())?; let headers = HeaderMap::from(resp.headers().to_owned()); let body = resp.bytes().await?; - Ok(Response { status, headers, body }) + Ok(Response { + status, + headers, + body, + }) } pub async fn from_hyper(resp: hyper::Response>) -> Result { let status = resp.status(); let headers = HeaderMap::from(resp.headers().to_owned()); let body = resp.into_body().collect().await?.to_bytes(); - Ok(Response { status, headers, body }) + Ok(Response { + status, + headers, + body, + }) } pub fn empty() -> Self { @@ -66,7 +74,7 @@ impl Response { body: Bytes::new(), } } - pub fn to_serde_json(self) -> Result>{ + pub fn to_serde_json(self) -> Result> { if self.body.is_empty() { return Ok(Response { status: self.status, @@ -75,7 +83,11 @@ impl Response { }); } let body: serde_json::Value = serde_json::from_slice(&self.body)?; - Ok(Response { status: self.status, headers: self.headers, body }) + Ok(Response { + status: self.status, + headers: self.headers, + body, + }) } pub fn to_json(self) -> Result> { @@ -91,10 +103,13 @@ impl Response { // without benchmarking the performance impact. let body: serde_json_borrow::Value = serde_json::from_slice(&self.body)?; let body = T::from_value(body); - Ok(Response { status: self.status, headers: self.headers, body }) + Ok(Response { + status: self.status, + headers: self.headers, + body, + }) } - pub fn to_resp_string(self) -> Result> { Ok(Response:: { body: String::from_utf8(self.body.to_vec())?, diff --git a/projects/ssddOnTop/src/ir/eval_ctx.rs b/projects/ssddOnTop/src/ir/eval_ctx.rs index 3c30a6b..f811c8c 100644 --- a/projects/ssddOnTop/src/ir/eval_ctx.rs +++ b/projects/ssddOnTop/src/ir/eval_ctx.rs @@ -1,7 +1,7 @@ -use std::borrow::Cow; -use std::sync::Arc; use crate::request_context::RequestContext; use crate::value::Value; +use std::borrow::Cow; +use std::sync::Arc; #[derive(Clone)] pub struct EvalContext<'a> { @@ -9,13 +9,11 @@ pub struct EvalContext<'a> { pub request_ctx: &'a RequestContext, // graphql_ctx: &'a Ctx, - graphql_ctx_value: Option, graphql_ctx_args: Option, } - impl<'a> EvalContext<'a> { pub fn new(request_ctx: &'a RequestContext) -> Self { Self { @@ -69,4 +67,3 @@ pub fn get_path_value<'a, T: AsRef>(input: &'a Value, path: &[T]) -> Option value.map(|v| Value::new(v.clone())) } - diff --git a/projects/ssddOnTop/src/ir/eval_http.rs b/projects/ssddOnTop/src/ir/eval_http.rs index 5582769..efe481a 100644 --- a/projects/ssddOnTop/src/ir/eval_http.rs +++ b/projects/ssddOnTop/src/ir/eval_http.rs @@ -1,16 +1,15 @@ -use bytes::Bytes; -use reqwest::Request; -use crate::http::RequestTemplate; use crate::http::response::Response; +use crate::http::RequestTemplate; use crate::ir::eval_ctx::EvalContext; use crate::value::Value; +use bytes::Bytes; +use reqwest::Request; pub struct EvalHttp<'a, 'ctx> { evaluation_ctx: &'ctx EvalContext<'a>, request_template: &'a RequestTemplate, } - impl<'a, 'ctx> EvalHttp<'a, 'ctx> { pub fn new( evaluation_ctx: &'ctx EvalContext<'a>, @@ -51,4 +50,4 @@ pub async fn execute_raw_request( body: Value::new(response.body), }; Ok(resp) -} \ No newline at end of file +} diff --git a/projects/ssddOnTop/src/ir/eval_io.rs b/projects/ssddOnTop/src/ir/eval_io.rs index 80e6974..9fcf9e2 100644 --- a/projects/ssddOnTop/src/ir/eval_io.rs +++ b/projects/ssddOnTop/src/ir/eval_io.rs @@ -1,10 +1,10 @@ -use std::num::NonZeroU64; -use futures_util::FutureExt; use crate::ir::eval_ctx::EvalContext; use crate::ir::eval_http::EvalHttp; use crate::ir::IO; use crate::request_context::CacheErr; use crate::value::Value; +use futures_util::FutureExt; +use std::num::NonZeroU64; pub async fn eval_io(io: &IO, ctx: &mut EvalContext<'_>) -> anyhow::Result { let key = io.cache_key(ctx); @@ -13,7 +13,10 @@ pub async fn eval_io(io: &IO, ctx: &mut EvalContext<'_>) -> anyhow::Result) -> Result( - &'a self, - ctx: &'b mut EvalContext<'a>, - ) -> anyhow::Result { + pub async fn eval<'a, 'b>(&'a self, ctx: &'b mut EvalContext<'a>) -> anyhow::Result { match self { - IR::IO(io) => { - eval_io(io, ctx).await - } - IR::Cache(_) => todo!() + IR::IO(io) => eval_io(io, ctx).await, + IR::Cache(_) => todo!(), } } } diff --git a/projects/ssddOnTop/src/jit/mod.rs b/projects/ssddOnTop/src/jit/mod.rs index e3ce5fc..ee2d47a 100644 --- a/projects/ssddOnTop/src/jit/mod.rs +++ b/projects/ssddOnTop/src/jit/mod.rs @@ -1 +1 @@ -mod model; \ No newline at end of file +mod model; diff --git a/projects/ssddOnTop/src/jit/model.rs b/projects/ssddOnTop/src/jit/model.rs index 0230dae..d37537e 100644 --- a/projects/ssddOnTop/src/jit/model.rs +++ b/projects/ssddOnTop/src/jit/model.rs @@ -1,9 +1,7 @@ -use std::collections::HashMap; use crate::value::Value; +use std::collections::HashMap; pub struct Field { args: HashMap, } -pub struct Operation { - -} \ No newline at end of file +pub struct Operation {} diff --git a/projects/ssddOnTop/src/lib.rs b/projects/ssddOnTop/src/lib.rs index 0a4a8f9..33c1e68 100644 --- a/projects/ssddOnTop/src/lib.rs +++ b/projects/ssddOnTop/src/lib.rs @@ -1,23 +1,23 @@ +mod app_ctx; mod blueprint; +mod cache; mod config; mod directive; +mod dl; mod endpoint; mod from_doc; mod hasher; mod helpers; mod http; mod ir; +mod jit; mod json; mod mustache; mod path; +mod request_context; pub mod run; -mod value; mod target_runtime; -mod cache; -mod app_ctx; -mod request_context; -mod jit; -mod dl; +mod value; pub fn is_default(val: &T) -> bool { *val == T::default() diff --git a/projects/ssddOnTop/src/path.rs b/projects/ssddOnTop/src/path.rs index f7c71bf..f930be6 100644 --- a/projects/ssddOnTop/src/path.rs +++ b/projects/ssddOnTop/src/path.rs @@ -1,9 +1,9 @@ use std::borrow::Cow; -use serde_json::json; use crate::ir::eval_ctx::EvalContext; use crate::json::JsonLike; use crate::value::Value; +use serde_json::json; /// /// The path module provides a trait for accessing values from a JSON-like @@ -53,7 +53,7 @@ fn convert_value(value: Cow<'_, Value>) -> Option> { serde_json::Value::Array(list) => Some(json!(list).to_string().into()), _ => None, } - }, + } Cow::Borrowed(val) => { let val = val.serde(); match val { @@ -64,7 +64,7 @@ fn convert_value(value: Cow<'_, Value>) -> Option> { serde_json::Value::Array(list) => Some(json!(list).to_string().into()), _ => None, } - }, + } _ => None, } } @@ -91,13 +91,13 @@ impl<'a> EvalContext<'a> { return match path[0].as_ref() { "value" => Some(ValueString::Value(ctx.path_value(&[] as &[T])?)), "args" => Some(ValueString::Value(ctx.path_arg::<&str>(&[])?)), - /* "vars" => Some(ValueString::String(Cow::Owned( + /* "vars" => Some(ValueString::String(Cow::Owned( json!(ctx.vars()).to_string(), ))),*/ _ => { println!("none"); None - }, + } }; } @@ -105,7 +105,7 @@ impl<'a> EvalContext<'a> { .and_then(move |(head, tail)| match head.as_ref() { "value" => Some(ValueString::Value(ctx.path_value(tail)?)), "args" => Some(ValueString::Value(ctx.path_arg(tail)?)), - /* "headers" => Some(ValueString::String(Cow::Borrowed( + /* "headers" => Some(ValueString::String(Cow::Borrowed( ctx.header(tail[0].as_ref())?, ))), "vars" => Some(ValueString::String(Cow::Borrowed( @@ -115,7 +115,7 @@ impl<'a> EvalContext<'a> { _ => { println!("none1"); None - }, + } }) } } @@ -129,9 +129,7 @@ impl<'a> PathValue for EvalContext<'a> { impl<'a> PathString for EvalContext<'a> { fn path_string>(&self, path: &[T]) -> Option> { self.to_raw_value(path).and_then(|value| match value { - ValueString::String(env) => { - Some(env) - }, + ValueString::String(env) => Some(env), ValueString::Value(value) => convert_value(value), }) } diff --git a/projects/ssddOnTop/src/request_context.rs b/projects/ssddOnTop/src/request_context.rs index 44cdc9c..952b5dc 100644 --- a/projects/ssddOnTop/src/request_context.rs +++ b/projects/ssddOnTop/src/request_context.rs @@ -1,14 +1,14 @@ -use std::num::NonZeroU64; -use std::sync::{Arc, Mutex}; -use anyhow::Error; use crate::app_ctx::AppCtx; use crate::blueprint::{Server, Upstream}; +use crate::dl::dedupe::Dedupe; use crate::ir::IoId; +use crate::target_runtime::cache::InMemoryCache; use crate::target_runtime::TargetRuntime; use crate::value::Value; +use anyhow::Error; use derive_setters::Setters; -use crate::dl::dedupe::Dedupe; -use crate::target_runtime::cache::InMemoryCache; +use std::num::NonZeroU64; +use std::sync::{Arc, Mutex}; #[derive(Clone)] pub struct CacheErr(String); diff --git a/projects/ssddOnTop/src/run/http1.rs b/projects/ssddOnTop/src/run/http1.rs index acfa365..c3760f2 100644 --- a/projects/ssddOnTop/src/run/http1.rs +++ b/projects/ssddOnTop/src/run/http1.rs @@ -1,3 +1,4 @@ +use crate::app_ctx::AppCtx; use crate::blueprint::{Blueprint, Server}; use crate::http::request_handler::handle_request; use hyper::service::service_fn; @@ -5,7 +6,6 @@ use std::net::SocketAddr; use std::sync::Arc; use tokio::net::TcpListener; use tokio::sync::oneshot; -use crate::app_ctx::AppCtx; pub async fn start(app_ctx: AppCtx) -> anyhow::Result<()> { let addr = app_ctx.blueprint.server.addr(); diff --git a/projects/ssddOnTop/src/run/run.rs b/projects/ssddOnTop/src/run/run.rs index 7e6ffa7..52486e3 100644 --- a/projects/ssddOnTop/src/run/run.rs +++ b/projects/ssddOnTop/src/run/run.rs @@ -1,9 +1,9 @@ -use std::sync::Arc; use crate::app_ctx::AppCtx; use crate::blueprint::Blueprint; use crate::config::ConfigReader; use crate::run; use crate::target_runtime::TargetRuntime; +use std::sync::Arc; pub async fn run() -> anyhow::Result<()> { let config_reader = ConfigReader::init(); diff --git a/projects/ssddOnTop/src/target_runtime.rs b/projects/ssddOnTop/src/target_runtime.rs index e45faed..887625a 100644 --- a/projects/ssddOnTop/src/target_runtime.rs +++ b/projects/ssddOnTop/src/target_runtime.rs @@ -1,8 +1,8 @@ -use crate::target_runtime::http::NativeHttp; -use std::sync::Arc; use crate::blueprint::Upstream; use crate::ir::IoId; +use crate::target_runtime::http::NativeHttp; use crate::value::Value; +use std::sync::Arc; #[derive(Clone)] pub struct TargetRuntime { @@ -62,14 +62,14 @@ pub mod cache { } mod http { - use bytes::Bytes; use crate::blueprint::Upstream; use crate::cache::HttpCacheManager; + use crate::http::response::Response; + use anyhow::Result; + use bytes::Bytes; use http_cache_reqwest::{Cache, CacheMode, HttpCache, HttpCacheOptions}; use reqwest::Client; use reqwest_middleware::{ClientBuilder, ClientWithMiddleware}; - use crate::http::response::Response; - use anyhow::Result; pub struct NativeHttp { client: ClientWithMiddleware, @@ -91,11 +91,11 @@ mod http { } pub async fn execute(&self, mut request: reqwest::Request) -> Result> { tracing::info!( - "{} {} {:?}", - request.method(), - request.url(), - request.version() - ); + "{} {} {:?}", + request.method(), + request.url(), + request.version() + ); tracing::debug!("request: {:?}", request); let response = self.client.execute(request).await; tracing::debug!("response: {:?}", response); @@ -105,7 +105,7 @@ mod http { .error_for_status() .map_err(|err| err.without_url())?, ) - .await?) + .await?) } } -} \ No newline at end of file +} diff --git a/projects/ssddOnTop/src/value/value.rs b/projects/ssddOnTop/src/value/value.rs index 91cae94..3934e2d 100644 --- a/projects/ssddOnTop/src/value/value.rs +++ b/projects/ssddOnTop/src/value/value.rs @@ -1,5 +1,5 @@ -use std::fmt::{Display, Formatter}; use derive_getters::Getters; +use std::fmt::{Display, Formatter}; #[derive(Getters, Debug, Clone, PartialEq, Eq, Hash)] pub struct Value { From 92d11c4e9b18a2da28dcb34b497df80e8131340b Mon Sep 17 00:00:00 2001 From: Sandipsinh Rathod Date: Thu, 12 Sep 2024 00:19:10 -0400 Subject: [PATCH 09/21] clippy --- mock-api/src/database.rs | 6 ++ mock-api/src/lib.rs | 2 +- mock-api/src/main.rs | 2 +- projects/ssddOnTop/src/blueprint/blueprint.rs | 4 +- .../ssddOnTop/src/blueprint/definitions.rs | 12 ++-- .../ssddOnTop/src/blueprint/operators/http.rs | 9 +-- projects/ssddOnTop/src/config/config.rs | 3 +- projects/ssddOnTop/src/config/mod.rs | 1 - projects/ssddOnTop/src/config/reader.rs | 2 +- projects/ssddOnTop/src/dl/dedupe.rs | 1 - projects/ssddOnTop/src/http/headers.rs | 6 +- projects/ssddOnTop/src/http/query_encoder.rs | 1 - projects/ssddOnTop/src/http/req_template.rs | 1 - .../ssddOnTop/src/http/request_handler.rs | 4 +- projects/ssddOnTop/src/http/response.rs | 1 - projects/ssddOnTop/src/ir/eval_ctx.rs | 5 +- projects/ssddOnTop/src/ir/eval_http.rs | 3 +- projects/ssddOnTop/src/ir/eval_io.rs | 1 - projects/ssddOnTop/src/ir/mod.rs | 1 - projects/ssddOnTop/src/mustache/parse.rs | 1 - projects/ssddOnTop/src/request_context.rs | 1 - projects/ssddOnTop/src/run/http1.rs | 4 -- projects/ssddOnTop/src/run/run.rs | 2 +- projects/ssddOnTop/src/target_runtime.rs | 6 +- src/benchmarks.rs | 70 +++++++++---------- src/command.rs | 2 +- src/graphql_tests.rs | 4 +- 27 files changed, 70 insertions(+), 85 deletions(-) diff --git a/mock-api/src/database.rs b/mock-api/src/database.rs index 6d66a3c..112a5d4 100644 --- a/mock-api/src/database.rs +++ b/mock-api/src/database.rs @@ -24,6 +24,12 @@ fn geo_add_fractional_part(val: &mut f64) { } } +impl Default for Database { + fn default() -> Self { + Self::new() + } +} + impl Database { /// Initialize the database with random data pub fn new() -> Self { diff --git a/mock-api/src/lib.rs b/mock-api/src/lib.rs index 2d06cb6..f2cbc83 100644 --- a/mock-api/src/lib.rs +++ b/mock-api/src/lib.rs @@ -14,7 +14,7 @@ pub struct AppState { impl Default for AppState { fn default() -> Self { let db = Database::new(); - let _ = db.reset().unwrap(); + db.reset().unwrap(); Self { db } } } diff --git a/mock-api/src/main.rs b/mock-api/src/main.rs index e213ca7..e53a1d5 100644 --- a/mock-api/src/main.rs +++ b/mock-api/src/main.rs @@ -59,7 +59,7 @@ async fn main() { .layer(axum::middleware::from_fn( // This middleware is responsible to apply the delay functionality move |request: Request, next: Next| { - let delay = delay.clone(); + let delay = delay; async move { let response = next.run(request).await; tokio::time::sleep(delay).await; diff --git a/projects/ssddOnTop/src/blueprint/blueprint.rs b/projects/ssddOnTop/src/blueprint/blueprint.rs index 4a78955..963dc6d 100644 --- a/projects/ssddOnTop/src/blueprint/blueprint.rs +++ b/projects/ssddOnTop/src/blueprint/blueprint.rs @@ -166,8 +166,8 @@ fn populate_nested_field( Definition::InputObject(_) => None, }); // println!("resolver for: {} is {:?}", field_name.0, x); - let x = x.and_then(|x| x.resolver.clone()); - x + + x.and_then(|x| x.resolver.clone()) }, args: field .args diff --git a/projects/ssddOnTop/src/blueprint/definitions.rs b/projects/ssddOnTop/src/blueprint/definitions.rs index b38f231..6584fa1 100644 --- a/projects/ssddOnTop/src/blueprint/definitions.rs +++ b/projects/ssddOnTop/src/blueprint/definitions.rs @@ -10,10 +10,10 @@ pub fn to_definitions(config: &Config) -> anyhow::Result> { let mut definitions = vec![]; for (ty_name, ty) in config.types.iter() { let def = - to_object_type_definition(ty_name, ty, config).and_then( + to_object_type_definition(ty_name, ty, config).map( |definition| match definition { Definition::Object(_) => { - Ok(definition) + definition /*if config.input_types().contains(ty_name) { to_input_object_type_definition(object_type_definition) } else if config.interface_types().contains(ty_name) { @@ -22,7 +22,7 @@ pub fn to_definitions(config: &Config) -> anyhow::Result> { Ok(definition) }*/ } - _ => Ok(definition), + _ => definition, }, )?; definitions.push(def); @@ -104,11 +104,11 @@ fn update_args( .args .iter() .map(|(name, arg)| { - let arg = InputFieldDefinition { + + InputFieldDefinition { name: name.clone(), of_type: arg.type_of.clone(), - }; - arg + } }) .collect::>(); diff --git a/projects/ssddOnTop/src/blueprint/operators/http.rs b/projects/ssddOnTop/src/blueprint/operators/http.rs index 75bd295..a174140 100644 --- a/projects/ssddOnTop/src/blueprint/operators/http.rs +++ b/projects/ssddOnTop/src/blueprint/operators/http.rs @@ -5,18 +5,15 @@ use crate::endpoint::Endpoint; use crate::http::method::Method; use crate::http::RequestTemplate; use crate::ir::{IO, IR}; -use crate::mustache::model::Mustache; fn compile_http(config_module: &config::Config, http: &config::Http) -> anyhow::Result { let mut base_url = String::new(); if let Some(base) = http.base_url.clone() { base_url = base; + } else if let Some(base) = config_module.upstream.base_url.clone() { + base_url = base; } else { - if let Some(base) = config_module.upstream.base_url.clone() { - base_url = base; - } else { - return Err(anyhow::anyhow!("No base URL defined")); - } + return Err(anyhow::anyhow!("No base URL defined")); } let mut base_url = base_url.trim_end_matches('/').to_owned(); base_url.push_str(http.path.clone().as_str()); diff --git a/projects/ssddOnTop/src/config/config.rs b/projects/ssddOnTop/src/config/config.rs index 07b3585..48ce7f5 100644 --- a/projects/ssddOnTop/src/config/config.rs +++ b/projects/ssddOnTop/src/config/config.rs @@ -5,8 +5,7 @@ use crate::http::method::Method; use crate::is_default; use async_graphql::parser::types::ConstDirective; use async_graphql::Positioned; -use macros::{CustomResolver, DirectiveDefinition, InputDefinition}; -use macros_common::directive_definition; +use macros::{DirectiveDefinition, InputDefinition}; use serde::{Deserialize, Serialize}; use std::collections::BTreeMap; use std::num::NonZeroU64; diff --git a/projects/ssddOnTop/src/config/mod.rs b/projects/ssddOnTop/src/config/mod.rs index 40505ac..9d63f4b 100644 --- a/projects/ssddOnTop/src/config/mod.rs +++ b/projects/ssddOnTop/src/config/mod.rs @@ -6,4 +6,3 @@ mod url_query; pub use config::*; pub use kv::*; pub use reader::*; -pub use url_query::*; diff --git a/projects/ssddOnTop/src/config/reader.rs b/projects/ssddOnTop/src/config/reader.rs index 34eb5aa..e1fb510 100644 --- a/projects/ssddOnTop/src/config/reader.rs +++ b/projects/ssddOnTop/src/config/reader.rs @@ -12,7 +12,7 @@ impl ConfigReader { pub fn read>(&self, path: T) -> anyhow::Result { let sdl = std::fs::read_to_string(path)?; let doc = async_graphql::parser::parse_schema(sdl)?; - Ok(crate::from_doc::from_doc(doc)?) + crate::from_doc::from_doc(doc) } } diff --git a/projects/ssddOnTop/src/dl/dedupe.rs b/projects/ssddOnTop/src/dl/dedupe.rs index 5aa6864..959b6f2 100644 --- a/projects/ssddOnTop/src/dl/dedupe.rs +++ b/projects/ssddOnTop/src/dl/dedupe.rs @@ -2,7 +2,6 @@ use std::collections::HashMap; use std::hash::Hash; use std::sync::{Arc, Mutex, Weak}; -use crate::ir::IoId; use futures_util::Future; use tokio::sync::broadcast; diff --git a/projects/ssddOnTop/src/http/headers.rs b/projects/ssddOnTop/src/http/headers.rs index b71e398..c563141 100644 --- a/projects/ssddOnTop/src/http/headers.rs +++ b/projects/ssddOnTop/src/http/headers.rs @@ -3,9 +3,9 @@ use std::str::FromStr; #[derive(Clone, Debug, Default)] pub struct HeaderMap(hyper::header::HeaderMap); -impl Into for HeaderMap { - fn into(self) -> hyper::header::HeaderMap { - self.0 +impl From for hyper::header::HeaderMap { + fn from(val: HeaderMap) -> Self { + val.0 } } diff --git a/projects/ssddOnTop/src/http/query_encoder.rs b/projects/ssddOnTop/src/http/query_encoder.rs index a92d14a..0ee47e5 100644 --- a/projects/ssddOnTop/src/http/query_encoder.rs +++ b/projects/ssddOnTop/src/http/query_encoder.rs @@ -1,5 +1,4 @@ use crate::path::ValueString; -use crate::value::Value; /// Defines different strategies for encoding query parameters. #[derive(Default, Debug, Clone)] diff --git a/projects/ssddOnTop/src/http/req_template.rs b/projects/ssddOnTop/src/http/req_template.rs index c1b81e2..8cb1905 100644 --- a/projects/ssddOnTop/src/http/req_template.rs +++ b/projects/ssddOnTop/src/http/req_template.rs @@ -7,7 +7,6 @@ use crate::mustache::model::{Mustache, Segment}; use crate::path::{PathString, PathValue, ValueString}; use crate::value::Value; use hyper::Method; -use reqwest::header::HeaderValue; use std::borrow::Cow; use std::hash::{Hash, Hasher}; use url::Url; diff --git a/projects/ssddOnTop/src/http/request_handler.rs b/projects/ssddOnTop/src/http/request_handler.rs index f9e7b5c..09ccc5f 100644 --- a/projects/ssddOnTop/src/http/request_handler.rs +++ b/projects/ssddOnTop/src/http/request_handler.rs @@ -1,6 +1,6 @@ use crate::app_ctx::AppCtx; use crate::blueprint::model::{FieldName, TypeName}; -use crate::blueprint::{Blueprint, FieldHash}; +use crate::blueprint::FieldHash; use crate::http::method::Method; use crate::http::request::Request; use crate::ir::eval_ctx::EvalContext; @@ -8,8 +8,6 @@ use crate::request_context::RequestContext; use crate::value::Value; use bytes::Bytes; use http_body_util::Full; -use std::ops::Deref; -use std::sync::Arc; pub async fn handle_request( req: Request, diff --git a/projects/ssddOnTop/src/http/response.rs b/projects/ssddOnTop/src/http/response.rs index 9adab68..776894e 100644 --- a/projects/ssddOnTop/src/http/response.rs +++ b/projects/ssddOnTop/src/http/response.rs @@ -5,7 +5,6 @@ use derive_setters::Setters; use http::StatusCode; use http_body_util::{BodyExt, Full}; use hyper::body::Bytes; -use indexmap::IndexMap; #[derive(Clone, Debug, Default, Setters)] pub struct Response { diff --git a/projects/ssddOnTop/src/ir/eval_ctx.rs b/projects/ssddOnTop/src/ir/eval_ctx.rs index f811c8c..7339ae4 100644 --- a/projects/ssddOnTop/src/ir/eval_ctx.rs +++ b/projects/ssddOnTop/src/ir/eval_ctx.rs @@ -1,7 +1,6 @@ use crate::request_context::RequestContext; use crate::value::Value; use std::borrow::Cow; -use std::sync::Arc; #[derive(Clone)] pub struct EvalContext<'a> { @@ -42,7 +41,7 @@ impl<'a> EvalContext<'a> { pub fn path_value>(&self, path: &[T]) -> Option> { // TODO: add unit tests for this if let Some(value) = self.graphql_ctx_value.as_ref() { - get_path_value(value, path).map(|a| Cow::Owned(a)) + get_path_value(value, path).map(Cow::Owned) } else { Some(Cow::Owned(Value::new(serde_json::Value::Null))) // get_path_value(self.graphql_ctx.value()?, path).map(Cow::Borrowed) @@ -50,7 +49,7 @@ impl<'a> EvalContext<'a> { } } -pub fn get_path_value<'a, T: AsRef>(input: &'a Value, path: &[T]) -> Option { +pub fn get_path_value>(input: &Value, path: &[T]) -> Option { let mut value = Some(input.serde()); for name in path { match value { diff --git a/projects/ssddOnTop/src/ir/eval_http.rs b/projects/ssddOnTop/src/ir/eval_http.rs index efe481a..9e6a89e 100644 --- a/projects/ssddOnTop/src/ir/eval_http.rs +++ b/projects/ssddOnTop/src/ir/eval_http.rs @@ -2,7 +2,6 @@ use crate::http::response::Response; use crate::http::RequestTemplate; use crate::ir::eval_ctx::EvalContext; use crate::value::Value; -use bytes::Bytes; use reqwest::Request; pub struct EvalHttp<'a, 'ctx> { @@ -21,7 +20,7 @@ impl<'a, 'ctx> EvalHttp<'a, 'ctx> { } } pub fn init_request(&self) -> anyhow::Result { - Ok(self.request_template.to_request(self.evaluation_ctx)?) + self.request_template.to_request(self.evaluation_ctx) } pub async fn execute(&self, req: Request) -> anyhow::Result> { diff --git a/projects/ssddOnTop/src/ir/eval_io.rs b/projects/ssddOnTop/src/ir/eval_io.rs index 9fcf9e2..b0b5424 100644 --- a/projects/ssddOnTop/src/ir/eval_io.rs +++ b/projects/ssddOnTop/src/ir/eval_io.rs @@ -3,7 +3,6 @@ use crate::ir::eval_http::EvalHttp; use crate::ir::IO; use crate::request_context::CacheErr; use crate::value::Value; -use futures_util::FutureExt; use std::num::NonZeroU64; pub async fn eval_io(io: &IO, ctx: &mut EvalContext<'_>) -> anyhow::Result { diff --git a/projects/ssddOnTop/src/ir/mod.rs b/projects/ssddOnTop/src/ir/mod.rs index cd5cf87..13e5987 100644 --- a/projects/ssddOnTop/src/ir/mod.rs +++ b/projects/ssddOnTop/src/ir/mod.rs @@ -4,5 +4,4 @@ mod eval_http; mod eval_io; mod model; -pub use discriminator::*; pub use model::*; diff --git a/projects/ssddOnTop/src/mustache/parse.rs b/projects/ssddOnTop/src/mustache/parse.rs index d6982c0..7eadda3 100644 --- a/projects/ssddOnTop/src/mustache/parse.rs +++ b/projects/ssddOnTop/src/mustache/parse.rs @@ -1,4 +1,3 @@ -use super::*; use crate::mustache::model::{Mustache, Segment}; use nom::branch::alt; use nom::bytes::complete::{tag, take_until}; diff --git a/projects/ssddOnTop/src/request_context.rs b/projects/ssddOnTop/src/request_context.rs index 952b5dc..8b24247 100644 --- a/projects/ssddOnTop/src/request_context.rs +++ b/projects/ssddOnTop/src/request_context.rs @@ -1,6 +1,5 @@ use crate::app_ctx::AppCtx; use crate::blueprint::{Server, Upstream}; -use crate::dl::dedupe::Dedupe; use crate::ir::IoId; use crate::target_runtime::cache::InMemoryCache; use crate::target_runtime::TargetRuntime; diff --git a/projects/ssddOnTop/src/run/http1.rs b/projects/ssddOnTop/src/run/http1.rs index c3760f2..6959b9f 100644 --- a/projects/ssddOnTop/src/run/http1.rs +++ b/projects/ssddOnTop/src/run/http1.rs @@ -1,11 +1,7 @@ use crate::app_ctx::AppCtx; -use crate::blueprint::{Blueprint, Server}; use crate::http::request_handler::handle_request; use hyper::service::service_fn; -use std::net::SocketAddr; -use std::sync::Arc; use tokio::net::TcpListener; -use tokio::sync::oneshot; pub async fn start(app_ctx: AppCtx) -> anyhow::Result<()> { let addr = app_ctx.blueprint.server.addr(); diff --git a/projects/ssddOnTop/src/run/run.rs b/projects/ssddOnTop/src/run/run.rs index 52486e3..e76d58a 100644 --- a/projects/ssddOnTop/src/run/run.rs +++ b/projects/ssddOnTop/src/run/run.rs @@ -7,7 +7,7 @@ use std::sync::Arc; pub async fn run() -> anyhow::Result<()> { let config_reader = ConfigReader::init(); - let path = std::env::args().into_iter().collect::>(); + let path = std::env::args().collect::>(); let path = path.get(1).cloned().unwrap_or({ let root = env!("CARGO_MANIFEST_DIR"); format!("{}/schema/schema.graphql", root) diff --git a/projects/ssddOnTop/src/target_runtime.rs b/projects/ssddOnTop/src/target_runtime.rs index 887625a..b6c6ea7 100644 --- a/projects/ssddOnTop/src/target_runtime.rs +++ b/projects/ssddOnTop/src/target_runtime.rs @@ -89,7 +89,7 @@ mod http { client: client.build(), } } - pub async fn execute(&self, mut request: reqwest::Request) -> Result> { + pub async fn execute(&self, request: reqwest::Request) -> Result> { tracing::info!( "{} {} {:?}", request.method(), @@ -100,12 +100,12 @@ mod http { let response = self.client.execute(request).await; tracing::debug!("response: {:?}", response); - Ok(Response::from_reqwest( + Response::from_reqwest( response? .error_for_status() .map_err(|err| err.without_url())?, ) - .await?) + .await } } } diff --git a/src/benchmarks.rs b/src/benchmarks.rs index 2e96a83..5cfe5a1 100644 --- a/src/benchmarks.rs +++ b/src/benchmarks.rs @@ -127,7 +127,7 @@ pub async fn run_benchmarks(output_path: &Path) -> Result<()> { stats.insert(bench_name.to_string(), single_stats); } - let json_path = output_path.join(format!("stats.json")); + let json_path = output_path.join("stats.json"); let mut file = fs::OpenOptions::new() .write(true) @@ -139,7 +139,7 @@ pub async fn run_benchmarks(output_path: &Path) -> Result<()> { file.write_all(serde_json::to_string_pretty(&stats)?.as_bytes()) .await?; - let score = output_path.join(format!("score.out")); + let score = output_path.join("score.out"); let mut file = fs::OpenOptions::new() .write(true) @@ -180,6 +180,39 @@ fn parse_u64(data: &str, re: Regex) -> anyhow::Result { } } +fn extract_errors(data: &str) -> (u64, u64, u64, u64) { + let re = Regex::new( + r"Socket\s+errors:\s+connect\s+(\d+),\s+read\s+(\d+).\s+write\s+(\d+).\s+timeout\s+(\d+)", + ) + .unwrap(); + if let Some(caps) = re.captures(data) { + ( + caps[1].parse().unwrap_or(0), + caps[2].parse().unwrap_or(0), + caps[3].parse().unwrap_or(0), + caps[4].parse().unwrap_or(0), + ) + } else { + (0, 0, 0, 0) + } +} + +fn check_errors(single_stats: &Stats) -> anyhow::Result<()> { + if single_stats.read_errors > 0 { + bail!("Execution failed because read_errors exist") + } + + if single_stats.write_errors > 0 { + bail!("Execution failed because write_errors exist") + } + + if single_stats.connect_errors > 0 { + bail!("Execution failed because connect_errors exist") + } + + Ok(()) +} + #[cfg(test)] mod tests { mod stats { @@ -345,36 +378,3 @@ mod tests { } } } - -fn extract_errors(data: &str) -> (u64, u64, u64, u64) { - let re = Regex::new( - r"Socket\s+errors:\s+connect\s+(\d+),\s+read\s+(\d+).\s+write\s+(\d+).\s+timeout\s+(\d+)", - ) - .unwrap(); - if let Some(caps) = re.captures(data) { - ( - caps[1].parse().unwrap_or(0), - caps[2].parse().unwrap_or(0), - caps[3].parse().unwrap_or(0), - caps[4].parse().unwrap_or(0), - ) - } else { - (0, 0, 0, 0) - } -} - -fn check_errors(single_stats: &Stats) -> anyhow::Result<()> { - if single_stats.read_errors > 0 { - bail!("Execution failed because read_errors exist") - } - - if single_stats.write_errors > 0 { - bail!("Execution failed because write_errors exist") - } - - if single_stats.connect_errors > 0 { - bail!("Execution failed because connect_errors exist") - } - - Ok(()) -} diff --git a/src/command.rs b/src/command.rs index 37dddbc..e92df7f 100644 --- a/src/command.rs +++ b/src/command.rs @@ -47,7 +47,7 @@ impl Command { let mut command = tokio::process::Command::new(cmd_path); - command.current_dir(&cmd_path.parent().unwrap_or(cmd_path)); + command.current_dir(cmd_path.parent().unwrap_or(cmd_path)); Ok(Self { command }) } diff --git a/src/graphql_tests.rs b/src/graphql_tests.rs index 6729022..8ebcb9c 100644 --- a/src/graphql_tests.rs +++ b/src/graphql_tests.rs @@ -41,9 +41,9 @@ pub async fn run_graphql_tests() -> Result<()> { MOCK_API_CLIENT.request(Method::POST, "reset").await?; for test in tests { - let actual = TESTED_GRAPHQL_CLIENT.request(&test).await?; + let actual = TESTED_GRAPHQL_CLIENT.request(test).await?; - let expected = REFERENCE_GRAPHQL_CLIENT.request(&test).await?; + let expected = REFERENCE_GRAPHQL_CLIENT.request(test).await?; let differ = DiffLogger::new(); From 32702425ad657445b390bc2092b40f5051c8f8a4 Mon Sep 17 00:00:00 2001 From: Sandipsinh Rathod Date: Thu, 12 Sep 2024 00:21:00 -0400 Subject: [PATCH 10/21] revert changes in non project files --- src/benchmarks.rs | 70 +++++++++++++++++++-------------------- src/bin/generate-mocks.rs | 7 ++-- src/command.rs | 2 +- src/graphql_tests.rs | 4 +-- 4 files changed, 40 insertions(+), 43 deletions(-) diff --git a/src/benchmarks.rs b/src/benchmarks.rs index 5cfe5a1..2e96a83 100644 --- a/src/benchmarks.rs +++ b/src/benchmarks.rs @@ -127,7 +127,7 @@ pub async fn run_benchmarks(output_path: &Path) -> Result<()> { stats.insert(bench_name.to_string(), single_stats); } - let json_path = output_path.join("stats.json"); + let json_path = output_path.join(format!("stats.json")); let mut file = fs::OpenOptions::new() .write(true) @@ -139,7 +139,7 @@ pub async fn run_benchmarks(output_path: &Path) -> Result<()> { file.write_all(serde_json::to_string_pretty(&stats)?.as_bytes()) .await?; - let score = output_path.join("score.out"); + let score = output_path.join(format!("score.out")); let mut file = fs::OpenOptions::new() .write(true) @@ -180,39 +180,6 @@ fn parse_u64(data: &str, re: Regex) -> anyhow::Result { } } -fn extract_errors(data: &str) -> (u64, u64, u64, u64) { - let re = Regex::new( - r"Socket\s+errors:\s+connect\s+(\d+),\s+read\s+(\d+).\s+write\s+(\d+).\s+timeout\s+(\d+)", - ) - .unwrap(); - if let Some(caps) = re.captures(data) { - ( - caps[1].parse().unwrap_or(0), - caps[2].parse().unwrap_or(0), - caps[3].parse().unwrap_or(0), - caps[4].parse().unwrap_or(0), - ) - } else { - (0, 0, 0, 0) - } -} - -fn check_errors(single_stats: &Stats) -> anyhow::Result<()> { - if single_stats.read_errors > 0 { - bail!("Execution failed because read_errors exist") - } - - if single_stats.write_errors > 0 { - bail!("Execution failed because write_errors exist") - } - - if single_stats.connect_errors > 0 { - bail!("Execution failed because connect_errors exist") - } - - Ok(()) -} - #[cfg(test)] mod tests { mod stats { @@ -378,3 +345,36 @@ mod tests { } } } + +fn extract_errors(data: &str) -> (u64, u64, u64, u64) { + let re = Regex::new( + r"Socket\s+errors:\s+connect\s+(\d+),\s+read\s+(\d+).\s+write\s+(\d+).\s+timeout\s+(\d+)", + ) + .unwrap(); + if let Some(caps) = re.captures(data) { + ( + caps[1].parse().unwrap_or(0), + caps[2].parse().unwrap_or(0), + caps[3].parse().unwrap_or(0), + caps[4].parse().unwrap_or(0), + ) + } else { + (0, 0, 0, 0) + } +} + +fn check_errors(single_stats: &Stats) -> anyhow::Result<()> { + if single_stats.read_errors > 0 { + bail!("Execution failed because read_errors exist") + } + + if single_stats.write_errors > 0 { + bail!("Execution failed because write_errors exist") + } + + if single_stats.connect_errors > 0 { + bail!("Execution failed because connect_errors exist") + } + + Ok(()) +} diff --git a/src/bin/generate-mocks.rs b/src/bin/generate-mocks.rs index 7909dd2..b7399f7 100644 --- a/src/bin/generate-mocks.rs +++ b/src/bin/generate-mocks.rs @@ -1,7 +1,4 @@ -use std::{ - fs, - sync::{Arc, Mutex}, -}; +use std::{fs, sync::{Arc, Mutex}}; use anyhow::Result; use mock_json::{mock, registry, MockFn}; @@ -77,7 +74,7 @@ fn main() -> Result<()> { generate(&template, 1)?; ordered_number_mock.reset(); - generate(&template, 2)?; + generate(&template, 2)?; ordered_number_mock.reset(); generate(&template, 3)?; diff --git a/src/command.rs b/src/command.rs index e92df7f..37dddbc 100644 --- a/src/command.rs +++ b/src/command.rs @@ -47,7 +47,7 @@ impl Command { let mut command = tokio::process::Command::new(cmd_path); - command.current_dir(cmd_path.parent().unwrap_or(cmd_path)); + command.current_dir(&cmd_path.parent().unwrap_or(cmd_path)); Ok(Self { command }) } diff --git a/src/graphql_tests.rs b/src/graphql_tests.rs index 8ebcb9c..6729022 100644 --- a/src/graphql_tests.rs +++ b/src/graphql_tests.rs @@ -41,9 +41,9 @@ pub async fn run_graphql_tests() -> Result<()> { MOCK_API_CLIENT.request(Method::POST, "reset").await?; for test in tests { - let actual = TESTED_GRAPHQL_CLIENT.request(test).await?; + let actual = TESTED_GRAPHQL_CLIENT.request(&test).await?; - let expected = REFERENCE_GRAPHQL_CLIENT.request(test).await?; + let expected = REFERENCE_GRAPHQL_CLIENT.request(&test).await?; let differ = DiffLogger::new(); From bedc4f0ef0d7cb8bc7d3cd2c519ecd139cffb0bf Mon Sep 17 00:00:00 2001 From: Sandipsinh Rathod Date: Thu, 12 Sep 2024 10:44:43 -0400 Subject: [PATCH 11/21] v0.1 --- Cargo.lock | 12 + projects/ssddOnTop/Cargo.toml | 1 + projects/ssddOnTop/src/blueprint/blueprint.rs | 6 + .../ssddOnTop/src/http/request_handler.rs | 34 +-- projects/ssddOnTop/src/ir/eval_ctx.rs | 14 +- projects/ssddOnTop/src/jit/mod.rs | 2 +- projects/ssddOnTop/src/jit/model.rs | 289 +++++++++++++++++- projects/ssddOnTop/src/value/value.rs | 17 +- 8 files changed, 343 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index baa0dc7..a86934b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -288,6 +288,17 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "async-recursion" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b43422f69d8ff38f95f1b2bb76517c91589a924d1559a0e935d7c8ce0274c11" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "async-signal" version = "0.2.10" @@ -2924,6 +2935,7 @@ dependencies = [ "anyhow", "async-graphql", "async-graphql-value", + "async-recursion", "async-trait", "bytes", "convert_case 0.6.0", diff --git a/projects/ssddOnTop/Cargo.toml b/projects/ssddOnTop/Cargo.toml index 1e7bf38..8188147 100644 --- a/projects/ssddOnTop/Cargo.toml +++ b/projects/ssddOnTop/Cargo.toml @@ -48,6 +48,7 @@ futures-util = "0.3.30" http = "1.1.0" url = "2.5.2" schemars = {version = "0.8.17", features = ["derive"]} +async-recursion = "1.1.1" [dev-dependencies] http-cache = "0.18.0" diff --git a/projects/ssddOnTop/src/blueprint/blueprint.rs b/projects/ssddOnTop/src/blueprint/blueprint.rs index 963dc6d..e49d5e0 100644 --- a/projects/ssddOnTop/src/blueprint/blueprint.rs +++ b/projects/ssddOnTop/src/blueprint/blueprint.rs @@ -14,6 +14,12 @@ pub struct FieldHash { pub id: TypeName, } +impl FieldHash { + pub fn new(name: FieldName, id: TypeName) -> Self { + Self { name, id } + } +} + #[derive(Debug)] pub struct Blueprint { pub fields: HashMap, diff --git a/projects/ssddOnTop/src/http/request_handler.rs b/projects/ssddOnTop/src/http/request_handler.rs index 09ccc5f..5ea3ea5 100644 --- a/projects/ssddOnTop/src/http/request_handler.rs +++ b/projects/ssddOnTop/src/http/request_handler.rs @@ -8,6 +8,7 @@ use crate::request_context::RequestContext; use crate::value::Value; use bytes::Bytes; use http_body_util::Full; +use crate::jit::model::PathFinder; pub async fn handle_request( req: Request, @@ -34,31 +35,14 @@ async fn handle_gql_req( let gql_req: async_graphql::Request = serde_json::from_slice(&request.body)?; let doc = async_graphql::parser::parse_query(&gql_req.query)?; let req_ctx = create_request_context(&app_ctx); - if let Some(query) = app_ctx.blueprint.schema.query.as_ref() { - let mut eval_ctx = EvalContext::new(&req_ctx); - let x = app_ctx.blueprint.fields.get(&FieldHash { - name: FieldName("post".to_string()), - id: TypeName(query.to_string()), - }); - let x = x.as_ref().unwrap().ir.as_ref().unwrap(); - let mut map = serde_json::Map::new(); - let key = "id".to_string(); - let val = serde_json::Value::Number(serde_json::Number::from(1)); - map.insert(key, val); - eval_ctx = eval_ctx.with_args(Value::new(serde_json::Value::Object(map))); - - let x = x.eval(&mut eval_ctx).await?; - println!("{}", x); - /*for (_,field) in app_ctx.blueprint.fields.iter() { - if let Some(ir) = field.ir.as_ref() { - println!("hx: {}", field.name.as_ref()); - println!("{}", ir.eval(&mut eval_ctx).await?); - }else { - println!("hx1: {}", field.name.as_ref()); - } - }*/ - Ok(hyper::Response::new(Full::new(Bytes::from_static( - b"Printed", + if let Some(_) = app_ctx.blueprint.schema.query.as_ref() { + let eval_ctx = EvalContext::new(&req_ctx); + let path_finder = PathFinder::new(doc, &app_ctx.blueprint); + let fields = path_finder.exec().await; + let resolved = fields.resolve(eval_ctx).await?; + let finalized = resolved.finalize(); + Ok(hyper::Response::new(Full::new(Bytes::from( + finalized.to_string(), )))) } else { Ok(hyper::Response::new(Full::new(Bytes::from_static( diff --git a/projects/ssddOnTop/src/ir/eval_ctx.rs b/projects/ssddOnTop/src/ir/eval_ctx.rs index 7339ae4..9a20b79 100644 --- a/projects/ssddOnTop/src/ir/eval_ctx.rs +++ b/projects/ssddOnTop/src/ir/eval_ctx.rs @@ -8,7 +8,7 @@ pub struct EvalContext<'a> { pub request_ctx: &'a RequestContext, // graphql_ctx: &'a Ctx, - graphql_ctx_value: Option, + pub graphql_ctx_value: Option, graphql_ctx_args: Option, } @@ -33,6 +33,18 @@ impl<'a> EvalContext<'a> { ..self } } + pub fn clear_args(self) -> Self { + Self { + graphql_ctx_args: None, + ..self + } + } + pub fn clear_value(self) -> Self { + Self { + graphql_ctx_value: None, + ..self + } + } pub fn path_arg>(&self, path: &[T]) -> Option> { let args = self.graphql_ctx_args.as_ref()?; get_path_value(args, path).map(|a| Cow::Owned(a.clone())) diff --git a/projects/ssddOnTop/src/jit/mod.rs b/projects/ssddOnTop/src/jit/mod.rs index ee2d47a..65880be 100644 --- a/projects/ssddOnTop/src/jit/mod.rs +++ b/projects/ssddOnTop/src/jit/mod.rs @@ -1 +1 @@ -mod model; +pub mod model; diff --git a/projects/ssddOnTop/src/jit/model.rs b/projects/ssddOnTop/src/jit/model.rs index d37537e..e6dac1d 100644 --- a/projects/ssddOnTop/src/jit/model.rs +++ b/projects/ssddOnTop/src/jit/model.rs @@ -1,7 +1,290 @@ +use std::borrow::Cow; +use std::fmt::{Debug, Formatter}; +use std::future::Future; +use std::pin::Pin; +use crate::blueprint::model::{FieldName, TypeName}; +use crate::blueprint::{Blueprint, FieldHash}; +use crate::ir::IR; use crate::value::Value; -use std::collections::HashMap; +use async_graphql::parser::types::{DocumentOperations, ExecutableDocument, OperationType, Selection, SelectionSet}; +use async_graphql::Positioned; +use serde_json::Map; +use crate::ir::eval_ctx::EvalContext; +pub struct PathFinder<'a> { + doc: ExecutableDocument, + blueprint: &'a Blueprint, +} +#[derive(Debug)] +pub struct Fields { + fields: Vec, +} + +// #[derive(Debug)] +// TODO: give it a lifetime +// it won't make much difference.. +// but anyways pub struct Field { - args: HashMap, + ir: Option, + pub name: String, + pub type_of: crate::blueprint::wrapping_type::Type, + nested: Vec, + pub args: Option, + pub resolved: Option, +} + +pub struct Field1<'a> { + value: serde_json_borrow::Value<'a>, + pub name: &'a str, + pub type_of: crate::blueprint::wrapping_type::Type, + nexted: Vec>, + pub args: Option, +} + +impl Debug for Field { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + let mut debug_struct = f.debug_struct("Field"); + debug_struct.field("name", &self.name); + if self.ir.is_some() { + debug_struct.field("ir", &"Some(..)"); + } + debug_struct.field("type_of", &self.type_of); + if self.args.is_some() { + debug_struct.field("args", &self.args); + } + if self.resolved.is_some() { + debug_struct.field("resolved", &self.resolved.as_ref().map(|v| v.serde())); + } + debug_struct.field("nested", &self.nested); + debug_struct.finish() + } +} + +impl Fields { + #[inline(always)] + pub fn finalize(self) -> serde_json::Value { + let mut map = Map::new(); + for field in self.fields { + if field.nested.is_empty() { + map.insert(field.name.clone(), field.resolved.unwrap_or(Value::new(serde_json::Value::Null)).into_serde()); + } else { + let nested_value = Fields { fields: field.nested }.finalize(); + map.insert(field.name.clone(), nested_value); + } + } + let mut data = Map::new(); + data.insert("data".to_string(), serde_json::Value::Object(map)); + serde_json::Value::Object(data) + } + #[inline(always)] + pub async fn resolve<'a>(mut self, eval_context: EvalContext<'a>) -> anyhow::Result { + let mut ans = vec![]; + ans = Self::resolve_inner(self.fields, eval_context).await?; + Ok(Fields { + fields: ans, + }) + } + + #[inline(always)] + fn resolve_inner<'a>(fields: Vec, mut eval_context: EvalContext<'a>) -> Pin>> + Send + 'a>> { + Box::pin(async move { + let mut ans = vec![]; + for mut field in fields { + if let Some(ir) = field.ir.clone() { + if let Some(val) = field.args.clone() { + eval_context = eval_context.with_args(val); + } + let val = ir.eval(&mut eval_context.clone()).await?; + eval_context = eval_context.with_value(val.clone()); + field.resolved = Some(val); + } else { + // println!("{:?}", eval_context.graphql_ctx_value); + let val = eval_context.path_value(&[field.name.as_str()]); + // println!("{}", val.is_some()); + let val = val.unwrap_or(Cow::Owned(Value::new(serde_json::Value::Null))).into_owned(); + + // println!("field: {} val: {}",field.name, val); + // eval_context = eval_context.with_value(val.clone()); + field.resolved = Some(val); + } + field.nested = Self::resolve_inner(field.nested, eval_context.clone()).await?; + ans.push(field); + } + Ok(ans) + }) + } +} + +pub struct Holder<'a> { + field_name: &'a str, + field_type: &'a str, + args: Vec<(&'a str, Value)>, } -pub struct Operation {} + +impl<'a> PathFinder<'a> { + pub fn new(doc: ExecutableDocument, blueprint: &'a Blueprint) -> Self { + Self { doc, blueprint } + } + pub async fn exec(&'a self) -> Fields { + match &self.doc.operations { + DocumentOperations::Single(single) => { + let operation = &single.node; + let selection_set = &operation.selection_set.node; + let ty = match &operation.ty { + OperationType::Query => { + let query = self.blueprint.schema.query.as_ref().map(|v| v.as_str()); + query + } + OperationType::Mutation => None, + OperationType::Subscription => None, + }; + if let Some(ty) = ty { + Fields { + fields: self.iter(selection_set, ty), + } + } else { + Fields { + fields: vec![], + } + } + } + DocumentOperations::Multiple(_) => todo!() + } + } + #[inline(always)] + fn iter( + &self, + selection: &SelectionSet, + type_condition: &str, + ) -> Vec { + let mut fields = vec![]; + for selection in &selection.items { + match &selection.node { + Selection::Field(Positioned { node: gql_field, .. }) => { + // let conditions = self.include(&gql_field.directives); + + /*for directive in &gql_field.directives { + let directive = &directive.node; + if directive.name.node == "skip" || directive.name.node == "include" { + continue; + } + let arguments = directive + .arguments + .iter() + .map(|(k, v)| (k.node.to_string(), v.node.clone())) + .collect::>(); + // println!("directive args: {:?}", arguments); + }*/ + + // let (include, skip) = conditions.into_variable_tuple(); + + let field_name = gql_field.name.node.as_str(); + let request_args = gql_field + .arguments + .iter() + .map(|(k, v)| (k.node.as_str().to_string(), v.node.to_owned().into_const().map(|v| v.into_json().ok()).flatten().unwrap())) + .collect::>(); + + // println!("req args: {:?}", request_args); + // println!("{}: {}",field_name, type_condition); + // println!("{:#?}", self.blueprint.fields); + + if let Some(field_def) = self.blueprint.fields.get(&FieldHash::new(FieldName(field_name.to_string()), TypeName(type_condition.to_string()))) { + // let mut args = Vec::with_capacity(request_args.len()); + /* if let QueryField::Field((_, schema_args)) = field_def { + for (arg_name, arg_value) in schema_args { + let type_of = arg_value.of_type.clone(); + let id = ArgId::new(self.arg_id.next()); + let name = arg_name.clone(); + let default_value = arg_value + .default_value + .as_ref() + .and_then(|v| v.to_owned().try_into().ok()); + args.push(Arg { + id, + name, + type_of, + // TODO: handle errors for non existing request_args without the + // default + value: request_args.get(arg_name).cloned(), + default_value, + }); + } + }*/ + + /* let type_of = match field_def { + QueryField::Field((field_def, _)) => field_def.of_type.clone(), + QueryField::InputField(field_def) => field_def.of_type.clone(), + }; + + let id = FieldId::new(self.field_id.next());*/ + let type_of = field_def.type_of.clone(); + let child_fields = self.iter( + &gql_field.selection_set.node, + type_of.name(), + ); + let field = Field { + ir: field_def.ir.clone(), + name: field_def.name.as_ref().to_string(), + type_of, + nested: child_fields, + args: match request_args.is_empty() { + false => Some(Value::new(serde_json::Value::Object(request_args))), + true => None, + }, + resolved: None, + }; + + /* let ir = match field_def { + QueryField::Field((field_def, _)) => field_def.resolver.clone(), + _ => None, + }; + let flat_field = Field { + id, + name: field_name.to_string(), + output_name: gql_field + .alias + .as_ref() + .map(|a| a.node.to_string()) + .unwrap_or(field_name.to_owned()), + ir, + type_of, + type_condition: Some(type_condition.to_string()), + skip, + include, + args, + pos: selection.pos.into(), + extensions: exts.clone(), + directives, + };*/ + + fields.push(field); + // fields = fields.merge_right(child_fields); + } /*else if field_name == "__typename" { + let flat_field = Field { + id: FieldId::new(self.field_id.next()), + name: field_name.to_string(), + output_name: field_name.to_string(), + ir: None, + type_of: Type::Named { name: "String".to_owned(), non_null: true }, + // __typename has a special meaning and could be applied + // to any type + type_condition: None, + skip, + include, + args: Vec::new(), + pos: selection.pos.into(), + extensions: exts.clone(), + directives, + }; + + fields.push(flat_field); + }*/ + } + _ => (), + } + } + + fields + } +} \ No newline at end of file diff --git a/projects/ssddOnTop/src/value/value.rs b/projects/ssddOnTop/src/value/value.rs index 3934e2d..a5f2249 100644 --- a/projects/ssddOnTop/src/value/value.rs +++ b/projects/ssddOnTop/src/value/value.rs @@ -15,8 +15,7 @@ impl Display for Value { impl Value { pub fn new(serde: serde_json::Value) -> Self { - let borrowed = serde_json_borrow::Value::from(&serde); - let borrowed = extend_lifetime(borrowed); + let borrowed = extend_lifetime(serde_json_borrow::Value::from(&serde)); Self { serde, borrowed } } pub fn into_serde(self) -> serde_json::Value { @@ -29,3 +28,17 @@ fn extend_lifetime<'b>(r: serde_json_borrow::Value<'b>) -> serde_json_borrow::Va std::mem::transmute::, serde_json_borrow::Value<'static>>(r) } } + +#[cfg(test)] +mod test { + use super::*; + use serde_json::json; + + #[test] + fn test_value() { + let val = json!({"key": "value"}); + let value = Value::new(val.clone()); + assert_eq!(value.serde(), &val); + assert_eq!(value.borrowed(), &serde_json_borrow::Value::from(&val)); + } +} \ No newline at end of file From db8ff19de74aa8b5f243e8879af52de28b32738c Mon Sep 17 00:00:00 2001 From: Sandipsinh Rathod Date: Thu, 12 Sep 2024 14:07:22 -0400 Subject: [PATCH 12/21] inteoduceborrowed_fields --- .../ssddOnTop/src/http/request_handler.rs | 6 +- projects/ssddOnTop/src/ir/eval_ctx.rs | 12 - projects/ssddOnTop/src/jit/model.rs | 324 ++++++++++-------- projects/ssddOnTop/src/value/value.rs | 11 +- 4 files changed, 191 insertions(+), 162 deletions(-) diff --git a/projects/ssddOnTop/src/http/request_handler.rs b/projects/ssddOnTop/src/http/request_handler.rs index 5ea3ea5..66984f9 100644 --- a/projects/ssddOnTop/src/http/request_handler.rs +++ b/projects/ssddOnTop/src/http/request_handler.rs @@ -15,7 +15,9 @@ pub async fn handle_request( app_ctx: AppCtx, ) -> anyhow::Result>> { let resp = match req.method { - Method::GET => hyper::Response::new(Full::new(Bytes::from_static(b"Hello, World!"))), + Method::GET => hyper::Response::builder() + .status(hyper::StatusCode::OK) + .body(Full::new(Bytes::from(async_graphql::http::GraphiQLSource::build().finish())))?, Method::POST => handle_gql_req(req, app_ctx).await?, _ => hyper::Response::builder() .status(hyper::StatusCode::METHOD_NOT_ALLOWED) @@ -39,6 +41,8 @@ async fn handle_gql_req( let eval_ctx = EvalContext::new(&req_ctx); let path_finder = PathFinder::new(doc, &app_ctx.blueprint); let fields = path_finder.exec().await; + let borrowed_fields = fields.to_borrowed(); + let resolved = fields.resolve(eval_ctx).await?; let finalized = resolved.finalize(); Ok(hyper::Response::new(Full::new(Bytes::from( diff --git a/projects/ssddOnTop/src/ir/eval_ctx.rs b/projects/ssddOnTop/src/ir/eval_ctx.rs index 9a20b79..3a4ed43 100644 --- a/projects/ssddOnTop/src/ir/eval_ctx.rs +++ b/projects/ssddOnTop/src/ir/eval_ctx.rs @@ -33,18 +33,6 @@ impl<'a> EvalContext<'a> { ..self } } - pub fn clear_args(self) -> Self { - Self { - graphql_ctx_args: None, - ..self - } - } - pub fn clear_value(self) -> Self { - Self { - graphql_ctx_value: None, - ..self - } - } pub fn path_arg>(&self, path: &[T]) -> Option> { let args = self.graphql_ctx_args.as_ref()?; get_path_value(args, path).map(|a| Cow::Owned(a.clone())) diff --git a/projects/ssddOnTop/src/jit/model.rs b/projects/ssddOnTop/src/jit/model.rs index e6dac1d..f3bf3fc 100644 --- a/projects/ssddOnTop/src/jit/model.rs +++ b/projects/ssddOnTop/src/jit/model.rs @@ -1,15 +1,15 @@ -use std::borrow::Cow; -use std::fmt::{Debug, Formatter}; -use std::future::Future; -use std::pin::Pin; use crate::blueprint::model::{FieldName, TypeName}; use crate::blueprint::{Blueprint, FieldHash}; +use crate::ir::eval_ctx::EvalContext; use crate::ir::IR; +use crate::json::JsonObjectLike; use crate::value::Value; use async_graphql::parser::types::{DocumentOperations, ExecutableDocument, OperationType, Selection, SelectionSet}; use async_graphql::Positioned; use serde_json::Map; -use crate::ir::eval_ctx::EvalContext; +use std::fmt::Debug; +use std::future::Future; +use std::pin::Pin; pub struct PathFinder<'a> { doc: ExecutableDocument, @@ -20,7 +20,12 @@ pub struct Fields { fields: Vec, } -// #[derive(Debug)] +#[derive(Debug)] +pub struct Fields1<'a> { + fields: Vec>, +} + +#[derive(Debug)] // TODO: give it a lifetime // it won't make much difference.. // but anyways @@ -33,86 +38,186 @@ pub struct Field { pub resolved: Option, } -pub struct Field1<'a> { - value: serde_json_borrow::Value<'a>, - pub name: &'a str, - pub type_of: crate::blueprint::wrapping_type::Type, - nexted: Vec>, - pub args: Option, -} - -impl Debug for Field { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - let mut debug_struct = f.debug_struct("Field"); - debug_struct.field("name", &self.name); - if self.ir.is_some() { - debug_struct.field("ir", &"Some(..)"); - } - debug_struct.field("type_of", &self.type_of); - if self.args.is_some() { - debug_struct.field("args", &self.args); +impl Fields { + #[inline(always)] + pub fn to_borrowed<'a>(&'a self) -> Fields1<'a> { + let fields = Self::borrowed_inner(&self.fields); + Fields1 { + fields, } - if self.resolved.is_some() { - debug_struct.field("resolved", &self.resolved.as_ref().map(|v| v.serde())); + } + + #[inline(always)] + pub fn borrowed_inner<'a>(vec: &'a [Field]) -> Vec> { + let mut ans = vec![]; + for field in vec.iter() { + let field = Field1 { + ir: field.ir.as_ref(), + name: field.name.as_str(), + type_of: &field.type_of, + nested: Self::borrowed_inner(&field.nested), + args: field.args.as_ref(), + resolved: field.resolved.as_ref().map(|v| serde_json_borrow::Value::from(v.serde())), + }; + ans.push(field); } - debug_struct.field("nested", &self.nested); - debug_struct.finish() + ans } + } +#[derive(Debug)] +pub struct Field1<'a> { + ir: Option<&'a IR>, + pub name: &'a str, + pub type_of: &'a crate::blueprint::wrapping_type::Type, + nested: Vec>, + pub args: Option<&'a Value>, + pub resolved: Option>, +} impl Fields { #[inline(always)] pub fn finalize(self) -> serde_json::Value { let mut map = Map::new(); - for field in self.fields { - if field.nested.is_empty() { - map.insert(field.name.clone(), field.resolved.unwrap_or(Value::new(serde_json::Value::Null)).into_serde()); - } else { - let nested_value = Fields { fields: field.nested }.finalize(); - map.insert(field.name.clone(), nested_value); + for field in self.fields.iter() { + let name = field.name.as_str().to_string(); + let val = Self::finalize_inner(field, None, None); + map.insert(name, val); + } + let mut ans = Map::new(); + ans.insert("data".to_string(), serde_json::Value::Object(map)); + // map.insert("data".to_string(), self.finalize_inner()); + // serde_json::Value::Object(map) + serde_json::Value::Object(ans) + } + #[inline(always)] + fn finalize_inner<'a>(field: &'a Field, mut value: Option<&'a serde_json::Value>, index: Option) -> serde_json::Value { + if let Some(val) = &field.resolved { + if value.is_none() { + value = Some(val.serde()); } } - let mut data = Map::new(); - data.insert("data".to_string(), serde_json::Value::Object(map)); - serde_json::Value::Object(data) + if let Some(val) = value { + match (val.as_array(), val.as_object()) { + (_, Some(obj)) => { + let mut ans = Map::new(); + + if field.nested.is_empty() { + let val = obj.get_key(field.name.as_str()); + let value = Self::finalize_inner(field, val, index); + ans.insert(field.name.as_str().to_string(), value); + } else { + for child in field.nested.iter() { + let child_name = child.name.as_str().to_string(); + let val = obj.get_key(child.name.as_str()); + let val = Self::finalize_inner(child, val, index); + ans.insert(child_name, val); + } + } + + serde_json::Value::Object(ans) + } + (Some(arr), _) => { + if let Some(index) = index { + let val = arr.get(index); + let val = Self::finalize_inner(field, val, None); + val + } else { + let mut ans = vec![]; + for (i, val) in arr.iter().enumerate() { + let val = Self::finalize_inner(field, Some(val), Some(i)); + ans.push(val); + } + serde_json::Value::Array(ans) + } + } + _ => value.cloned().unwrap_or_default(), + } + } else { + serde_json::Value::Null + } } #[inline(always)] pub async fn resolve<'a>(mut self, eval_context: EvalContext<'a>) -> anyhow::Result { let mut ans = vec![]; - ans = Self::resolve_inner(self.fields, eval_context).await?; + ans = Self::resolve_inner(self.fields, eval_context, None).await?; Ok(Fields { fields: ans, }) } #[inline(always)] - fn resolve_inner<'a>(fields: Vec, mut eval_context: EvalContext<'a>) -> Pin>> + Send + 'a>> { + fn resolve_inner<'a>(fields: Vec, mut eval_context: EvalContext<'a>, parent: Option) -> Pin>> + Send + 'a>> { Box::pin(async move { let mut ans = vec![]; for mut field in fields { + let mut parent_val = None; + if let Some(ir) = field.ir.clone() { if let Some(val) = field.args.clone() { eval_context = eval_context.with_args(val); } - let val = ir.eval(&mut eval_context.clone()).await?; - eval_context = eval_context.with_value(val.clone()); - field.resolved = Some(val); - } else { - // println!("{:?}", eval_context.graphql_ctx_value); - let val = eval_context.path_value(&[field.name.as_str()]); - // println!("{}", val.is_some()); - let val = val.unwrap_or(Cow::Owned(Value::new(serde_json::Value::Null))).into_owned(); - // println!("field: {} val: {}",field.name, val); - // eval_context = eval_context.with_value(val.clone()); - field.resolved = Some(val); + let val = match &parent { + Some(val) => { + match val.clone().into_serde() { + serde_json::Value::Array(arr) => { + let mut ans = vec![]; + for val in arr { + eval_context = eval_context.with_value(Value::new(val)); + let val = ir.eval(&mut eval_context.clone()).await?; + ans.push(val.into_serde()); + } + Some(Value::new(serde_json::Value::Array(ans))) + } + val => { + eval_context = eval_context.with_value(Value::new(val)); + let val = ir.eval(&mut eval_context.clone()).await?; + Some(val) + } + } + } + None => { + let val = ir.eval(&mut eval_context.clone()).await?; + Some(val) + } + }; + parent_val = val.clone(); + field.resolved = val; + } else { + // println!("hx: {}", field.name); + // let val = Self::resolve_non_ir(eval_context.graphql_ctx_value.as_ref().map(|v| v.serde()).unwrap_or(&serde_json::Value::Null), field.name.as_str()); + // println!("{}",val); + // let val = eval_context.path_value(&[field.name.as_str()]); + // let val = val.unwrap_or(Cow::Owned(Value::new(serde_json::Value::Null))).into_owned(); + // field.resolved = Some(Value::new(val)); } - field.nested = Self::resolve_inner(field.nested, eval_context.clone()).await?; + + let eval_ctx_clone = eval_context.clone(); + field.nested = Self::resolve_inner(field.nested, eval_ctx_clone, parent_val).await?; ans.push(field); } Ok(ans) }) } + #[inline(always)] + fn resolve_non_ir(value: &serde_json::Value, key: &str) -> serde_json::Value { + match value { + serde_json::Value::Array(arr) => { + let mut ans = vec![]; + for val in arr { + ans.push(Self::resolve_non_ir(val, key)); + } + serde_json::Value::Array(ans) + } + serde_json::Value::Object(obj) => { + let mut ans = Map::new(); + obj.get_key(key).map(|v| ans.insert(key.to_string(), v.clone())).unwrap_or_default(); + serde_json::Value::Object(ans) + } + val => val.clone(), + } + } } pub struct Holder<'a> { @@ -148,7 +253,28 @@ impl<'a> PathFinder<'a> { } } } - DocumentOperations::Multiple(_) => todo!() + DocumentOperations::Multiple(multi) => { + let (_,single) = multi.iter().next().unwrap(); + let operation = &single.node; + let selection_set = &operation.selection_set.node; + let ty = match &operation.ty { + OperationType::Query => { + let query = self.blueprint.schema.query.as_ref().map(|v| v.as_str()); + query + } + OperationType::Mutation => None, + OperationType::Subscription => None, + }; + if let Some(ty) = ty { + Fields { + fields: self.iter(selection_set, ty), + } + } else { + Fields { + fields: vec![], + } + } + } } } #[inline(always)] @@ -161,23 +287,6 @@ impl<'a> PathFinder<'a> { for selection in &selection.items { match &selection.node { Selection::Field(Positioned { node: gql_field, .. }) => { - // let conditions = self.include(&gql_field.directives); - - /*for directive in &gql_field.directives { - let directive = &directive.node; - if directive.name.node == "skip" || directive.name.node == "include" { - continue; - } - let arguments = directive - .arguments - .iter() - .map(|(k, v)| (k.node.to_string(), v.node.clone())) - .collect::>(); - // println!("directive args: {:?}", arguments); - }*/ - - // let (include, skip) = conditions.into_variable_tuple(); - let field_name = gql_field.name.node.as_str(); let request_args = gql_field .arguments @@ -185,39 +294,7 @@ impl<'a> PathFinder<'a> { .map(|(k, v)| (k.node.as_str().to_string(), v.node.to_owned().into_const().map(|v| v.into_json().ok()).flatten().unwrap())) .collect::>(); - // println!("req args: {:?}", request_args); - // println!("{}: {}",field_name, type_condition); - // println!("{:#?}", self.blueprint.fields); - if let Some(field_def) = self.blueprint.fields.get(&FieldHash::new(FieldName(field_name.to_string()), TypeName(type_condition.to_string()))) { - // let mut args = Vec::with_capacity(request_args.len()); - /* if let QueryField::Field((_, schema_args)) = field_def { - for (arg_name, arg_value) in schema_args { - let type_of = arg_value.of_type.clone(); - let id = ArgId::new(self.arg_id.next()); - let name = arg_name.clone(); - let default_value = arg_value - .default_value - .as_ref() - .and_then(|v| v.to_owned().try_into().ok()); - args.push(Arg { - id, - name, - type_of, - // TODO: handle errors for non existing request_args without the - // default - value: request_args.get(arg_name).cloned(), - default_value, - }); - } - }*/ - - /* let type_of = match field_def { - QueryField::Field((field_def, _)) => field_def.of_type.clone(), - QueryField::InputField(field_def) => field_def.of_type.clone(), - }; - - let id = FieldId::new(self.field_id.next());*/ let type_of = field_def.type_of.clone(); let child_fields = self.iter( &gql_field.selection_set.node, @@ -235,51 +312,8 @@ impl<'a> PathFinder<'a> { resolved: None, }; - /* let ir = match field_def { - QueryField::Field((field_def, _)) => field_def.resolver.clone(), - _ => None, - }; - let flat_field = Field { - id, - name: field_name.to_string(), - output_name: gql_field - .alias - .as_ref() - .map(|a| a.node.to_string()) - .unwrap_or(field_name.to_owned()), - ir, - type_of, - type_condition: Some(type_condition.to_string()), - skip, - include, - args, - pos: selection.pos.into(), - extensions: exts.clone(), - directives, - };*/ - fields.push(field); - // fields = fields.merge_right(child_fields); - } /*else if field_name == "__typename" { - let flat_field = Field { - id: FieldId::new(self.field_id.next()), - name: field_name.to_string(), - output_name: field_name.to_string(), - ir: None, - type_of: Type::Named { name: "String".to_owned(), non_null: true }, - // __typename has a special meaning and could be applied - // to any type - type_condition: None, - skip, - include, - args: Vec::new(), - pos: selection.pos.into(), - extensions: exts.clone(), - directives, - }; - - fields.push(flat_field); - }*/ + } } _ => (), } diff --git a/projects/ssddOnTop/src/value/value.rs b/projects/ssddOnTop/src/value/value.rs index a5f2249..a4528f0 100644 --- a/projects/ssddOnTop/src/value/value.rs +++ b/projects/ssddOnTop/src/value/value.rs @@ -4,7 +4,7 @@ use std::fmt::{Display, Formatter}; #[derive(Getters, Debug, Clone, PartialEq, Eq, Hash)] pub struct Value { serde: serde_json::Value, - borrowed: serde_json_borrow::Value<'static>, + // borrowed: serde_json_borrow::Value<'static>, } impl Display for Value { @@ -15,8 +15,11 @@ impl Display for Value { impl Value { pub fn new(serde: serde_json::Value) -> Self { - let borrowed = extend_lifetime(serde_json_borrow::Value::from(&serde)); - Self { serde, borrowed } + // let borrowed = extend_lifetime(serde_json_borrow::Value::from(&serde)); + Self { + serde, + // borrowed, + } } pub fn into_serde(self) -> serde_json::Value { self.serde @@ -39,6 +42,6 @@ mod test { let val = json!({"key": "value"}); let value = Value::new(val.clone()); assert_eq!(value.serde(), &val); - assert_eq!(value.borrowed(), &serde_json_borrow::Value::from(&val)); + // assert_eq!(value.borrowed(), &serde_json_borrow::Value::from(&val)); } } \ No newline at end of file From 7017f634128d9fde7b18f222fdac0ed31cb5de51 Mon Sep 17 00:00:00 2001 From: Sandipsinh Rathod Date: Thu, 12 Sep 2024 14:21:56 -0400 Subject: [PATCH 13/21] revert chan --- Cargo.lock | 1671 +------------------------------ Cargo.toml | 2 +- mock-api/src/database.rs | 6 - mock-api/src/lib.rs | 6 +- mock-api/src/main.rs | 2 +- mock-api/src/routes/get_user.rs | 5 +- projects/ssddOnTop/run.sh | 2 +- 7 files changed, 50 insertions(+), 1644 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a86934b..eb69c17 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,16 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "Inflector" -version = "0.11.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" -dependencies = [ - "lazy_static", - "regex", -] - [[package]] name = "addr2line" version = "0.22.0" @@ -106,272 +96,6 @@ version = "1.0.88" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4e1496f8fb1fbf272686b8d37f523dab3e4a7443300055e74cdaa449f3114356" -[[package]] -name = "ascii_utils" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71938f30533e4d95a6d17aa530939da3842c2ab6f4f84b9dae68447e4129f74a" - -[[package]] -name = "async-channel" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81953c529336010edd6d8e358f886d9581267795c61b19475b71314bffa46d35" -dependencies = [ - "concurrent-queue", - "event-listener 2.5.3", - "futures-core", -] - -[[package]] -name = "async-channel" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89b47800b0be77592da0afd425cc03468052844aff33b84e33cc696f64e77b6a" -dependencies = [ - "concurrent-queue", - "event-listener-strategy", - "futures-core", - "pin-project-lite", -] - -[[package]] -name = "async-executor" -version = "1.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30ca9a001c1e8ba5149f91a74362376cc6bc5b919d92d988668657bd570bdcec" -dependencies = [ - "async-task", - "concurrent-queue", - "fastrand", - "futures-lite", - "slab", -] - -[[package]] -name = "async-global-executor" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05b1b633a2115cd122d73b955eadd9916c18c8f510ec9cd1686404c60ad1c29c" -dependencies = [ - "async-channel 2.3.1", - "async-executor", - "async-io", - "async-lock", - "blocking", - "futures-lite", - "once_cell", -] - -[[package]] -name = "async-graphql" -version = "7.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d37c3e9ba322eb00e9e5e997d58f08e8b6de037325b9367ac59bca8e3cd46af" -dependencies = [ - "async-graphql-derive", - "async-graphql-parser", - "async-graphql-value", - "async-stream", - "async-trait", - "base64 0.22.1", - "bytes", - "fast_chemail", - "fnv", - "futures-timer", - "futures-util", - "handlebars", - "http 1.1.0", - "indexmap", - "mime", - "multer", - "num-traits", - "once_cell", - "pin-project-lite", - "regex", - "serde", - "serde_json", - "serde_urlencoded", - "static_assertions_next", - "tempfile", - "thiserror", -] - -[[package]] -name = "async-graphql-derive" -version = "7.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1141703c11c6ad4fa9b3b0e1e476dea01dbd18a44db00f949b804afaab2f344" -dependencies = [ - "Inflector", - "async-graphql-parser", - "darling", - "proc-macro-crate", - "proc-macro2", - "quote", - "strum", - "syn", - "thiserror", -] - -[[package]] -name = "async-graphql-parser" -version = "7.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f66edcce4c38c18f7eb181fdf561c3d3aa2d644ce7358fc7a928c00a4ffef17" -dependencies = [ - "async-graphql-value", - "pest", - "serde", - "serde_json", -] - -[[package]] -name = "async-graphql-value" -version = "7.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b0206011cad065420c27988f17dd7fe201a0e056b20c262209b7bffcd6fa176" -dependencies = [ - "bytes", - "indexmap", - "serde", - "serde_json", -] - -[[package]] -name = "async-io" -version = "2.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "444b0228950ee6501b3568d3c93bf1176a1fdbc3b758dcd9475046d30f4dc7e8" -dependencies = [ - "async-lock", - "cfg-if", - "concurrent-queue", - "futures-io", - "futures-lite", - "parking", - "polling", - "rustix", - "slab", - "tracing", - "windows-sys 0.59.0", -] - -[[package]] -name = "async-lock" -version = "3.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff6e472cdea888a4bd64f342f09b3f50e1886d32afe8df3d663c01140b811b18" -dependencies = [ - "event-listener 5.3.1", - "event-listener-strategy", - "pin-project-lite", -] - -[[package]] -name = "async-process" -version = "2.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8a07789659a4d385b79b18b9127fc27e1a59e1e89117c78c5ea3b806f016374" -dependencies = [ - "async-channel 2.3.1", - "async-io", - "async-lock", - "async-signal", - "async-task", - "blocking", - "cfg-if", - "event-listener 5.3.1", - "futures-lite", - "rustix", - "tracing", - "windows-sys 0.59.0", -] - -[[package]] -name = "async-recursion" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b43422f69d8ff38f95f1b2bb76517c91589a924d1559a0e935d7c8ce0274c11" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "async-signal" -version = "0.2.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "637e00349800c0bdf8bfc21ebbc0b6524abea702b0da4168ac00d070d0c0b9f3" -dependencies = [ - "async-io", - "async-lock", - "atomic-waker", - "cfg-if", - "futures-core", - "futures-io", - "rustix", - "signal-hook-registry", - "slab", - "windows-sys 0.59.0", -] - -[[package]] -name = "async-std" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c634475f29802fde2b8f0b505b1bd00dfe4df7d4a000f0b36f7671197d5c3615" -dependencies = [ - "async-channel 1.9.0", - "async-global-executor", - "async-io", - "async-lock", - "async-process", - "crossbeam-utils", - "futures-channel", - "futures-core", - "futures-io", - "futures-lite", - "gloo-timers", - "kv-log-macro", - "log", - "memchr", - "once_cell", - "pin-project-lite", - "pin-utils", - "slab", - "wasm-bindgen-futures", -] - -[[package]] -name = "async-stream" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd56dd203fef61ac097dd65721a419ddccb106b2d2b70ba60a6b529f03961a51" -dependencies = [ - "async-stream-impl", - "futures-core", - "pin-project-lite", -] - -[[package]] -name = "async-stream-impl" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "async-task" -version = "4.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de" - [[package]] name = "async-trait" version = "0.1.82" @@ -405,10 +129,10 @@ dependencies = [ "axum-core", "bytes", "futures-util", - "http 1.1.0", - "http-body 1.0.1", + "http", + "http-body", "http-body-util", - "hyper 1.4.1", + "hyper", "hyper-util", "itoa", "matchit", @@ -438,8 +162,8 @@ dependencies = [ "async-trait", "bytes", "futures-util", - "http 1.1.0", - "http-body 1.0.1", + "http", + "http-body", "http-body-util", "mime", "pin-project-lite", @@ -477,49 +201,12 @@ version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" -[[package]] -name = "bincode" -version = "1.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" -dependencies = [ - "serde", -] - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - [[package]] name = "bitflags" version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" -[[package]] -name = "block-buffer" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" -dependencies = [ - "generic-array", -] - -[[package]] -name = "blocking" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "703f41c54fc768e63e091340b424302bb1c29ef4aa0c7f10fe849dfb114d29ea" -dependencies = [ - "async-channel 2.3.1", - "async-task", - "futures-io", - "futures-lite", - "piper", -] - [[package]] name = "bumpalo" version = "3.16.0" @@ -537,35 +224,6 @@ name = "bytes" version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" -dependencies = [ - "serde", -] - -[[package]] -name = "cacache" -version = "12.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "142316461ed3a3dfcba10417317472da5bfd0461e4d276bf7c07b330766d9490" -dependencies = [ - "async-std", - "digest", - "either", - "futures", - "hex", - "libc", - "memmap2", - "miette", - "reflink-copy", - "serde", - "serde_derive", - "serde_json", - "sha1", - "sha2", - "ssri", - "tempfile", - "thiserror", - "walkdir", -] [[package]] name = "cc" @@ -664,30 +322,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "concurrent-queue" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" -dependencies = [ - "crossbeam-utils", -] - -[[package]] -name = "convert_case" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" - -[[package]] -name = "convert_case" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" -dependencies = [ - "unicode-segmentation", -] - [[package]] name = "core-foundation" version = "0.9.4" @@ -704,84 +338,12 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" -[[package]] -name = "cpufeatures" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" -dependencies = [ - "libc", -] - -[[package]] -name = "crossbeam-channel" -version = "0.5.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33480d6946193aa8033910124896ca395333cae7e2d1113d1fef6c3272217df2" -dependencies = [ - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.9.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" -dependencies = [ - "crossbeam-utils", -] - [[package]] name = "crossbeam-utils" version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" -[[package]] -name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] - -[[package]] -name = "darling" -version = "0.20.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" -dependencies = [ - "darling_core", - "darling_macro", -] - -[[package]] -name = "darling_core" -version = "0.20.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" -dependencies = [ - "fnv", - "ident_case", - "proc-macro2", - "quote", - "strsim", - "syn", -] - -[[package]] -name = "darling_macro" -version = "0.20.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" -dependencies = [ - "darling_core", - "quote", - "syn", -] - [[package]] name = "dashmap" version = "5.5.3" @@ -804,48 +366,6 @@ dependencies = [ "powerfmt", ] -[[package]] -name = "derive-getters" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74ef43543e701c01ad77d3a5922755c6a1d71b22d942cb8042be4994b380caff" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "derive_more" -version = "0.99.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" -dependencies = [ - "convert_case 0.4.0", - "proc-macro2", - "quote", - "rustc_version", - "syn", -] - -[[package]] -name = "derive_setters" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e8ef033054e131169b8f0f9a7af8f5533a9436fadf3c500ed547f730f07090d" -dependencies = [ - "darling", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "diff" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" - [[package]] name = "diff_logger" version = "0.1.0" @@ -857,22 +377,6 @@ dependencies = [ "serde_json", ] -[[package]] -name = "digest" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" -dependencies = [ - "block-buffer", - "crypto-common", -] - -[[package]] -name = "dyn-clone" -version = "1.0.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" - [[package]] name = "easy_retry" version = "0.1.0" @@ -883,12 +387,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "either" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" - [[package]] name = "encoding_rs" version = "0.8.34" @@ -898,27 +396,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "env_filter" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f2c92ceda6ceec50f43169f9ee8424fe2db276791afde7b2cd8bc084cb376ab" -dependencies = [ - "log", -] - -[[package]] -name = "env_logger" -version = "0.11.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13fa619b91fb2381732789fc5de83b45675e882f66623b7d8cb4f643017018d" -dependencies = [ - "anstream", - "anstyle", - "env_filter", - "log", -] - [[package]] name = "equivalent" version = "1.0.1" @@ -935,42 +412,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "event-listener" -version = "2.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" - -[[package]] -name = "event-listener" -version = "5.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6032be9bd27023a771701cc49f9f053c751055f71efb2e0ae5c15809093675ba" -dependencies = [ - "concurrent-queue", - "parking", - "pin-project-lite", -] - -[[package]] -name = "event-listener-strategy" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f214dc438f977e6d4e3500aaa277f5ad94ca83fbbd9b1a15713ce2344ccc5a1" -dependencies = [ - "event-listener 5.3.1", - "pin-project-lite", -] - -[[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 = "2.1.1" @@ -1065,19 +506,6 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" -[[package]] -name = "futures-lite" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52527eb5074e35e9339c6b4e8d12600c7128b68fb25dcb9fa9dec18f7c25f3a5" -dependencies = [ - "fastrand", - "futures-core", - "futures-io", - "parking", - "pin-project-lite", -] - [[package]] name = "futures-macro" version = "0.3.30" @@ -1125,25 +553,6 @@ dependencies = [ "slab", ] -[[package]] -name = "fxhash" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" -dependencies = [ - "byteorder", -] - -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", -] - [[package]] name = "getrandom" version = "0.2.15" @@ -1163,18 +572,6 @@ version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" -[[package]] -name = "gloo-timers" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbb143cf96099802033e0d4f4963b19fd2e0b728bcf076cd9cf7f6634f092994" -dependencies = [ - "futures-channel", - "futures-core", - "js-sys", - "wasm-bindgen", -] - [[package]] name = "governor" version = "0.6.3" @@ -1195,25 +592,6 @@ dependencies = [ "spinning_top", ] -[[package]] -name = "h2" -version = "0.3.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8" -dependencies = [ - "bytes", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http 0.2.12", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - [[package]] name = "h2" version = "0.4.6" @@ -1225,7 +603,7 @@ dependencies = [ "fnv", "futures-core", "futures-sink", - "http 1.1.0", + "http", "indexmap", "slab", "tokio", @@ -1245,7 +623,7 @@ dependencies = [ "mock_json", "octocrate", "regex", - "reqwest 0.12.7", + "reqwest", "serde", "serde_json", "tokio", @@ -1253,20 +631,6 @@ dependencies = [ "tracing-subscriber", ] -[[package]] -name = "handlebars" -version = "5.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d08485b96a0e6393e9e4d1b8d48cf74ad6c063cd905eb33f42c1ce3f0377539b" -dependencies = [ - "log", - "pest", - "pest_derive", - "serde", - "serde_json", - "thiserror", -] - [[package]] name = "hashbrown" version = "0.14.5" @@ -1285,29 +649,6 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" -[[package]] -name = "hermit-abi" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc" - -[[package]] -name = "hex" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" - -[[package]] -name = "http" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - [[package]] name = "http" version = "1.1.0" @@ -1319,17 +660,6 @@ dependencies = [ "itoa", ] -[[package]] -name = "http-body" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" -dependencies = [ - "bytes", - "http 0.2.12", - "pin-project-lite", -] - [[package]] name = "http-body" version = "1.0.1" @@ -1337,7 +667,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ "bytes", - "http 1.1.0", + "http", ] [[package]] @@ -1348,69 +678,11 @@ checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" dependencies = [ "bytes", "futures-util", - "http 1.1.0", - "http-body 1.0.1", + "http", + "http-body", "pin-project-lite", ] -[[package]] -name = "http-cache" -version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b5ab65432bbdfe8490dfde21d0366353a8d39f2bc24aca0146889f931b0b4b5" -dependencies = [ - "async-trait", - "bincode", - "cacache", - "http 0.2.12", - "http-cache-semantics", - "httpdate", - "moka", - "serde", - "url", -] - -[[package]] -name = "http-cache-reqwest" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8285341ce7e709c56a0f259ff1c789c70edfbaa88acd69d27e4d63980b92dc" -dependencies = [ - "anyhow", - "async-trait", - "http 0.2.12", - "http-cache", - "http-cache-semantics", - "reqwest 0.11.27", - "reqwest-middleware", - "serde", - "task-local-extensions", - "url", -] - -[[package]] -name = "http-cache-semantics" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7aec9f678bca3f4a15194b980f20ed9bfe0dd38e8d298c65c559a93dfbd6380a" -dependencies = [ - "http 0.2.12", - "http-serde", - "reqwest 0.11.27", - "serde", - "time", -] - -[[package]] -name = "http-serde" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f560b665ad9f1572cfcaf034f7fb84338a7ce945216d64a90fd81f046a3caee" -dependencies = [ - "http 0.2.12", - "serde", -] - [[package]] name = "httparse" version = "1.9.4" @@ -1423,30 +695,6 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" -[[package]] -name = "hyper" -version = "0.14.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a152ddd61dfaec7273fe8419ab357f33aee0d914c5f4efbf0d96fa749eea5ec9" -dependencies = [ - "bytes", - "futures-channel", - "futures-core", - "futures-util", - "h2 0.3.26", - "http 0.2.12", - "http-body 0.4.6", - "httparse", - "httpdate", - "itoa", - "pin-project-lite", - "socket2", - "tokio", - "tower-service", - "tracing", - "want", -] - [[package]] name = "hyper" version = "1.4.1" @@ -1456,9 +704,9 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2 0.4.6", - "http 1.1.0", - "http-body 1.0.1", + "h2", + "http", + "http-body", "httparse", "httpdate", "itoa", @@ -1475,27 +723,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5ee4be2c948921a1a5320b629c4193916ed787a7f7f293fd3f7f5a6c9de74155" dependencies = [ "futures-util", - "http 1.1.0", - "hyper 1.4.1", + "http", + "hyper", "hyper-util", "rustls", "rustls-pki-types", "tokio", - "tokio-rustls", - "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" -dependencies = [ - "bytes", - "hyper 0.14.30", - "native-tls", - "tokio", - "tokio-native-tls", + "tokio-rustls", + "tower-service", ] [[package]] @@ -1506,7 +741,7 @@ checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" dependencies = [ "bytes", "http-body-util", - "hyper 1.4.1", + "hyper", "hyper-util", "native-tls", "tokio", @@ -1523,9 +758,9 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "http 1.1.0", - "http-body 1.0.1", - "hyper 1.4.1", + "http", + "http-body", + "hyper", "pin-project-lite", "socket2", "tokio", @@ -1545,7 +780,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core 0.52.0", + "windows-core", ] [[package]] @@ -1557,12 +792,6 @@ dependencies = [ "cc", ] -[[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.5.0" @@ -1573,12 +802,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indenter" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" - [[package]] name = "indexmap" version = "2.5.0" @@ -1587,7 +810,6 @@ checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" dependencies = [ "equivalent", "hashbrown", - "serde", ] [[package]] @@ -1602,15 +824,6 @@ version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" -[[package]] -name = "itertools" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" -dependencies = [ - "either", -] - [[package]] name = "itoa" version = "1.0.11" @@ -1641,15 +854,6 @@ dependencies = [ "simple_asn1", ] -[[package]] -name = "kv-log-macro" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" -dependencies = [ - "log", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -1662,12 +866,6 @@ version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" -[[package]] -name = "linked-hash-map" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" - [[package]] name = "linux-raw-sys" version = "0.4.14" @@ -1689,28 +887,6 @@ name = "log" version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" -dependencies = [ - "value-bag", -] - -[[package]] -name = "macros" -version = "0.1.0" -dependencies = [ - "anyhow", - "macros_common", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "macros_common" -version = "0.1.0" -dependencies = [ - "async-graphql", - "schemars", -] [[package]] name = "matchers" @@ -1733,60 +909,12 @@ version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" -[[package]] -name = "memmap2" -version = "0.5.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83faa42c0a078c393f6b29d5db232d8be22776a891f8f56e5284faee4a20b327" -dependencies = [ - "libc", -] - -[[package]] -name = "miette" -version = "5.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59bb584eaeeab6bd0226ccf3509a69d7936d148cf3d036ad350abe35e8c6856e" -dependencies = [ - "miette-derive", - "once_cell", - "thiserror", - "unicode-width", -] - -[[package]] -name = "miette-derive" -version = "5.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49e7bc1560b95a3c4a25d03de42fe76ca718ab92d1a22a55b9b4cf67b3ae635c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "mime" version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" -[[package]] -name = "mime_guess" -version = "2.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e" -dependencies = [ - "mime", - "unicase", -] - -[[package]] -name = "minimal-lexical" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" - [[package]] name = "miniz_oxide" version = "0.7.4" @@ -1802,7 +930,7 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" dependencies = [ - "hermit-abi 0.3.9", + "hermit-abi", "libc", "wasi", "windows-sys 0.52.0", @@ -1835,47 +963,6 @@ dependencies = [ "serde_json", ] -[[package]] -name = "moka" -version = "0.12.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32cf62eb4dd975d2dde76432fb1075c49e3ee2331cf36f1f8fd4b66550d32b6f" -dependencies = [ - "async-lock", - "async-trait", - "crossbeam-channel", - "crossbeam-epoch", - "crossbeam-utils", - "event-listener 5.3.1", - "futures-util", - "once_cell", - "parking_lot", - "quanta", - "rustc_version", - "smallvec", - "tagptr", - "thiserror", - "triomphe", - "uuid", -] - -[[package]] -name = "multer" -version = "3.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83e87776546dc87511aa5ee218730c92b666d7264ab6ed41f9d215af9cd5224b" -dependencies = [ - "bytes", - "encoding_rs", - "futures-util", - "http 1.1.0", - "httparse", - "memchr", - "mime", - "spin", - "version_check", -] - [[package]] name = "native-tls" version = "0.2.12" @@ -1899,7 +986,7 @@ version = "0.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2eb04e9c688eff1c89d72b407f168cf79bb9e867a9d3323ed6c01519eb9cc053" dependencies = [ - "bitflags 2.6.0", + "bitflags", "cfg-if", "libc", ] @@ -1910,16 +997,6 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b93853da6d84c2e3c7d730d6473e8817692dd89be387eb01b94d7f108ecb5b8c" -[[package]] -name = "nom" -version = "7.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" -dependencies = [ - "memchr", - "minimal-lexical", -] - [[package]] name = "nonempty" version = "0.7.0" @@ -1976,16 +1053,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi 0.3.9", - "libc", -] - [[package]] name = "object" version = "0.36.4" @@ -2017,7 +1084,7 @@ dependencies = [ "chrono", "jsonwebtoken", "octocrate-types", - "reqwest 0.12.7", + "reqwest", "serde", "serde_json", "thiserror", @@ -2046,7 +1113,7 @@ version = "0.10.66" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" dependencies = [ - "bitflags 2.6.0", + "bitflags", "cfg-if", "foreign-types", "libc", @@ -2090,12 +1157,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" -[[package]] -name = "parking" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" - [[package]] name = "parking_lot" version = "0.12.3" @@ -2135,51 +1196,6 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" -[[package]] -name = "pest" -version = "2.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c73c26c01b8c87956cea613c907c9d6ecffd8d18a2a5908e5de0adfaa185cea" -dependencies = [ - "memchr", - "thiserror", - "ucd-trie", -] - -[[package]] -name = "pest_derive" -version = "2.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "664d22978e2815783adbdd2c588b455b1bd625299ce36b2a99881ac9627e6d8d" -dependencies = [ - "pest", - "pest_generator", -] - -[[package]] -name = "pest_generator" -version = "2.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2d5487022d5d33f4c30d91c22afa240ce2a644e87fe08caad974d4eab6badbe" -dependencies = [ - "pest", - "pest_meta", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "pest_meta" -version = "2.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0091754bbd0ea592c4deb3a122ce8ecbb0753b738aa82bc055fcc2eccc8d8174" -dependencies = [ - "once_cell", - "pest", - "sha2", -] - [[package]] name = "pin-project" version = "1.1.5" @@ -2212,38 +1228,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "piper" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96c8c490f422ef9a4efd2cb5b42b76c8613d7e7dfc1caf667b8a3350a5acc066" -dependencies = [ - "atomic-waker", - "fastrand", - "futures-io", -] - [[package]] name = "pkg-config" version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" -[[package]] -name = "polling" -version = "3.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc2790cd301dec6cd3b7a025e4815cf825724a51c98dccfe6a3e55f05ffb6511" -dependencies = [ - "cfg-if", - "concurrent-queue", - "hermit-abi 0.4.0", - "pin-project-lite", - "rustix", - "tracing", - "windows-sys 0.59.0", -] - [[package]] name = "portable-atomic" version = "1.7.0" @@ -2265,25 +1255,6 @@ dependencies = [ "zerocopy", ] -[[package]] -name = "pretty_assertions" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af7cee1a6c8a5b9208b3cb1061f10c0cb689087b3d8ce85fb9d2dd7a29b6ba66" -dependencies = [ - "diff", - "yansi", -] - -[[package]] -name = "proc-macro-crate" -version = "3.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ecf48c7ca261d60b74ab1a7b20da18bede46776b2e55535cb958eb595c5fa7b" -dependencies = [ - "toml_edit", -] - [[package]] name = "proc-macro2" version = "1.0.86" @@ -2293,49 +1264,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "prost" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b2ecbe40f08db5c006b5764a2645f7f3f141ce756412ac9e1dd6087e6d32995" -dependencies = [ - "bytes", - "prost-derive", -] - -[[package]] -name = "prost-derive" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acf0c195eebb4af52c752bec4f52f645da98b6e92077a04110c7f349477ae5ac" -dependencies = [ - "anyhow", - "itertools", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "prost-reflect" -version = "0.14.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b7535b02f0e5efe3e1dbfcb428be152226ed0c66cad9541f2274c8ba8d4cd40" -dependencies = [ - "once_cell", - "prost", - "prost-types", -] - -[[package]] -name = "prost-types" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60caa6738c7369b940c3d49246a8d1749323674c65cb13010134f5c9bad5b519" -dependencies = [ - "prost", -] - [[package]] name = "quanta" version = "0.12.3" @@ -2396,7 +1324,7 @@ version = "11.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb9ee317cfe3fbd54b36a511efc1edd42e216903c9cd575e686dd68a2ba90d8d" dependencies = [ - "bitflags 2.6.0", + "bitflags", ] [[package]] @@ -2405,18 +1333,7 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" dependencies = [ - "bitflags 2.6.0", -] - -[[package]] -name = "reflink-copy" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc31414597d1cd7fdd2422798b7652a6329dda0fe0219e6335a13d5bcaa9aeb6" -dependencies = [ - "cfg-if", - "rustix", - "windows", + "bitflags", ] [[package]] @@ -2463,47 +1380,6 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" -[[package]] -name = "reqwest" -version = "0.11.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd67538700a17451e7cba03ac727fb961abb7607553461627b97de0b89cf4a62" -dependencies = [ - "base64 0.21.7", - "bytes", - "encoding_rs", - "futures-core", - "futures-util", - "h2 0.3.26", - "http 0.2.12", - "http-body 0.4.6", - "hyper 0.14.30", - "hyper-tls 0.5.0", - "ipnet", - "js-sys", - "log", - "mime", - "mime_guess", - "native-tls", - "once_cell", - "percent-encoding", - "pin-project-lite", - "rustls-pemfile 1.0.4", - "serde", - "serde_json", - "serde_urlencoded", - "sync_wrapper 0.1.2", - "system-configuration 0.5.1", - "tokio", - "tokio-native-tls", - "tower-service", - "url", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", - "winreg", -] - [[package]] name = "reqwest" version = "0.12.7" @@ -2515,13 +1391,13 @@ dependencies = [ "encoding_rs", "futures-core", "futures-util", - "h2 0.4.6", - "http 1.1.0", - "http-body 1.0.1", + "h2", + "http", + "http-body", "http-body-util", - "hyper 1.4.1", + "hyper", "hyper-rustls", - "hyper-tls 0.6.0", + "hyper-tls", "hyper-util", "ipnet", "js-sys", @@ -2531,12 +1407,12 @@ dependencies = [ "once_cell", "percent-encoding", "pin-project-lite", - "rustls-pemfile 2.1.3", + "rustls-pemfile", "serde", "serde_json", "serde_urlencoded", "sync_wrapper 1.0.1", - "system-configuration 0.6.1", + "system-configuration", "tokio", "tokio-native-tls", "tower-service", @@ -2547,21 +1423,6 @@ dependencies = [ "windows-registry", ] -[[package]] -name = "reqwest-middleware" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a735987236a8e238bf0296c7e351b999c188ccc11477f311b82b55c93984216" -dependencies = [ - "anyhow", - "async-trait", - "http 0.2.12", - "reqwest 0.11.27", - "serde", - "task-local-extensions", - "thiserror", -] - [[package]] name = "ring" version = "0.17.8" @@ -2583,22 +1444,13 @@ version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" -[[package]] -name = "rustc_version" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" -dependencies = [ - "semver", -] - [[package]] name = "rustix" version = "0.38.35" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a85d50532239da68e9addb745ba38ff4612a242c1c7ceea689c4bc7c2f43c36f" dependencies = [ - "bitflags 2.6.0", + "bitflags", "errno", "libc", "linux-raw-sys", @@ -2612,19 +1464,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c58f8c84392efc0a126acce10fa59ff7b3d2ac06ab451a33f2741989b806b044" dependencies = [ "once_cell", - "rustls-pki-types", - "rustls-webpki", - "subtle", - "zeroize", -] - -[[package]] -name = "rustls-pemfile" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" -dependencies = [ - "base64 0.21.7", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", ] [[package]] @@ -2666,15 +1509,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "same-file" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" -dependencies = [ - "winapi-util", -] - [[package]] name = "schannel" version = "0.1.23" @@ -2684,30 +1518,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "schemars" -version = "0.8.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09c024468a378b7e36765cd36702b7a90cc3cba11654f6685c8f233408e89e92" -dependencies = [ - "dyn-clone", - "schemars_derive", - "serde", - "serde_json", -] - -[[package]] -name = "schemars_derive" -version = "0.8.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1eee588578aff73f856ab961cd2f79e36bc45d7ded33a7562adba4667aecc0e" -dependencies = [ - "proc-macro2", - "quote", - "serde_derive_internals", - "syn", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -2720,7 +1530,7 @@ version = "2.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" dependencies = [ - "bitflags 2.6.0", + "bitflags", "core-foundation", "core-foundation-sys", "libc", @@ -2737,12 +1547,6 @@ dependencies = [ "libc", ] -[[package]] -name = "semver" -version = "1.0.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" - [[package]] name = "serde" version = "1.0.210" @@ -2763,17 +1567,6 @@ dependencies = [ "syn", ] -[[package]] -name = "serde_derive_internals" -version = "0.29.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "serde_json" version = "1.0.127" @@ -2787,16 +1580,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_json_borrow" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "176a77dea19cf9b2cfe7f9e31966112ef8282a709af7c0a0fb28fc6347c7ba78" -dependencies = [ - "serde", - "serde_json", -] - [[package]] name = "serde_path_to_error" version = "0.1.16" @@ -2819,39 +1602,6 @@ dependencies = [ "serde", ] -[[package]] -name = "sha-1" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5058ada175748e33390e40e872bd0fe59a19f265d0158daa551c5a88a76009c" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "sha1" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "sha2" -version = "0.10.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - [[package]] name = "sharded-slab" version = "0.1.7" @@ -2928,105 +1678,12 @@ dependencies = [ "lock_api", ] -[[package]] -name = "ssddOnTop" -version = "0.1.0" -dependencies = [ - "anyhow", - "async-graphql", - "async-graphql-value", - "async-recursion", - "async-trait", - "bytes", - "convert_case 0.6.0", - "derive-getters", - "derive_more", - "derive_setters", - "futures-util", - "fxhash", - "http 1.1.0", - "http-body-util", - "http-cache", - "http-cache-reqwest", - "http-cache-semantics", - "hyper 1.4.1", - "hyper-util", - "indenter", - "indexmap", - "macros", - "macros_common", - "moka", - "nom", - "num_cpus", - "pretty_assertions", - "prost-reflect", - "reqwest 0.11.27", - "reqwest-middleware", - "schemars", - "serde", - "serde_json", - "serde_json_borrow", - "serde_path_to_error", - "strum_macros", - "test-log", - "tokio", - "tracing", - "tracing-subscriber", - "ttl_cache", - "url", -] - -[[package]] -name = "ssri" -version = "9.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da7a2b3c2bc9693bcb40870c4e9b5bf0d79f9cb46273321bf855ec513e919082" -dependencies = [ - "base64 0.21.7", - "digest", - "hex", - "miette", - "serde", - "sha-1", - "sha2", - "thiserror", - "xxhash-rust", -] - -[[package]] -name = "static_assertions_next" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7beae5182595e9a8b683fa98c4317f956c9a2dec3b9716990d20023cc60c766" - [[package]] name = "strsim" version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" -[[package]] -name = "strum" -version = "0.26.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" -dependencies = [ - "strum_macros", -] - -[[package]] -name = "strum_macros" -version = "0.26.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "rustversion", - "syn", -] - [[package]] name = "subtle" version = "2.6.1" @@ -3059,36 +1716,15 @@ dependencies = [ "futures-core", ] -[[package]] -name = "system-configuration" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" -dependencies = [ - "bitflags 1.3.2", - "core-foundation", - "system-configuration-sys 0.5.0", -] - [[package]] name = "system-configuration" version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" dependencies = [ - "bitflags 2.6.0", + "bitflags", "core-foundation", - "system-configuration-sys 0.6.0", -] - -[[package]] -name = "system-configuration-sys" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" -dependencies = [ - "core-foundation-sys", - "libc", + "system-configuration-sys", ] [[package]] @@ -3101,21 +1737,6 @@ dependencies = [ "libc", ] -[[package]] -name = "tagptr" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b2093cf4c8eb1e67749a6762251bc9cd836b6fc171623bd0a9d324d37af2417" - -[[package]] -name = "task-local-extensions" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba323866e5d033818e3240feeb9f7db2c4296674e4d9e16b97b7bf8f490434e8" -dependencies = [ - "pin-utils", -] - [[package]] name = "tempfile" version = "3.12.0" @@ -3129,28 +1750,6 @@ dependencies = [ "windows-sys 0.59.0", ] -[[package]] -name = "test-log" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dffced63c2b5c7be278154d76b479f9f9920ed34e7574201407f0b14e2bbb93" -dependencies = [ - "env_logger", - "test-log-macros", - "tracing-subscriber", -] - -[[package]] -name = "test-log-macros" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5999e24eaa32083191ba4e425deb75cdf25efefabe5aaccb7446dd0d4122a3f5" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "thiserror" version = "1.0.63" @@ -3290,23 +1889,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "toml_datetime" -version = "0.6.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" - -[[package]] -name = "toml_edit" -version = "0.22.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" -dependencies = [ - "indexmap", - "toml_datetime", - "winnow", -] - [[package]] name = "tower" version = "0.4.13" @@ -3344,7 +1926,7 @@ dependencies = [ "axum", "forwarded-header-value", "governor", - "http 1.1.0", + "http", "pin-project", "thiserror", "tower", @@ -3413,27 +1995,12 @@ dependencies = [ "tracing-log", ] -[[package]] -name = "triomphe" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "859eb650cfee7434994602c3a68b25d77ad9e68c8a6cd491616ef86661382eb3" - [[package]] name = "try-lock" version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" -[[package]] -name = "ttl_cache" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4189890526f0168710b6ee65ceaedf1460c48a14318ceec933cb26baa492096a" -dependencies = [ - "linked-hash-map", -] - [[package]] name = "typed-builder" version = "0.18.2" @@ -3454,27 +2021,6 @@ dependencies = [ "syn", ] -[[package]] -name = "typenum" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" - -[[package]] -name = "ucd-trie" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" - -[[package]] -name = "unicase" -version = "2.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" -dependencies = [ - "version_check", -] - [[package]] name = "unicode-bidi" version = "0.3.15" @@ -3496,18 +2042,6 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "unicode-segmentation" -version = "1.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" - -[[package]] -name = "unicode-width" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" - [[package]] name = "untrusted" version = "0.9.0" @@ -3523,7 +2057,6 @@ dependencies = [ "form_urlencoded", "idna", "percent-encoding", - "serde", ] [[package]] @@ -3532,49 +2065,18 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" -[[package]] -name = "uuid" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81dfa00651efa65069b0b6b651f4aaa31ba9e3c3ce0137aaad053604ee7e0314" -dependencies = [ - "getrandom", -] - [[package]] name = "valuable" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" -[[package]] -name = "value-bag" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a84c137d37ab0142f0f2ddfe332651fdbf252e7b7dbb4e67b6c1f1b2e925101" - [[package]] name = "vcpkg" version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - -[[package]] -name = "walkdir" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" -dependencies = [ - "same-file", - "winapi-util", -] - [[package]] name = "want" version = "0.3.1" @@ -3683,31 +2185,12 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -[[package]] -name = "winapi-util" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows" -version = "0.58.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd04d41d93c4992d421894c18c8b43496aa748dd4c081bac0dc93eb0489272b6" -dependencies = [ - "windows-core 0.58.0", - "windows-targets 0.52.6", -] - [[package]] name = "windows-core" version = "0.52.0" @@ -3717,41 +2200,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-core" -version = "0.58.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99" -dependencies = [ - "windows-implement", - "windows-interface", - "windows-result", - "windows-strings", - "windows-targets 0.52.6", -] - -[[package]] -name = "windows-implement" -version = "0.58.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "windows-interface" -version = "0.58.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "windows-registry" version = "0.2.0" @@ -3930,37 +2378,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" -[[package]] -name = "winnow" -version = "0.6.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" -dependencies = [ - "memchr", -] - -[[package]] -name = "winreg" -version = "0.50.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" -dependencies = [ - "cfg-if", - "windows-sys 0.48.0", -] - -[[package]] -name = "xxhash-rust" -version = "0.8.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a5cbf750400958819fb6178eaa83bee5cd9c29a26a40cc241df8c70fdd46984" - -[[package]] -name = "yansi" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" - [[package]] name = "zerocopy" version = "0.7.35" diff --git a/Cargo.toml b/Cargo.toml index 8c82f3b..245d76d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,4 +21,4 @@ tracing = "0.1.40" tracing-subscriber = "0.3.18" [workspace] -members = ["mock-api", "projects/ssddOnTop"] +members = ["mock-api"] diff --git a/mock-api/src/database.rs b/mock-api/src/database.rs index 112a5d4..6d66a3c 100644 --- a/mock-api/src/database.rs +++ b/mock-api/src/database.rs @@ -24,12 +24,6 @@ fn geo_add_fractional_part(val: &mut f64) { } } -impl Default for Database { - fn default() -> Self { - Self::new() - } -} - impl Database { /// Initialize the database with random data pub fn new() -> Self { diff --git a/mock-api/src/lib.rs b/mock-api/src/lib.rs index f2cbc83..8bbb83a 100644 --- a/mock-api/src/lib.rs +++ b/mock-api/src/lib.rs @@ -14,7 +14,7 @@ pub struct AppState { impl Default for AppState { fn default() -> Self { let db = Database::new(); - db.reset().unwrap(); + let _ = db.reset().unwrap(); Self { db } } } @@ -66,9 +66,7 @@ impl IntoResponse for AppError { fn into_response(self) -> axum::response::Response { match self { AppError::NotFound(msg) => (StatusCode::NOT_FOUND, msg).into_response(), - AppError::InternalServerError(msg) => { - (StatusCode::INTERNAL_SERVER_ERROR, msg).into_response() - } + AppError::InternalServerError(msg) => (StatusCode::INTERNAL_SERVER_ERROR, msg).into_response(), } } } diff --git a/mock-api/src/main.rs b/mock-api/src/main.rs index e53a1d5..e213ca7 100644 --- a/mock-api/src/main.rs +++ b/mock-api/src/main.rs @@ -59,7 +59,7 @@ async fn main() { .layer(axum::middleware::from_fn( // This middleware is responsible to apply the delay functionality move |request: Request, next: Next| { - let delay = delay; + let delay = delay.clone(); async move { let response = next.run(request).await; tokio::time::sleep(delay).await; diff --git a/mock-api/src/routes/get_user.rs b/mock-api/src/routes/get_user.rs index 97f6e62..dbaf54f 100644 --- a/mock-api/src/routes/get_user.rs +++ b/mock-api/src/routes/get_user.rs @@ -16,9 +16,6 @@ pub async fn handle( let user_id = user_id.0; match state.db.user(user_id) { Some(user) => Ok(Json(user).into_response()), - None => Err(AppError::NotFound(format!( - "User with id {} not found", - user_id - ))), + None => Err(AppError::NotFound(format!("User with id {} not found", user_id))), } } diff --git a/projects/ssddOnTop/run.sh b/projects/ssddOnTop/run.sh index c75c909..3db4ae1 100755 --- a/projects/ssddOnTop/run.sh +++ b/projects/ssddOnTop/run.sh @@ -2,4 +2,4 @@ set -e -cargo run -p ssddOnTop #--release \ No newline at end of file +cargo run -p ssddOnTop --release \ No newline at end of file From 4696b607cf784db7da848a908df35eac24cd6e82 Mon Sep 17 00:00:00 2001 From: Sandipsinh Rathod Date: Thu, 12 Sep 2024 14:23:31 -0400 Subject: [PATCH 14/21] revert cargo --- Cargo.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index eb69c17..3730594 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -92,15 +92,15 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.88" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e1496f8fb1fbf272686b8d37f523dab3e4a7443300055e74cdaa449f3114356" +checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" [[package]] name = "async-trait" -version = "0.1.82" +version = "0.1.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a27b8a3a6e1a44fa4c8baf1f653e4172e81486d4941f2237e20dc2d0cf4ddff1" +checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107" dependencies = [ "proc-macro2", "quote", @@ -751,9 +751,9 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.8" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da62f120a8a37763efb0cf8fdf264b884c7b8b9ac8660b900c8661030c00e6ba" +checksum = "cde7055719c54e36e95e8719f95883f22072a48ede39db7fc17a4e1d5281e9b9" dependencies = [ "bytes", "futures-channel", From 3ce51f6fffc0ef0e8abef917d72724fc66a25b01 Mon Sep 17 00:00:00 2001 From: Sandipsinh Rathod Date: Thu, 12 Sep 2024 16:54:18 -0400 Subject: [PATCH 15/21] some logical fixes --- projects/ssddOnTop/Cargo.lock | 66 +++++++++++++++++++ projects/ssddOnTop/Cargo.toml | 3 + projects/ssddOnTop/src/blueprint/blueprint.rs | 16 ++--- projects/ssddOnTop/src/blueprint/model.rs | 2 - 4 files changed, 74 insertions(+), 13 deletions(-) diff --git a/projects/ssddOnTop/Cargo.lock b/projects/ssddOnTop/Cargo.lock index 766906b..530415e 100644 --- a/projects/ssddOnTop/Cargo.lock +++ b/projects/ssddOnTop/Cargo.lock @@ -273,6 +273,17 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "async-recursion" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b43422f69d8ff38f95f1b2bb76517c91589a924d1559a0e935d7c8ce0274c11" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "async-signal" version = "0.2.10" @@ -686,6 +697,12 @@ dependencies = [ "crypto-common", ] +[[package]] +name = "dyn-clone" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" + [[package]] name = "either" version = "1.13.0" @@ -1351,11 +1368,21 @@ dependencies = [ name = "macros" version = "0.1.0" dependencies = [ + "anyhow", + "macros_common", "proc-macro2", "quote", "syn", ] +[[package]] +name = "macros_common" +version = "0.1.0" +dependencies = [ + "async-graphql", + "schemars", +] + [[package]] name = "matchers" version = "0.1.0" @@ -2035,6 +2062,30 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "schemars" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09c024468a378b7e36765cd36702b7a90cc3cba11654f6685c8f233408e89e92" +dependencies = [ + "dyn-clone", + "schemars_derive", + "serde", + "serde_json", +] + +[[package]] +name = "schemars_derive" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1eee588578aff73f856ab961cd2f79e36bc45d7ded33a7562adba4667aecc0e" +dependencies = [ + "proc-macro2", + "quote", + "serde_derive_internals", + "syn", +] + [[package]] name = "scopeguard" version = "1.2.0" @@ -2090,6 +2141,17 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_derive_internals" +version = "0.29.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "serde_json" version = "1.0.128" @@ -2229,6 +2291,7 @@ dependencies = [ "anyhow", "async-graphql", "async-graphql-value", + "async-recursion", "async-trait", "bytes", "convert_case 0.6.0", @@ -2246,6 +2309,8 @@ dependencies = [ "hyper-util", "indenter", "indexmap", + "macros", + "macros_common", "moka", "nom", "num_cpus", @@ -2253,6 +2318,7 @@ dependencies = [ "prost-reflect", "reqwest", "reqwest-middleware", + "schemars", "serde", "serde_json", "serde_json_borrow", diff --git a/projects/ssddOnTop/Cargo.toml b/projects/ssddOnTop/Cargo.toml index 8188147..ebfdaa9 100644 --- a/projects/ssddOnTop/Cargo.toml +++ b/projects/ssddOnTop/Cargo.toml @@ -52,3 +52,6 @@ async-recursion = "1.1.1" [dev-dependencies] http-cache = "0.18.0" + +[workspace] +members = [] diff --git a/projects/ssddOnTop/src/blueprint/blueprint.rs b/projects/ssddOnTop/src/blueprint/blueprint.rs index e49d5e0..917d0ce 100644 --- a/projects/ssddOnTop/src/blueprint/blueprint.rs +++ b/projects/ssddOnTop/src/blueprint/blueprint.rs @@ -133,14 +133,13 @@ impl TryFrom<&Config> for Blueprint { fn fields_to_map(qry: &str, config: &Config, defs: Vec) -> HashMap { let mut fields = HashMap::new(); - populate_nested_field(config, qry, 0, &mut fields, &defs); + populate_nested_field(config, qry, &mut fields, &defs); fields } fn populate_nested_field( config: &Config, ty_name: &str, - field_id: usize, field_map: &mut HashMap, defs: &[Definition], ) { @@ -149,10 +148,8 @@ fn populate_nested_field( if let Some(ty) = config.types.get(ty_name) { for (field_name, field) in ty.fields.iter() { let field_name = FieldName(field_name.clone()); - populate_nested_field(config, field.ty_of.name(), field_id + 1, field_map, defs); - let mut arg_id = 0; + populate_nested_field(config, field.ty_of.name(), field_map, defs); let field = Field { - id: FieldId::new(field_id), name: field_name.clone(), type_of: field.ty_of.clone(), ir: { @@ -160,13 +157,13 @@ fn populate_nested_field( Definition::Interface(int) => Some( int.fields .iter() - .find(|f| field_name.0.eq(&f.name))? + .find(|f| field_name.0.eq(&f.name) && int.name.eq(ty_name))? .clone(), ), Definition::Object(obj) => Some( obj.fields .iter() - .find(|f| field_name.0.eq(&f.name))? + .find(|f| field_name.0.eq(&f.name) && obj.name.eq(ty_name))? .clone(), ), Definition::InputObject(_) => None, @@ -180,12 +177,9 @@ fn populate_nested_field( .iter() .map(|(arg_name, arg)| { let arg = Arg { - id: ArgId::new(arg_id), name: arg_name.clone(), type_of: arg.type_of.clone(), }; - arg_id += 1; - arg }) .collect(), @@ -214,6 +208,6 @@ mod test { .read(format!("{}/schema/schema.graphql", root)) .unwrap(); let blueprint = crate::blueprint::Blueprint::try_from(&config).unwrap(); - // println!("{:#?}", blueprint); + println!("{:#?}", blueprint.fields ); } } diff --git a/projects/ssddOnTop/src/blueprint/model.rs b/projects/ssddOnTop/src/blueprint/model.rs index 64fa53c..f3fbdf3 100644 --- a/projects/ssddOnTop/src/blueprint/model.rs +++ b/projects/ssddOnTop/src/blueprint/model.rs @@ -48,7 +48,6 @@ impl FieldId { #[derive(Clone, Debug)] pub struct Arg { - pub id: ArgId, pub name: String, pub type_of: crate::blueprint::wrapping_type::Type, } @@ -60,7 +59,6 @@ pub struct Flat(FieldId); #[derive(Clone, Debug)] pub struct Field { - pub id: FieldId, pub name: FieldName, pub type_of: crate::blueprint::wrapping_type::Type, pub ir: Option, From fff15f965b5b0f14aceb1f054b9e03bb75e73f63 Mon Sep 17 00:00:00 2001 From: Sandipsinh Rathod Date: Thu, 12 Sep 2024 16:56:33 -0400 Subject: [PATCH 16/21] disable tracing --- projects/ssddOnTop/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/ssddOnTop/src/main.rs b/projects/ssddOnTop/src/main.rs index beb722b..c0fe75b 100644 --- a/projects/ssddOnTop/src/main.rs +++ b/projects/ssddOnTop/src/main.rs @@ -1,5 +1,5 @@ fn main() -> anyhow::Result<()> { - tracing_subscriber::fmt::init(); + // tracing_subscriber::fmt::init(); let rt = tokio::runtime::Builder::new_multi_thread() .worker_threads(num_cpus::get()) .enable_all() From 99c24520f3a538d83945b69ec74f79f957a7a99d Mon Sep 17 00:00:00 2001 From: Sandipsinh Rathod Date: Thu, 12 Sep 2024 17:04:46 -0400 Subject: [PATCH 17/21] allow unused tag --- projects/ssddOnTop/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/projects/ssddOnTop/src/lib.rs b/projects/ssddOnTop/src/lib.rs index 33c1e68..ccef48e 100644 --- a/projects/ssddOnTop/src/lib.rs +++ b/projects/ssddOnTop/src/lib.rs @@ -1,3 +1,4 @@ +#![allow(unused, non_snake_case)] mod app_ctx; mod blueprint; mod cache; From c31ab608e05c9fa89cf77b73730df00f97d34bc5 Mon Sep 17 00:00:00 2001 From: Sandipsinh Rathod Date: Thu, 12 Sep 2024 17:35:16 -0400 Subject: [PATCH 18/21] finalize to borrowed --- .../ssddOnTop/src/http/request_handler.rs | 4 +- projects/ssddOnTop/src/jit/model.rs | 131 ++++++++++-------- 2 files changed, 72 insertions(+), 63 deletions(-) diff --git a/projects/ssddOnTop/src/http/request_handler.rs b/projects/ssddOnTop/src/http/request_handler.rs index 66984f9..d775baf 100644 --- a/projects/ssddOnTop/src/http/request_handler.rs +++ b/projects/ssddOnTop/src/http/request_handler.rs @@ -44,9 +44,9 @@ async fn handle_gql_req( let borrowed_fields = fields.to_borrowed(); let resolved = fields.resolve(eval_ctx).await?; - let finalized = resolved.finalize(); + let borrowed_val = resolved.to_borrowed(); Ok(hyper::Response::new(Full::new(Bytes::from( - finalized.to_string(), + borrowed_val.finalize().to_string(), )))) } else { Ok(hyper::Response::new(Full::new(Bytes::from_static( diff --git a/projects/ssddOnTop/src/jit/model.rs b/projects/ssddOnTop/src/jit/model.rs index f3bf3fc..dd28db3 100644 --- a/projects/ssddOnTop/src/jit/model.rs +++ b/projects/ssddOnTop/src/jit/model.rs @@ -10,6 +10,7 @@ use serde_json::Map; use std::fmt::Debug; use std::future::Future; use std::pin::Pin; +use serde_json_borrow::ObjectAsVec; pub struct PathFinder<'a> { doc: ExecutableDocument, @@ -25,6 +26,75 @@ pub struct Fields1<'a> { fields: Vec>, } +fn to_borrowed(val: &Value) -> serde_json_borrow::Value { + serde_json_borrow::Value::from(val.serde()) +} + +impl<'a> Fields1<'a> { + #[inline(always)] + pub fn finalize(&'a self) -> serde_json_borrow::Value<'a> { + let mut map = ObjectAsVec::new(); + for field in self.fields.iter() { + let name = field.name; + let val = Self::finalize_inner(field, None, None); + map.insert(name, val); + } + let mut ans = ObjectAsVec::new(); + ans.insert("data", serde_json_borrow::Value::Object(map)); + // map.insert("data".to_string(), self.finalize_inner()); + // serde_json::Value::Object(map) + serde_json_borrow::Value::Object(ans) + } + #[inline(always)] + fn finalize_inner(field: &'a Field1<'a>, mut value: Option>, index: Option) -> serde_json_borrow::Value<'a> { + if let Some(val) = &field.resolved { + if value.is_none() { + value = Some(val.clone()); + } + } + if let Some(val) = value.clone(){ + match (val.as_array(), val.as_object()) { + (_, Some(obj)) => { + // let mut ans = Map::new(); + let mut ans = ObjectAsVec::new(); + + if field.nested.is_empty() { + let val = obj.get_key(field.name); + let value = Self::finalize_inner(field, val.cloned(), index); + ans.insert(field.name, value); + } else { + for child in field.nested.iter() { + let child_name = child.name; + let val = obj.get_key(child.name).cloned(); + let val = Self::finalize_inner(child, val, index); + ans.insert(child_name, val); + } + } + + serde_json_borrow::Value::Object(ans) + } + (Some(arr), _) => { + if let Some(index) = index { + let val = arr.get(index).cloned(); + let val = Self::finalize_inner(field, val, None); + val + } else { + let mut ans = vec![]; + for (i, val) in arr.iter().enumerate() { + let val = Self::finalize_inner(field, Some(val.clone()), Some(i)); + ans.push(val); + } + serde_json_borrow::Value::Array(ans) + } + } + _ => value.unwrap_or_default(), + } + } else { + serde_json_borrow::Value::Null + } + } +} + #[derive(Debug)] // TODO: give it a lifetime // it won't make much difference.. @@ -76,67 +146,6 @@ pub struct Field1<'a> { pub resolved: Option>, } impl Fields { - #[inline(always)] - pub fn finalize(self) -> serde_json::Value { - let mut map = Map::new(); - for field in self.fields.iter() { - let name = field.name.as_str().to_string(); - let val = Self::finalize_inner(field, None, None); - map.insert(name, val); - } - let mut ans = Map::new(); - ans.insert("data".to_string(), serde_json::Value::Object(map)); - // map.insert("data".to_string(), self.finalize_inner()); - // serde_json::Value::Object(map) - serde_json::Value::Object(ans) - } - #[inline(always)] - fn finalize_inner<'a>(field: &'a Field, mut value: Option<&'a serde_json::Value>, index: Option) -> serde_json::Value { - if let Some(val) = &field.resolved { - if value.is_none() { - value = Some(val.serde()); - } - } - if let Some(val) = value { - match (val.as_array(), val.as_object()) { - (_, Some(obj)) => { - let mut ans = Map::new(); - - if field.nested.is_empty() { - let val = obj.get_key(field.name.as_str()); - let value = Self::finalize_inner(field, val, index); - ans.insert(field.name.as_str().to_string(), value); - } else { - for child in field.nested.iter() { - let child_name = child.name.as_str().to_string(); - let val = obj.get_key(child.name.as_str()); - let val = Self::finalize_inner(child, val, index); - ans.insert(child_name, val); - } - } - - serde_json::Value::Object(ans) - } - (Some(arr), _) => { - if let Some(index) = index { - let val = arr.get(index); - let val = Self::finalize_inner(field, val, None); - val - } else { - let mut ans = vec![]; - for (i, val) in arr.iter().enumerate() { - let val = Self::finalize_inner(field, Some(val), Some(i)); - ans.push(val); - } - serde_json::Value::Array(ans) - } - } - _ => value.cloned().unwrap_or_default(), - } - } else { - serde_json::Value::Null - } - } #[inline(always)] pub async fn resolve<'a>(mut self, eval_context: EvalContext<'a>) -> anyhow::Result { let mut ans = vec![]; From 71278a5d8cb7e70c06294d081d65621885e85320 Mon Sep 17 00:00:00 2001 From: Sandipsinh Rathod Date: Thu, 12 Sep 2024 17:40:48 -0400 Subject: [PATCH 19/21] reduce clones --- projects/ssddOnTop/src/jit/model.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/projects/ssddOnTop/src/jit/model.rs b/projects/ssddOnTop/src/jit/model.rs index dd28db3..924d0a2 100644 --- a/projects/ssddOnTop/src/jit/model.rs +++ b/projects/ssddOnTop/src/jit/model.rs @@ -46,10 +46,10 @@ impl<'a> Fields1<'a> { serde_json_borrow::Value::Object(ans) } #[inline(always)] - fn finalize_inner(field: &'a Field1<'a>, mut value: Option>, index: Option) -> serde_json_borrow::Value<'a> { + fn finalize_inner(field: &'a Field1<'a>, mut value: Option<&'a serde_json_borrow::Value<'a>>, index: Option) -> serde_json_borrow::Value<'a> { if let Some(val) = &field.resolved { if value.is_none() { - value = Some(val.clone()); + value = Some(val); } } if let Some(val) = value.clone(){ @@ -60,12 +60,12 @@ impl<'a> Fields1<'a> { if field.nested.is_empty() { let val = obj.get_key(field.name); - let value = Self::finalize_inner(field, val.cloned(), index); + let value = Self::finalize_inner(field, val, index); ans.insert(field.name, value); } else { for child in field.nested.iter() { let child_name = child.name; - let val = obj.get_key(child.name).cloned(); + let val = obj.get_key(child.name); let val = Self::finalize_inner(child, val, index); ans.insert(child_name, val); } @@ -75,19 +75,19 @@ impl<'a> Fields1<'a> { } (Some(arr), _) => { if let Some(index) = index { - let val = arr.get(index).cloned(); + let val = arr.get(index); let val = Self::finalize_inner(field, val, None); val } else { let mut ans = vec![]; for (i, val) in arr.iter().enumerate() { - let val = Self::finalize_inner(field, Some(val.clone()), Some(i)); + let val = Self::finalize_inner(field, Some(val), Some(i)); ans.push(val); } serde_json_borrow::Value::Array(ans) } } - _ => value.unwrap_or_default(), + _ => value.cloned().unwrap_or_default(), } } else { serde_json_borrow::Value::Null @@ -162,25 +162,25 @@ impl Fields { for mut field in fields { let mut parent_val = None; - if let Some(ir) = field.ir.clone() { + if let Some(ir) = field.ir.as_ref() { if let Some(val) = field.args.clone() { eval_context = eval_context.with_args(val); } let val = match &parent { Some(val) => { - match val.clone().into_serde() { + match val.serde() { serde_json::Value::Array(arr) => { let mut ans = vec![]; for val in arr { - eval_context = eval_context.with_value(Value::new(val)); + eval_context = eval_context.with_value(Value::new(val.clone())); let val = ir.eval(&mut eval_context.clone()).await?; ans.push(val.into_serde()); } Some(Value::new(serde_json::Value::Array(ans))) } val => { - eval_context = eval_context.with_value(Value::new(val)); + eval_context = eval_context.with_value(Value::new(val.clone())); let val = ir.eval(&mut eval_context.clone()).await?; Some(val) } From 75913af845cfc01d9fe6467a684a5729b8fb52d5 Mon Sep 17 00:00:00 2001 From: Sandipsinh Rathod Date: Thu, 12 Sep 2024 18:26:04 -0400 Subject: [PATCH 20/21] reduce clones --- projects/ssddOnTop/src/jit/model.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/ssddOnTop/src/jit/model.rs b/projects/ssddOnTop/src/jit/model.rs index 924d0a2..df68c88 100644 --- a/projects/ssddOnTop/src/jit/model.rs +++ b/projects/ssddOnTop/src/jit/model.rs @@ -52,7 +52,7 @@ impl<'a> Fields1<'a> { value = Some(val); } } - if let Some(val) = value.clone(){ + if let Some(val) = value{ match (val.as_array(), val.as_object()) { (_, Some(obj)) => { // let mut ans = Map::new(); From 13be82d15f6cf9d004627d4271d1434b09cbc7ae Mon Sep 17 00:00:00 2001 From: Sandipsinh Rathod Date: Fri, 13 Sep 2024 09:18:52 -0400 Subject: [PATCH 21/21] remove some deps --- projects/ssddOnTop/Cargo.lock | 319 +--------------------------------- projects/ssddOnTop/Cargo.toml | 6 - 2 files changed, 4 insertions(+), 321 deletions(-) diff --git a/projects/ssddOnTop/Cargo.lock b/projects/ssddOnTop/Cargo.lock index 530415e..b713eb7 100644 --- a/projects/ssddOnTop/Cargo.lock +++ b/projects/ssddOnTop/Cargo.lock @@ -36,55 +36,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "anstream" -version = "0.6.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" -dependencies = [ - "anstyle", - "anstyle-parse", - "anstyle-query", - "anstyle-wincon", - "colorchoice", - "is_terminal_polyfill", - "utf8parse", -] - -[[package]] -name = "anstyle" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" - -[[package]] -name = "anstyle-parse" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" -dependencies = [ - "utf8parse", -] - -[[package]] -name = "anstyle-query" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" -dependencies = [ - "windows-sys 0.52.0", -] - -[[package]] -name = "anstyle-wincon" -version = "3.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" -dependencies = [ - "anstyle", - "windows-sys 0.52.0", -] - [[package]] name = "anyhow" version = "1.0.88" @@ -273,17 +224,6 @@ dependencies = [ "windows-sys 0.59.0", ] -[[package]] -name = "async-recursion" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b43422f69d8ff38f95f1b2bb76517c91589a924d1559a0e935d7c8ce0274c11" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "async-signal" version = "0.2.10" @@ -512,12 +452,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "colorchoice" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" - [[package]] name = "concurrent-queue" version = "2.5.0" @@ -533,15 +467,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" -[[package]] -name = "convert_case" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" -dependencies = [ - "unicode-segmentation", -] - [[package]] name = "core-foundation" version = "0.9.4" @@ -662,7 +587,7 @@ version = "0.99.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" dependencies = [ - "convert_case 0.4.0", + "convert_case", "proc-macro2", "quote", "rustc_version", @@ -681,12 +606,6 @@ dependencies = [ "syn", ] -[[package]] -name = "diff" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" - [[package]] name = "digest" version = "0.10.7" @@ -718,27 +637,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "env_filter" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f2c92ceda6ceec50f43169f9ee8424fe2db276791afde7b2cd8bc084cb376ab" -dependencies = [ - "log", -] - -[[package]] -name = "env_logger" -version = "0.11.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13fa619b91fb2381732789fc5de83b45675e882f66623b7d8cb4f643017018d" -dependencies = [ - "anstream", - "anstyle", - "env_filter", - "log", -] - [[package]] name = "equivalent" version = "1.0.1" @@ -1282,21 +1180,6 @@ version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "187674a687eed5fe42285b40c6291f9a01517d415fad1c3cbc6a9f778af7fcd4" -[[package]] -name = "is_terminal_polyfill" -version = "1.70.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" - -[[package]] -name = "itertools" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" -dependencies = [ - "either", -] - [[package]] name = "itoa" version = "1.0.11" @@ -1383,15 +1266,6 @@ dependencies = [ "schemars", ] -[[package]] -name = "matchers" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" -dependencies = [ - "regex-automata 0.1.10", -] - [[package]] name = "memchr" version = "2.7.4" @@ -1541,16 +1415,6 @@ dependencies = [ "minimal-lexical", ] -[[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-conv" version = "0.1.0" @@ -1635,12 +1499,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" version = "2.2.1" @@ -1771,16 +1629,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" -[[package]] -name = "pretty_assertions" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af7cee1a6c8a5b9208b3cb1061f10c0cb689087b3d8ce85fb9d2dd7a29b6ba66" -dependencies = [ - "diff", - "yansi", -] - [[package]] name = "proc-macro-crate" version = "3.2.0" @@ -1799,49 +1647,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "prost" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b2ecbe40f08db5c006b5764a2645f7f3f141ce756412ac9e1dd6087e6d32995" -dependencies = [ - "bytes", - "prost-derive", -] - -[[package]] -name = "prost-derive" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acf0c195eebb4af52c752bec4f52f645da98b6e92077a04110c7f349477ae5ac" -dependencies = [ - "anyhow", - "itertools", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "prost-reflect" -version = "0.14.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b7535b02f0e5efe3e1dbfcb428be152226ed0c66cad9541f2274c8ba8d4cd40" -dependencies = [ - "once_cell", - "prost", - "prost-types", -] - -[[package]] -name = "prost-types" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60caa6738c7369b940c3d49246a8d1749323674c65cb13010134f5c9bad5b519" -dependencies = [ - "prost", -] - [[package]] name = "quanta" version = "0.12.3" @@ -1903,17 +1708,8 @@ checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.4.7", - "regex-syntax 0.8.4", -] - -[[package]] -name = "regex-automata" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" -dependencies = [ - "regex-syntax 0.6.29", + "regex-automata", + "regex-syntax", ] [[package]] @@ -1924,15 +1720,9 @@ checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.8.4", + "regex-syntax", ] -[[package]] -name = "regex-syntax" -version = "0.6.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" - [[package]] name = "regex-syntax" version = "0.8.4" @@ -2229,15 +2019,6 @@ dependencies = [ "digest", ] -[[package]] -name = "sharded-slab" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" -dependencies = [ - "lazy_static", -] - [[package]] name = "shlex" version = "1.3.0" @@ -2291,10 +2072,8 @@ dependencies = [ "anyhow", "async-graphql", "async-graphql-value", - "async-recursion", "async-trait", "bytes", - "convert_case 0.6.0", "derive-getters", "derive_more", "derive_setters", @@ -2314,8 +2093,6 @@ dependencies = [ "moka", "nom", "num_cpus", - "pretty_assertions", - "prost-reflect", "reqwest", "reqwest-middleware", "schemars", @@ -2324,10 +2101,8 @@ dependencies = [ "serde_json_borrow", "serde_path_to_error", "strum_macros", - "test-log", "tokio", "tracing", - "tracing-subscriber", "ttl_cache", "url", ] @@ -2449,28 +2224,6 @@ dependencies = [ "windows-sys 0.59.0", ] -[[package]] -name = "test-log" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dffced63c2b5c7be278154d76b479f9f9920ed34e7574201407f0b14e2bbb93" -dependencies = [ - "env_logger", - "test-log-macros", - "tracing-subscriber", -] - -[[package]] -name = "test-log-macros" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5999e24eaa32083191ba4e425deb75cdf25efefabe5aaccb7446dd0d4122a3f5" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "thiserror" version = "1.0.63" @@ -2491,16 +2244,6 @@ dependencies = [ "syn", ] -[[package]] -name = "thread_local" -version = "1.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" -dependencies = [ - "cfg-if", - "once_cell", -] - [[package]] name = "time" version = "0.3.36" @@ -2651,36 +2394,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ "once_cell", - "valuable", -] - -[[package]] -name = "tracing-log" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" -dependencies = [ - "log", - "once_cell", - "tracing-core", -] - -[[package]] -name = "tracing-subscriber" -version = "0.3.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" -dependencies = [ - "matchers", - "nu-ansi-term", - "once_cell", - "regex", - "sharded-slab", - "smallvec", - "thread_local", - "tracing", - "tracing-core", - "tracing-log", ] [[package]] @@ -2746,12 +2459,6 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "unicode-segmentation" -version = "1.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" - [[package]] name = "unicode-width" version = "0.1.13" @@ -2770,12 +2477,6 @@ dependencies = [ "serde", ] -[[package]] -name = "utf8parse" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" - [[package]] name = "uuid" version = "1.10.0" @@ -2785,12 +2486,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "valuable" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" - [[package]] name = "value-bag" version = "1.9.0" @@ -3178,9 +2873,3 @@ name = "xxhash-rust" version = "0.8.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a5cbf750400958819fb6178eaa83bee5cd9c29a26a40cc241df8c70fdd46984" - -[[package]] -name = "yansi" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" diff --git a/projects/ssddOnTop/Cargo.toml b/projects/ssddOnTop/Cargo.toml index ebfdaa9..9230540 100644 --- a/projects/ssddOnTop/Cargo.toml +++ b/projects/ssddOnTop/Cargo.toml @@ -18,20 +18,15 @@ serde_json = "1.0.127" serde = { version = "1.0.210", features = ["derive"] } async-graphql-value = "7.0.9" serde_path_to_error = "0.1.16" -tracing-subscriber = "0.3.18" num_cpus = "1.16.0" reqwest = "0.11" nom = "7.1.3" -pretty_assertions = "1.4.0" serde_json_borrow = "0.6.0" derive-getters = "0.5.0" indexmap = "2.5.0" derive_more = "0.99.18" indenter = "0.3.3" derive_setters = "0.1.6" -test-log = "0.2.16" -convert_case = "0.6.0" -prost-reflect = "0.14.2" fxhash = "0.2.1" strum_macros = "0.26.4" http-cache-reqwest = { version = "0.13.0", features = [ @@ -48,7 +43,6 @@ futures-util = "0.3.30" http = "1.1.0" url = "2.5.2" schemars = {version = "0.8.17", features = ["derive"]} -async-recursion = "1.1.1" [dev-dependencies] http-cache = "0.18.0"