From 43acb93dd1cca8f72768e184b2788c4ee0c0fb88 Mon Sep 17 00:00:00 2001 From: JasterV <49537445+JasterV@users.noreply.github.com> Date: Tue, 24 Mar 2026 00:39:47 +0100 Subject: [PATCH] refactor: use streams for stream responses --- Cargo.lock | 391 ++++++++++-------- Cargo.toml | 1 + granc-core/Cargo.toml | 2 +- .../src/client/online_without_reflection.rs | 14 +- granc-core/src/client/types.rs | 4 +- granc-core/src/grpc/client.rs | 10 +- granc-core/tests/granc_client_online_test.rs | 5 +- ...c_client_online_without_reflection_test.rs | 9 +- granc/Cargo.toml | 1 + granc/src/formatter.rs | 27 +- granc/src/main.rs | 13 +- 11 files changed, 274 insertions(+), 203 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 75af6cc..176862d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,9 +13,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.21" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a" +checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d" dependencies = [ "anstyle", "anstyle-parse", @@ -28,15 +28,15 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.13" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78" +checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000" [[package]] name = "anstyle-parse" -version = "0.2.7" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" +checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e" dependencies = [ "utf8parse", ] @@ -47,7 +47,7 @@ version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" dependencies = [ - "windows-sys 0.61.2", + "windows-sys", ] [[package]] @@ -58,14 +58,14 @@ checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" dependencies = [ "anstyle", "once_cell_polyfill", - "windows-sys 0.61.2", + "windows-sys", ] [[package]] name = "anyhow" -version = "1.0.101" +version = "1.0.102" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f0e0fee31ef5ed1ba1316088939cea399010ed7731dba877ed44aeb407a75ea" +checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" [[package]] name = "async-trait" @@ -141,9 +141,9 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "bitflags" -version = "2.10.0" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" +checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" [[package]] name = "bytes" @@ -159,9 +159,9 @@ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" [[package]] name = "clap" -version = "4.5.60" +version = "4.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2797f34da339ce31042b27d23607e051786132987f595b02ba4f6a6dffb7030a" +checksum = "b193af5b67834b676abd72466a96c1024e6a6ad978a1f484bd90b85c94041351" dependencies = [ "clap_builder", "clap_derive", @@ -169,9 +169,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.60" +version = "4.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24a241312cea5059b13574bb9b3861cabf758b879c15190b37b6d6fd63ab6876" +checksum = "714a53001bf66416adb0e2ef5ac857140e7dc3a0c48fb28b2f10762fc4b5069f" dependencies = [ "anstream", "anstyle", @@ -181,9 +181,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.55" +version = "4.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a92793da1a46a5f2a02a6f4c46c6496b28c43638adea8306fcb0caa1634f24e5" +checksum = "1110bd8a634a1ab8cb04345d8d878267d57c3cf1b38d91b71af6686408bbca6a" dependencies = [ "heck", "proc-macro2", @@ -193,15 +193,15 @@ dependencies = [ [[package]] name = "clap_lex" -version = "1.0.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a822ea5bc7590f9d40f1ba12c0dc3c2760f3482c6984db1573ad11031420831" +checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9" [[package]] name = "colorchoice" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" +checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570" [[package]] name = "colored" @@ -209,7 +209,7 @@ version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "faf9468729b8cbcea668e36183cb69d317348c2e08e994829fb56ebfdfbaac34" dependencies = [ - "windows-sys 0.61.2", + "windows-sys", ] [[package]] @@ -231,7 +231,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.61.2", + "windows-sys", ] [[package]] @@ -260,9 +260,9 @@ checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" [[package]] name = "futures-channel" -version = "0.3.31" +version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" +checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d" dependencies = [ "futures-core", ] @@ -286,9 +286,9 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.31" +version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" +checksum = "c39754e157331b013978ec91992bde1ac089843443c49cbc7f46150b0fad0893" [[package]] name = "futures-task" @@ -311,14 +311,15 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.3.4" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" +checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555" dependencies = [ "cfg-if", "libc", "r-efi", "wasip2", + "wasip3", ] [[package]] @@ -327,8 +328,9 @@ version = "0.7.4" dependencies = [ "clap", "colored", + "futures-util", "granc-test-support", - "granc_core 0.6.1", + "granc_core", "serde_json", "tokio", ] @@ -347,26 +349,6 @@ dependencies = [ "tonic-prost-build", ] -[[package]] -name = "granc_core" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12684196af508c702e011ed6d6c3272c089b562fdd7a3e4d481d91859f7cfb89" -dependencies = [ - "futures-util", - "http", - "http-body", - "prost", - "prost-reflect", - "prost-types", - "serde_json", - "thiserror", - "tokio", - "tokio-stream", - "tonic", - "tonic-reflection", -] - [[package]] name = "granc_core" version = "0.6.2" @@ -527,6 +509,12 @@ dependencies = [ "tracing", ] +[[package]] +name = "id-arena" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" + [[package]] name = "indexmap" version = "2.13.0" @@ -535,6 +523,8 @@ checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" dependencies = [ "equivalent", "hashbrown 0.16.1", + "serde", + "serde_core", ] [[package]] @@ -554,15 +544,21 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.17" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] +name = "leb128fmt" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" [[package]] name = "libc" -version = "0.2.182" +version = "0.2.183" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6800badb6cb2082ffd7b6a67e6125bb39f18782f793520caee8cb8846be06112" +checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d" [[package]] name = "linux-raw-sys" @@ -584,9 +580,9 @@ checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3" [[package]] name = "memchr" -version = "2.7.6" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" +checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" [[package]] name = "mime" @@ -602,7 +598,7 @@ checksum = "a69bcab0ad47271a0234d9422b131806bf3968021e5dc9328caf2d4cd58557fc" dependencies = [ "libc", "wasi", - "windows-sys 0.61.2", + "windows-sys", ] [[package]] @@ -622,9 +618,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.21.3" +version = "1.21.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" [[package]] name = "once_cell_polyfill" @@ -660,18 +656,18 @@ dependencies = [ [[package]] name = "pin-project" -version = "1.1.10" +version = "1.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677f1add503faace112b9f1373e43e9e054bfdd22ff1a63c1bc485eaec6a6a8a" +checksum = "f1749c7ed4bcaf4c3d0a3efc28538844fb29bcdd7d2b67b2be7e20ba861ff517" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.10" +version = "1.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e918e4ff8c4549eb882f14b3a4bc8c8bc93de829416eacf579f1207a8fbf861" +checksum = "d9b20ed30f105399776b9c883e68e536ef602a16ae6f596d2c473591d6ad64c6" dependencies = [ "proc-macro2", "quote", @@ -680,9 +676,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" [[package]] name = "pin-utils" @@ -777,9 +773,9 @@ dependencies = [ [[package]] name = "pulldown-cmark" -version = "0.13.0" +version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e8bbe1a966bd2f362681a44f6edce3c2310ac21e4d5067a6e7ec396297a6ea0" +checksum = "7c3a14896dfa883796f1cb410461aef38810ea05f2b2c33c5aded3649095fdad" dependencies = [ "bitflags", "memchr", @@ -797,18 +793,18 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.44" +version = "1.0.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4" +checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" dependencies = [ "proc-macro2", ] [[package]] name = "r-efi" -version = "5.3.0" +version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" [[package]] name = "regex" @@ -835,9 +831,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.9" +version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a96887878f22d7bad8a3b6dc5b7440e0ada9a245242924394987b21cf2210a4c" +checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a" [[package]] name = "rustix" @@ -849,9 +845,15 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys 0.61.2", + "windows-sys", ] +[[package]] +name = "semver" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2" + [[package]] name = "serde" version = "1.0.228" @@ -918,12 +920,12 @@ checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" [[package]] name = "socket2" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86f4aa3ad99f2088c990dfa82d367e19cb29268ed67c574d10d0a4bfe71f07e0" +checksum = "3a766e1110788c36f4fa1c2b71b387a7815aa65f88ce0229841826633d93723e" dependencies = [ "libc", - "windows-sys 0.60.2", + "windows-sys", ] [[package]] @@ -934,9 +936,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "syn" -version = "2.0.114" +version = "2.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" dependencies = [ "proc-macro2", "quote", @@ -951,15 +953,15 @@ checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" [[package]] name = "tempfile" -version = "3.26.0" +version = "3.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82a72c767771b47409d2345987fda8628641887d5466101319899796367354a0" +checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" dependencies = [ "fastrand", "getrandom", "once_cell", "rustix", - "windows-sys 0.61.2", + "windows-sys", ] [[package]] @@ -994,14 +996,14 @@ dependencies = [ "pin-project-lite", "socket2", "tokio-macros", - "windows-sys 0.61.2", + "windows-sys", ] [[package]] name = "tokio-macros" -version = "2.6.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5" +checksum = "5c55a2eff8b69ce66c84f85e1da1c233edc36ceb85a2058d11b0d6a3c7e7569c" dependencies = [ "proc-macro2", "quote", @@ -1063,9 +1065,9 @@ dependencies = [ [[package]] name = "tonic-build" -version = "0.14.3" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27aac809edf60b741e2d7db6367214d078856b8a5bff0087e94ff330fb97b6fc" +checksum = "1882ac3bf5ef12877d7ed57aad87e75154c11931c2ba7e6cde5e22d63522c734" dependencies = [ "prettyplease", "proc-macro2", @@ -1190,9 +1192,15 @@ checksum = "dbc4bc3a9f746d862c45cb89d705aa10f187bb96c76001afab07a0d35ce60142" [[package]] name = "unicode-ident" -version = "1.0.22" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" [[package]] name = "utf8parse" @@ -1224,21 +1232,55 @@ dependencies = [ "wit-bindgen", ] +[[package]] +name = "wasip3" +version = "0.4.0+wasi-0.3.0-rc-2026-01-06" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5" +dependencies = [ + "wit-bindgen", +] + +[[package]] +name = "wasm-encoder" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319" +dependencies = [ + "leb128fmt", + "wasmparser", +] + +[[package]] +name = "wasm-metadata" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909" +dependencies = [ + "anyhow", + "indexmap", + "wasm-encoder", + "wasmparser", +] + +[[package]] +name = "wasmparser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" +dependencies = [ + "bitflags", + "hashbrown 0.15.5", + "indexmap", + "semver", +] + [[package]] name = "windows-link" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" -[[package]] -name = "windows-sys" -version = "0.60.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" -dependencies = [ - "windows-targets", -] - [[package]] name = "windows-sys" version = "0.61.2" @@ -1248,79 +1290,96 @@ dependencies = [ "windows-link", ] -[[package]] -name = "windows-targets" -version = "0.53.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" -dependencies = [ - "windows-link", - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" - -[[package]] -name = "windows_i686_gnu" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" - -[[package]] -name = "windows_i686_msvc" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" - [[package]] name = "wit-bindgen" version = "0.51.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" +dependencies = [ + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen-core" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc" +dependencies = [ + "anyhow", + "heck", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "prettyplease", + "syn", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a" +dependencies = [ + "anyhow", + "prettyplease", + "proc-macro2", + "quote", + "syn", + "wit-bindgen-core", + "wit-bindgen-rust", +] + +[[package]] +name = "wit-component" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" +dependencies = [ + "anyhow", + "bitflags", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder", + "wasm-metadata", + "wasmparser", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser", +] [[package]] name = "zmij" -version = "1.0.19" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ff05f8caa9038894637571ae6b9e29466c1f4f829d26c9b28f869a29cbe3445" +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" diff --git a/Cargo.toml b/Cargo.toml index 040cca4..606c3e4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ rust-version = "1.89" [workspace.dependencies] serde_json = "1.0.149" tokio = { version = "1.50.0" } +futures-util = "0.3.32" # Tonic & prost related deps # They must be updated all at once diff --git a/granc-core/Cargo.toml b/granc-core/Cargo.toml index 33cfef4..d0590f9 100644 --- a/granc-core/Cargo.toml +++ b/granc-core/Cargo.toml @@ -18,7 +18,7 @@ name = "granc_core" path = "src/lib.rs" [dependencies] -futures-util = "0.3.32" +futures-util = { workspace = true } http = "1.4.0" http-body = "1.0.1" prost = { workspace = true } diff --git a/granc-core/src/client/online_without_reflection.rs b/granc-core/src/client/online_without_reflection.rs index d251bd0..24a15c6 100644 --- a/granc-core/src/client/online_without_reflection.rs +++ b/granc-core/src/client/online_without_reflection.rs @@ -4,7 +4,7 @@ //! but uses a local, in-memory `DescriptorPool` (Static schema) to resolve messages. use super::{DynamicRequest, DynamicResponse, GrancClient, OnlineWithoutReflection}; use crate::{BoxError, client::OfflineReflectionState, grpc::client::GrpcRequestError}; -use futures_util::{Stream, StreamExt}; +use futures_util::{Stream, StreamExt, stream}; use http_body::Body as HttpBody; use std::fmt::Debug; @@ -76,8 +76,10 @@ where .server_streaming(method, request.body, request.headers) .await? { - Ok(stream) => Ok(DynamicResponse::Streaming(Ok(stream.collect().await))), - Err(status) => Ok(DynamicResponse::Streaming(Err(status))), + Ok(stream) => Ok(DynamicResponse::Streaming(stream.boxed())), + Err(status) => Ok(DynamicResponse::Streaming( + stream::once(async { Err(status) }).boxed(), + )), }, (true, false) => { let input_stream = @@ -98,8 +100,10 @@ where .bidirectional_streaming(method, input_stream, request.headers) .await? { - Ok(stream) => Ok(DynamicResponse::Streaming(Ok(stream.collect().await))), - Err(status) => Ok(DynamicResponse::Streaming(Err(status))), + Ok(stream) => Ok(DynamicResponse::Streaming(stream.boxed())), + Err(status) => Ok(DynamicResponse::Streaming( + stream::once(async { Err(status) }).boxed(), + )), } } } diff --git a/granc-core/src/client/types.rs b/granc-core/src/client/types.rs index eae387a..c19c173 100644 --- a/granc-core/src/client/types.rs +++ b/granc-core/src/client/types.rs @@ -1,3 +1,4 @@ +use futures_util::stream::BoxStream; use prost_reflect::{EnumDescriptor, MessageDescriptor, ServiceDescriptor}; use std::fmt::Debug; @@ -17,12 +18,11 @@ pub struct DynamicRequest { } /// The result of a dynamic gRPC call. -#[derive(Debug, Clone)] pub enum DynamicResponse { /// A single response message (for Unary and Client Streaming calls). Unary(Result), /// A stream of response messages (for Server Streaming and Bidirectional calls). - Streaming(Result>, tonic::Status>), + Streaming(BoxStream<'static, Result>), } /// A generic wrapper for different types of Protobuf descriptors. diff --git a/granc-core/src/grpc/client.rs b/granc-core/src/grpc/client.rs index 5ed9164..3350233 100644 --- a/granc-core/src/grpc/client.rs +++ b/granc-core/src/grpc/client.rs @@ -104,10 +104,7 @@ where method: MethodDescriptor, payload: serde_json::Value, headers: Vec<(String, String)>, - ) -> Result< - Result>, tonic::Status>, - GrpcRequestError, - > { + ) -> Result, tonic::Status>, GrpcRequestError> { self.client .ready() .await @@ -163,10 +160,7 @@ where method: MethodDescriptor, payload_stream: impl Stream + Send + 'static, headers: Vec<(String, String)>, - ) -> Result< - Result>, tonic::Status>, - GrpcRequestError, - > { + ) -> Result, tonic::Status>, GrpcRequestError> { self.client .ready() .await diff --git a/granc-core/tests/granc_client_online_test.rs b/granc-core/tests/granc_client_online_test.rs index 912d4ed..ccca11c 100644 --- a/granc-core/tests/granc_client_online_test.rs +++ b/granc-core/tests/granc_client_online_test.rs @@ -2,6 +2,7 @@ use echo_service_impl::EchoServiceImpl; use granc_core::client::{DynamicRequest, DynamicResponse, GrancClient, Online, online}; use granc_core::reflection::client::ReflectionResolveError; use granc_test_support::echo_service::{EchoServiceServer, FILE_DESCRIPTOR_SET}; +use tokio_stream::StreamExt; use tonic::Code; use tonic::service::Routes; @@ -62,7 +63,9 @@ async fn test_reflection_server_streaming_success() { let res = client.dynamic(req).await.unwrap(); match res { - DynamicResponse::Streaming(Ok(stream)) => { + DynamicResponse::Streaming(stream) => { + let stream: Vec<_> = stream.collect().await; + assert_eq!(stream.len(), 3); assert_eq!(stream[0].as_ref().unwrap()["message"], "stream - seq 0"); assert_eq!(stream[1].as_ref().unwrap()["message"], "stream - seq 1"); diff --git a/granc-core/tests/granc_client_online_without_reflection_test.rs b/granc-core/tests/granc_client_online_without_reflection_test.rs index 07ba4fc..5337091 100644 --- a/granc-core/tests/granc_client_online_without_reflection_test.rs +++ b/granc-core/tests/granc_client_online_without_reflection_test.rs @@ -1,4 +1,5 @@ use echo_service_impl::EchoServiceImpl; +use futures_util::StreamExt; use granc_core::client::{ DynamicRequest, DynamicResponse, GrancClient, OnlineWithoutReflection, online_without_reflection, @@ -50,7 +51,9 @@ async fn test_dynamic_server_streaming_success() { let res = client.dynamic(req).await.unwrap(); match res { - DynamicResponse::Streaming(Ok(stream)) => { + DynamicResponse::Streaming(stream) => { + let stream: Vec<_> = stream.collect().await; + assert_eq!(stream.len(), 3); assert_eq!(stream[0].as_ref().unwrap()["message"], "stream - seq 0"); assert_eq!(stream[1].as_ref().unwrap()["message"], "stream - seq 1"); @@ -101,7 +104,9 @@ async fn test_dynamic_bidirectional_streaming_success() { let res = client.dynamic(req).await.unwrap(); match res { - DynamicResponse::Streaming(Ok(stream)) => { + DynamicResponse::Streaming(stream) => { + let stream: Vec<_> = stream.collect().await; + assert_eq!(stream.len(), 2); assert_eq!(stream[0].as_ref().unwrap()["message"], "echo: Ping"); assert_eq!(stream[1].as_ref().unwrap()["message"], "echo: Pong"); diff --git a/granc/Cargo.toml b/granc/Cargo.toml index 49b5441..5fa4344 100644 --- a/granc/Cargo.toml +++ b/granc/Cargo.toml @@ -26,6 +26,7 @@ colored = "3.1.1" granc_core = { version = "0.6.2", path = "../granc-core" } serde_json = { workspace = true } tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } +futures-util = { workspace = true } [dev-dependencies] granc-test-support = { path = "../granc-test-support" } diff --git a/granc/src/formatter.rs b/granc/src/formatter.rs index 66f8478..6107fe2 100644 --- a/granc/src/formatter.rs +++ b/granc/src/formatter.rs @@ -1,10 +1,10 @@ use colored::*; use granc_core::{ - client::{Descriptor, DynamicResponse, online, online_without_reflection}, + client::{Descriptor, online, online_without_reflection}, prost_reflect::{ self, EnumDescriptor, Kind, MessageDescriptor, MethodDescriptor, ServiceDescriptor, }, - tonic::Status, + tonic::{self, Status}, }; use std::fmt::Display; @@ -42,23 +42,16 @@ impl From for FormattedString { } } -impl From for FormattedString { - fn from(value: DynamicResponse) -> Self { - match value { - DynamicResponse::Unary(Ok(value)) => FormattedString::from(value), - DynamicResponse::Unary(Err(status)) => FormattedString::from(status), - DynamicResponse::Streaming(Ok(values)) => { - let mut s = String::new(); - for elem in values { - match elem { - Ok(val) => s.push_str(&FormattedString::from(val).0), - Err(status) => s.push_str(&FormattedString::from(status).0), - } - } - FormattedString(s) +impl From>> for FormattedString { + fn from(values: Vec>) -> Self { + let mut s = String::new(); + for elem in values { + match elem { + Ok(val) => s.push_str(&FormattedString::from(val).0), + Err(status) => s.push_str(&FormattedString::from(status).0), } - DynamicResponse::Streaming(Err(status)) => FormattedString::from(status), } + FormattedString(s) } } diff --git a/granc/src/main.rs b/granc/src/main.rs index 53f1ff4..612c706 100644 --- a/granc/src/main.rs +++ b/granc/src/main.rs @@ -14,6 +14,7 @@ mod formatter; use clap::Parser; use cli::{Cli, Commands, Source}; use formatter::{FormattedString, GenericError}; +use futures_util::StreamExt; use granc_core::client::{Descriptor, DynamicRequest, DynamicResponse, GrancClient}; use std::process; @@ -30,7 +31,17 @@ async fn main() { file_descriptor_set, } => { let response = call(endpoint, uri, body, headers, file_descriptor_set).await; - println!("{}", FormattedString::from(response)) + + let formatted = match response { + DynamicResponse::Unary(Ok(value)) => FormattedString::from(value), + DynamicResponse::Unary(Err(status)) => FormattedString::from(status), + DynamicResponse::Streaming(stream) => { + let elems = stream.collect::>().await; + FormattedString::from(elems) + } + }; + + println!("{formatted}") } Commands::List { source } => {