From 84cae5af7d7009ff7b7acc1fe1170903dc4a51d4 Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Sat, 22 Jul 2023 19:05:54 -0400 Subject: [PATCH] Add streaming method generation (untested) --- Cargo.lock | 517 ++++++++++----------- usdpl-back/Cargo.toml | 2 +- usdpl-build/Cargo.toml | 2 +- usdpl-build/src/front/service_generator.rs | 333 ++++++++++--- usdpl-front/Cargo.toml | 4 +- usdpl-front/src/client_handler.rs | 147 ++++-- usdpl-front/src/convert.rs | 8 + usdpl-front/src/lib.rs | 2 + usdpl-front/src/wasm/js_function_stream.rs | 74 +++ usdpl-front/src/wasm/mod.rs | 4 + usdpl-front/src/wasm/streaming.rs | 189 ++++++++ 11 files changed, 903 insertions(+), 379 deletions(-) create mode 100644 usdpl-front/src/wasm/js_function_stream.rs create mode 100644 usdpl-front/src/wasm/streaming.rs diff --git a/Cargo.lock b/Cargo.lock index 44f28bb..b8c205e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "addr2line" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4fa78e18c64fce05e902adecd7a5eed15a5e0a3439f7b0e169f0252214865e3" +dependencies = [ + "gimli", +] + [[package]] name = "adler" version = "1.0.2" @@ -45,16 +54,25 @@ dependencies = [ ] [[package]] -name = "anyhow" -version = "1.0.70" +name = "aho-corasick" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4" +checksum = "43f6cb1bf222025340178f382c426f13757b2960e89779dfcb319c32542a5a41" +dependencies = [ + "memchr", +] + +[[package]] +name = "anyhow" +version = "1.0.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8" [[package]] name = "async-channel" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf46fee83e5ccffc220104713af3292ff9bc7c64c7de289f66dae8e38d826833" +checksum = "81953c529336010edd6d8e358f886d9581267795c61b19475b71314bffa46d35" dependencies = [ "concurrent-queue", "event-listener", @@ -78,18 +96,18 @@ checksum = "0e97ce7de6cf12de5d7226c73f5ba9811622f4db3a5b91b55c53e987e5f91cba" dependencies = [ "proc-macro2", "quote", - "syn 2.0.15", + "syn 2.0.25", ] [[package]] name = "async-trait" -version = "0.1.68" +version = "0.1.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842" +checksum = "a564d521dd56509c4c47480d00b80ee55f7e385ae48db5744c67ad50c92d2ebf" dependencies = [ "proc-macro2", "quote", - "syn 2.0.15", + "syn 2.0.25", ] [[package]] @@ -98,6 +116,21 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "backtrace" +version = "0.3.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4319208da049c43661739c5fade2ba182f09d1dc2299b32298d3a31692b17e12" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + [[package]] name = "base64" version = "0.13.1" @@ -127,9 +160,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.12.0" +version = "3.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" +checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" [[package]] name = "byteorder" @@ -202,9 +235,9 @@ checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" [[package]] name = "cpufeatures" -version = "0.2.6" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "280a9f2d8b3a38871a3c8a46fb80db65e5e5ed97da80c4d08bf27fb63e35e181" +checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1" dependencies = [ "libc", ] @@ -220,9 +253,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.15" +version = "0.8.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c063cd8cc95f5c377ed0d4b49a4b21f632396ff690e8470c29b3359b346984b" +checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" dependencies = [ "cfg-if", ] @@ -336,7 +369,7 @@ checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" dependencies = [ "errno-dragonfly", "libc", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -372,9 +405,9 @@ checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" [[package]] name = "flate2" -version = "1.0.25" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8a2db397cb1c8772f31494cb8917e48cd1e64f0fa7efac59fbd741a0a8ce841" +checksum = "3b9429470923de8e8cbd4d2dc513535400b4b3fef0319fb5c4e1f520a7bef743" dependencies = [ "crc32fast", "libz-sys", @@ -389,9 +422,9 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "form_urlencoded" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" +checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" dependencies = [ "percent-encoding", ] @@ -452,7 +485,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.15", + "syn 2.0.25", ] [[package]] @@ -497,9 +530,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.9" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c85e1d9ab2eadba7e5040d4e09cbd6d072b76a557ad64e797c2cb9d4da21d7e4" +checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" dependencies = [ "cfg-if", "libc", @@ -517,15 +550,22 @@ dependencies = [ ] [[package]] -name = "gloo-net" -version = "0.2.6" +name = "gimli" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9902a044653b26b99f7e3693a42f171312d9be8b26b5697bd1e43ad1f8a35e10" +checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e" + +[[package]] +name = "gloo-net" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3000ef231a67d5bfee6b35f2c0f6f5c8d45b3381ef5bbbea603690ec4e539762" dependencies = [ "futures-channel", "futures-core", "futures-sink", "gloo-utils", + "http", "js-sys", "pin-project", "serde", @@ -538,9 +578,9 @@ dependencies = [ [[package]] name = "gloo-utils" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8e8fc851e9c7b9852508bc6e3f690f452f474417e8545ec9857b7f7377036b5" +checksum = "037fcb07216cb3a30f7292bd0176b050b7b9a052ba830ef7d5d65f6dc64ba58e" dependencies = [ "js-sys", "serde", @@ -563,18 +603,9 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" -version = "0.2.6" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" -dependencies = [ - "libc", -] - -[[package]] -name = "hermit-abi" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" +checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" [[package]] name = "hex" @@ -607,9 +638,9 @@ checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" [[package]] name = "idna" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" +checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" dependencies = [ "unicode-bidi", "unicode-normalization", @@ -636,13 +667,13 @@ dependencies = [ [[package]] name = "io-lifetimes" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c66c74d2ae7e79a5a8f7ac924adbe38ee42a859c6539ad869eb51f0b52dc220" +checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" dependencies = [ - "hermit-abi 0.3.1", + "hermit-abi", "libc", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -656,15 +687,15 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.6" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" +checksum = "62b02a5381cc465bd3041d84623d0fa3b66738b52b8e2fc3bab8ad63ab032f4a" [[package]] name = "js-sys" -version = "0.3.61" +version = "0.3.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" +checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" dependencies = [ "wasm-bindgen", ] @@ -677,15 +708,15 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.141" +version = "0.2.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" [[package]] name = "libz-sys" -version = "1.1.8" +version = "1.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9702761c3935f8cc2f101793272e202c72b99da8f4224a19ddcf1279a6450bbf" +checksum = "56ee889ecc9568871456d42f603d6a0ce59ff328d291063a45cbdf0036baf6db" dependencies = [ "cc", "pkg-config", @@ -694,15 +725,15 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.3.1" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d59d8c75012853d2e872fb56bc8a2e53718e2cafe1a4c823143141c6d90c322f" +checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" [[package]] name = "lock_api" -version = "0.4.9" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" +checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" dependencies = [ "autocfg", "scopeguard", @@ -710,12 +741,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.17" +version = "0.4.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" -dependencies = [ - "cfg-if", -] +checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" [[package]] name = "logos" @@ -736,8 +764,8 @@ dependencies = [ "fnv", "proc-macro2", "quote", - "regex-syntax", - "syn 2.0.15", + "regex-syntax 0.6.29", + "syn 2.0.25", ] [[package]] @@ -757,9 +785,9 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "miette" -version = "5.7.0" +version = "5.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7abdc09c381c9336b9f2e9bd6067a9a5290d20e2d2e2296f275456121c33ae89" +checksum = "a236ff270093b0b67451bc50a509bd1bad302cb1d3c7d37d5efe931238581fa9" dependencies = [ "miette-derive", "once_cell", @@ -769,34 +797,33 @@ dependencies = [ [[package]] name = "miette-derive" -version = "5.7.0" +version = "5.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8842972f23939443013dfd3720f46772b743e86f1a81d120d4b6fb090f87de1c" +checksum = "4901771e1d44ddb37964565c654a3223ba41a594d02b8da471cc4464912b5cfa" dependencies = [ "proc-macro2", "quote", - "syn 2.0.15", + "syn 2.0.25", ] [[package]] name = "miniz_oxide" -version = "0.6.2" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa" +checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" dependencies = [ "adler", ] [[package]] name = "mio" -version = "0.8.6" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9" +checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" dependencies = [ "libc", - "log", "wasi", - "windows-sys 0.45.0", + "windows-sys", ] [[package]] @@ -807,45 +834,35 @@ checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" [[package]] name = "nrpc" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f41caeb65399490c6f68ab2527a833d6f2e9b0d7d5ffc4b062f1484b3fa61cd" -dependencies = [ - "async-trait", - "bytes", - "prost", -] - -[[package]] -name = "nrpc" -version = "0.7.0" +version = "0.10.0" dependencies = [ "async-trait", "bytes", + "futures", "prost", ] [[package]] name = "nrpc-build" -version = "0.7.0" +version = "0.10.0" dependencies = [ - "nrpc 0.7.0", - "prettyplease 0.2.4", + "nrpc", + "prettyplease 0.2.10", "proc-macro2", "prost-build", "prost-types", "protox", "quote", - "syn 2.0.15", + "syn 2.0.25", ] [[package]] name = "num_cpus" -version = "1.15.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi 0.2.6", + "hermit-abi", "libc", ] @@ -856,10 +873,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b2b2cbbfd8defa51ff24450a61d73b3ff3e158484ddd274a883e886e6fbaa78" [[package]] -name = "once_cell" -version = "1.17.1" +name = "object" +version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" +checksum = "8bda667d9f2b5051b8833f59f3bf748b28ef54f850f4fcb389a252aa383866d1" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" [[package]] name = "opaque-debug" @@ -879,22 +905,22 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.7" +version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521" +checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.2.16", + "redox_syscall", "smallvec", - "windows-sys 0.45.0", + "windows-targets", ] [[package]] name = "percent-encoding" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" +checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" [[package]] name = "petgraph" @@ -908,29 +934,29 @@ dependencies = [ [[package]] name = "pin-project" -version = "1.0.12" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad29a609b6bcd67fee905812e544992d216af9d755757c05ed2d0e15a74c6ecc" +checksum = "030ad2bc4db10a8944cb0d837f158bdfec4d4a4873ab701a95046770d11f8842" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.0.12" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" +checksum = "ec2e072ecce94ec471b13398d5402c188e76ac03cf74dd1a975161b23a3f6d9c" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.25", ] [[package]] name = "pin-project-lite" -version = "0.2.9" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" +checksum = "4c40d25201921e5ff0c862a505c6557ea88568a4e3ace775ab55e93f2f4f9d57" [[package]] name = "pin-utils" @@ -940,9 +966,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.26" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" +checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" [[package]] name = "polyval" @@ -974,19 +1000,19 @@ dependencies = [ [[package]] name = "prettyplease" -version = "0.2.4" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ceca8aaf45b5c46ec7ed39fff75f57290368c1846d33d24a122ca81416ab058" +checksum = "92139198957b410250d43fad93e630d956499a625c527eda65175c8680f83387" dependencies = [ "proc-macro2", - "syn 2.0.15", + "syn 2.0.25", ] [[package]] name = "proc-macro2" -version = "1.0.56" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" +checksum = "78803b62cbf1f46fde80d7c0e803111524b9877184cfe7c3033659490ac7a7da" dependencies = [ "unicode-ident", ] @@ -1038,9 +1064,9 @@ dependencies = [ [[package]] name = "prost-reflect" -version = "0.11.3" +version = "0.11.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4df26814fb2cd59b1764305047aac8e9c467efe84a9e51bfd0c8811f08fe88a" +checksum = "000e1e05ebf7b26e1eba298e66fe4eee6eb19c567d0ffb35e0dd34231cdac4c8" dependencies = [ "logos", "miette", @@ -1060,9 +1086,9 @@ dependencies = [ [[package]] name = "protox" -version = "0.3.1" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cb2d1d74977bfa8fc4ddac1951ea639197c2896a830b6c5640085e498726da2" +checksum = "24022a7eb88547eaba87a1db7954c9c4cb4a143565c4e8f2b7f3e76eed63db2d" dependencies = [ "bytes", "miette", @@ -1075,9 +1101,9 @@ dependencies = [ [[package]] name = "protox-parse" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df78235a8c28dc4c5d8acb498d3000851b61b80a68774ff7b43323371b082ea4" +checksum = "712a2a651fa4466e67df6c967df5d7fc6cbffac89afc7b834f97ec49846c9c11" dependencies = [ "logos", "miette", @@ -1087,9 +1113,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.26" +version = "1.0.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" +checksum = "573015e8ab27661678357f27dc26460738fd2b6c86e46f386fde94cb5d913105" dependencies = [ "proc-macro2", ] @@ -1184,15 +1210,6 @@ dependencies = [ "ratchet_ext", ] -[[package]] -name = "redox_syscall" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" -dependencies = [ - "bitflags", -] - [[package]] name = "redox_syscall" version = "0.3.5" @@ -1204,11 +1221,25 @@ dependencies = [ [[package]] name = "regex" -version = "1.7.3" +version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b1f693b24f6ac912f4893ef08244d70b6067480d2f1a46e950c9691e6749d1d" +checksum = "b2eae68fc220f7cf2532e4494aded17545fce192d59cd996e0fe7887f4ceb575" dependencies = [ - "regex-syntax", + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax 0.7.3", +] + +[[package]] +name = "regex-automata" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83d3daa6976cffb758ec878f108ba0e062a45b2d6ca3a2cca965338855476caf" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax 0.7.3", ] [[package]] @@ -1217,6 +1248,18 @@ version = "0.6.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" +[[package]] +name = "regex-syntax" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ab07dc67230e4a4718e70fd5c20055a4334b121f1f9db8fe63ef39ce9b8c846" + +[[package]] +name = "rustc-demangle" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" + [[package]] name = "rustc_version" version = "0.4.0" @@ -1228,23 +1271,23 @@ dependencies = [ [[package]] name = "rustix" -version = "0.37.11" +version = "0.37.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85597d61f83914ddeba6a47b3b8ffe7365107221c2e557ed94426489fefb5f77" +checksum = "4d69718bf81c6127a49dc64e44a742e8bb9213c0ff8869a22c308f84c1d4ab06" dependencies = [ "bitflags", "errno", "io-lifetimes", "libc", "linux-raw-sys", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] name = "ryu" -version = "1.0.13" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" +checksum = "fe232bdf6be8c8de797b22184ee71118d63780ea42ac85b61d1baa6d3b782ae9" [[package]] name = "scoped-tls" @@ -1266,15 +1309,15 @@ checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed" [[package]] name = "serde" -version = "1.0.160" +version = "1.0.171" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb2f3770c8bce3bcda7e149193a069a0f4365bda1fa5cd88e03bca26afc1216c" +checksum = "30e27d1e4fd7659406c492fd6cfaf2066ba8773de45ca75e855590f856dc34a9" [[package]] name = "serde_json" -version = "1.0.96" +version = "1.0.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "057d394a50403bcac12672b2b18fb387ab6d289d957dab67dd201875391e52f1" +checksum = "0f1e14e89be7aa4c4b78bdbdc9eb5bf8517829a600ae8eaa39a6e1d960b5185c" dependencies = [ "itoa", "ryu", @@ -1314,9 +1357,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" [[package]] name = "socket2" @@ -1347,9 +1390,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.15" +version = "2.0.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822" +checksum = "15e3fc8c0c74267e2df136e5e5fb656a464158aa57624053375eb9c8c6e25ae2" dependencies = [ "proc-macro2", "quote", @@ -1358,35 +1401,36 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.5.0" +version = "3.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9fbec84f381d5795b08656e4912bec604d162bff9291d6189a78f4c8ab87998" +checksum = "31c0432476357e58790aaa47a8efb0c5138f137343f3b5f23bd36a27e3b0a6d6" dependencies = [ + "autocfg", "cfg-if", "fastrand", - "redox_syscall 0.3.5", + "redox_syscall", "rustix", - "windows-sys 0.45.0", + "windows-sys", ] [[package]] name = "thiserror" -version = "1.0.40" +version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" +checksum = "a35fc5b8971143ca348fa6df4f024d4d55264f3468c71ad1c2f365b0a4d58c42" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.40" +version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" +checksum = "463fe12d7993d3b327787537ce8dd4dfa058de32fc2b195ef3cde03dc4771e8f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.15", + "syn 2.0.25", ] [[package]] @@ -1406,11 +1450,12 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.27.0" +version = "1.29.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0de47a4eecbe11f498978a9b29d792f0d2692d1dd003650c24c76510e3bc001" +checksum = "532826ff75199d5833b9d2c5fe410f29235e25704ee5f0ef599fb51c21f4a4da" dependencies = [ "autocfg", + "backtrace", "bytes", "libc", "mio", @@ -1420,18 +1465,18 @@ dependencies = [ "signal-hook-registry", "socket2", "tokio-macros", - "windows-sys 0.45.0", + "windows-sys", ] [[package]] name = "tokio-macros" -version = "2.0.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61a573bdc87985e9d6ddeed1b3d864e8a302c847e40d647746df2f1de209d1ce" +checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.15", + "syn 2.0.25", ] [[package]] @@ -1462,9 +1507,9 @@ checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" [[package]] name = "unicode-ident" -version = "1.0.8" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" +checksum = "22049a19f4a68748a168c0fc439f9516686aa045927ff767eca0a85101fb6e73" [[package]] name = "unicode-normalization" @@ -1493,9 +1538,9 @@ dependencies = [ [[package]] name = "url" -version = "2.3.1" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643" +checksum = "50bff7831e19200a85b17131d085c25d7811bc4e186efdaf54bbd132994a88cb" dependencies = [ "form_urlencoded", "idna", @@ -1513,7 +1558,7 @@ dependencies = [ "gettext-ng", "hex", "log", - "nrpc 0.6.0", + "nrpc", "obfstr", "prost", "ratchet_rs", @@ -1527,12 +1572,12 @@ name = "usdpl-build" version = "0.11.0" dependencies = [ "nrpc-build", - "prettyplease 0.2.4", + "prettyplease 0.2.10", "proc-macro2", "prost-build", "prost-types", "quote", - "syn 2.0.15", + "syn 2.0.25", ] [[package]] @@ -1556,7 +1601,7 @@ dependencies = [ "hex", "js-sys", "log", - "nrpc 0.7.0", + "nrpc", "obfstr", "prost", "usdpl-core", @@ -1586,9 +1631,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.84" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" +checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -1596,24 +1641,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.84" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" +checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.25", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" -version = "0.4.34" +version = "0.4.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f219e0d211ba40266969f6dbdd90636da12f75bee4fc9d6c23d1260dadb51454" +checksum = "c02dbc21516f9f1f04f187958890d7e6026df8d16540b7ad9492bc34a67cea03" dependencies = [ "cfg-if", "js-sys", @@ -1623,9 +1668,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.84" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" +checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1633,28 +1678,28 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.84" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" +checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.25", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.84" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" +checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" [[package]] name = "wasm-bindgen-test" -version = "0.3.34" +version = "0.3.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db36fc0f9fb209e88fb3642590ae0205bb5a56216dabd963ba15879fe53a30b" +checksum = "6e6e302a7ea94f83a6d09e78e7dc7d9ca7b186bc2829c24a22d0753efd680671" dependencies = [ "console_error_panic_hook", "js-sys", @@ -1666,9 +1711,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-test-macro" -version = "0.3.34" +version = "0.3.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0734759ae6b3b1717d661fe4f016efcfb9828f5edb4520c18eaee05af3b43be9" +checksum = "ecb993dd8c836930ed130e020e77d9b2e65dd0fbab1b67c790b0f5d80b11a575" dependencies = [ "proc-macro2", "quote", @@ -1676,9 +1721,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.61" +version = "0.3.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e33b99f4b23ba3eec1a53ac264e35a755f00e966e0065077d6027c0f575b0b97" +checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" dependencies = [ "js-sys", "wasm-bindgen", @@ -1717,132 +1762,66 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows-sys" -version = "0.45.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" -dependencies = [ - "windows-targets 0.42.2", -] - [[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.0", + "windows-targets", ] [[package]] name = "windows-targets" -version = "0.42.2" +version = "0.48.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" dependencies = [ - "windows_aarch64_gnullvm 0.42.2", - "windows_aarch64_msvc 0.42.2", - "windows_i686_gnu 0.42.2", - "windows_i686_msvc 0.42.2", - "windows_x86_64_gnu 0.42.2", - "windows_x86_64_gnullvm 0.42.2", - "windows_x86_64_msvc 0.42.2", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", ] -[[package]] -name = "windows-targets" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" -dependencies = [ - "windows_aarch64_gnullvm 0.48.0", - "windows_aarch64_msvc 0.48.0", - "windows_i686_gnu 0.48.0", - "windows_i686_msvc 0.48.0", - "windows_x86_64_gnu 0.48.0", - "windows_x86_64_gnullvm 0.48.0", - "windows_x86_64_msvc 0.48.0", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" - [[package]] name = "windows_aarch64_gnullvm" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" -[[package]] -name = "windows_aarch64_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" - [[package]] name = "windows_aarch64_msvc" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" -[[package]] -name = "windows_i686_gnu" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" - [[package]] name = "windows_i686_gnu" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" -[[package]] -name = "windows_i686_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" - [[package]] name = "windows_i686_msvc" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" -[[package]] -name = "windows_x86_64_gnu" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" - [[package]] name = "windows_x86_64_gnu" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" - [[package]] name = "windows_x86_64_gnullvm" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" -[[package]] -name = "windows_x86_64_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" - [[package]] name = "windows_x86_64_msvc" version = "0.48.0" diff --git a/usdpl-back/Cargo.toml b/usdpl-back/Cargo.toml index 1037037..ff6e69d 100644 --- a/usdpl-back/Cargo.toml +++ b/usdpl-back/Cargo.toml @@ -19,7 +19,7 @@ usdpl-core = { version = "0.11", path = "../usdpl-core"} log = "0.4" # gRPC/protobuf -nrpc = "0.6" +nrpc = { version = "0.10", path = "../../nRPC/nrpc", default-features = false, features = [ "server-send" ] } async-lock = "2.7" prost = "0.11" diff --git a/usdpl-build/Cargo.toml b/usdpl-build/Cargo.toml index 9b1f1ad..796f836 100644 --- a/usdpl-build/Cargo.toml +++ b/usdpl-build/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -nrpc-build = { version = "0.7", path = "../../nRPC/nrpc-build" } +nrpc-build = { version = "0.10", path = "../../nRPC/nrpc-build" } prost-build = "0.11" prost-types = "0.11" diff --git a/usdpl-build/src/front/service_generator.rs b/usdpl-build/src/front/service_generator.rs index ce6eeda..00189f4 100644 --- a/usdpl-build/src/front/service_generator.rs +++ b/usdpl-build/src/front/service_generator.rs @@ -35,68 +35,203 @@ fn generate_service_methods( let mut input_params = Vec::with_capacity(input_type.field.len()); let mut params_to_fields = Vec::with_capacity(input_type.field.len()); - for field in &input_type.field { - //let param_name = quote::format_ident!("val{}", i.to_string()); - let type_enum = ProtobufType::from_field(field, &service.name, false); - //let rs_type_name = type_enum.to_tokens(); - let js_type_name = type_enum.to_wasm_tokens(); - let rs_type_name = type_enum.to_tokens(); - let field_name = quote::format_ident!( - "{}", - field - .name - .as_ref() - .expect("Protobuf message field needs a name") - ); - input_params.push(quote::quote! { - #field_name: #js_type_name, - }); - params_to_fields.push(quote::quote! { - #field_name: #rs_type_name::from_wasm(#field_name.into()),//: #field_name, - }); - } - let params_to_fields_transformer = if input_type.field.len() == 1 { - let field_name = quote::format_ident!( - "{}", - input_type.field[0] - .name - .as_ref() - .expect("Protobuf message field needs a name") - ); - quote::quote! { - let val = #method_input::from_wasm(#field_name.into()); - } - } else if input_type.field.is_empty() { - quote::quote! { - let val = #method_input {}; - } - } else { - quote::quote! { - let val = #method_input { - #(#params_to_fields)* - }; - } - }; - gen_methods.push(quote::quote! { - #[wasm_bindgen] - pub async fn #method_name(&self, #(#input_params)*) -> Option<#method_output> { - - #params_to_fields_transformer - - match self.service.#method_name(val.into()).await { - Ok(x) => { - let x2: #method_output_as_in = x.into(); - Some(x2.into_wasm()) - }, - Err(e) => { - // log error - log::error!("service:{}|method:{}|error:{}", self.service.descriptor(), #method_name_str, e); - None - } + match (method.client_streaming, method.server_streaming) { + (false, false) => { + for field in &input_type.field { + //let param_name = quote::format_ident!("val{}", i.to_string()); + let type_enum = ProtobufType::from_field(field, &service.name, false); + //let rs_type_name = type_enum.to_tokens(); + let js_type_name = type_enum.to_wasm_tokens(); + let rs_type_name = type_enum.to_tokens(); + let field_name = quote::format_ident!( + "{}", + field + .name + .as_ref() + .expect("Protobuf message field needs a name") + ); + input_params.push(quote::quote! { + #field_name: #js_type_name, + }); + params_to_fields.push(quote::quote! { + #field_name: #rs_type_name::from_wasm(#field_name.into()),//: #field_name, + }); } - } - }); + let params_to_fields_transformer = if input_type.field.len() == 1 { + let field_name = quote::format_ident!( + "{}", + input_type.field[0] + .name + .as_ref() + .expect("Protobuf message field needs a name") + ); + quote::quote! { + let val = #method_input::from_wasm(#field_name.into()); + } + } else if input_type.field.is_empty() { + quote::quote! { + let val = #method_input {}; + } + } else { + quote::quote! { + let val = #method_input { + #(#params_to_fields)* + }; + } + }; + + gen_methods.push(quote::quote! { + #[wasm_bindgen] + pub async fn #method_name(&self, #(#input_params)*) -> Option<#method_output> { + + #params_to_fields_transformer + + match self.service.#method_name(val.into()).await { + Ok(x) => { + let x2: #method_output_as_in = x.into(); + Some(x2.into_wasm()) + }, + Err(e) => { + // log error + log::error!("service:{}|method:{}|error:{}", self.service.descriptor(), #method_name_str, e); + None + } + } + } + }); + }, + (true, false) => { + // many -> 1 + gen_methods.push(quote::quote! { + #[wasm_bindgen] + pub async fn #method_name(&self, generator: js_sys::Function) -> Option<#method_output> { + + // function into Rust futures Stream + let stream = Box::new(::usdpl_front::wasm::JsFunctionStream::<#method_input>::from_function(generator)); + + match self.service.#method_name(stream).await { + Ok(x) => { + let x2: #method_output_as_in = x.into(); + Some(x2.into_wasm()) + }, + Err(e) => { + // log error + log::error!("service:{}|method:{}|error:{}", self.service.descriptor(), #method_name_str, e); + None + } + } + } + }); + }, + (false, true) => { + // 1 -> many + for field in &input_type.field { + //let param_name = quote::format_ident!("val{}", i.to_string()); + let type_enum = ProtobufType::from_field(field, &service.name, false); + //let rs_type_name = type_enum.to_tokens(); + let js_type_name = type_enum.to_wasm_tokens(); + let rs_type_name = type_enum.to_tokens(); + let field_name = quote::format_ident!( + "{}", + field + .name + .as_ref() + .expect("Protobuf message field needs a name") + ); + input_params.push(quote::quote! { + #field_name: #js_type_name, + }); + params_to_fields.push(quote::quote! { + #field_name: #rs_type_name::from_wasm(#field_name.into()),//: #field_name, + }); + } + let params_to_fields_transformer = if input_type.field.len() == 1 { + let field_name = quote::format_ident!( + "{}", + input_type.field[0] + .name + .as_ref() + .expect("Protobuf message field needs a name") + ); + quote::quote! { + let val = #method_input::from_wasm(#field_name.into()); + } + } else if input_type.field.is_empty() { + quote::quote! { + let val = #method_input {}; + } + } else { + quote::quote! { + let val = #method_input { + #(#params_to_fields)* + }; + } + }; + + gen_methods.push(quote::quote! { + #[wasm_bindgen] + pub async fn #method_name(&self, #(#input_params)*, callback: js_sys::Function) { + + #params_to_fields_transformer + + match self.service.#method_name(val.into()).await { + Ok(x) => { + while let Some(next_result) = x.next().await { + match next_result { + Err(e) => { + log::error!("service:{}|method:{}|error:{}", self.service.descriptor(), #method_name_str, e); + }, + Ok(item) => { + callback.call1(JsValue::undefined(), item.into_wasm_streamable()); + } + } + } + }, + Err(e) => { + // log error + log::error!("service:{}|method:{}|error:{}", self.service.descriptor(), #method_name_str, e); + } + } + } + }); + }, + (true, true) => { + // many -> many + gen_methods.push(quote::quote! { + #[wasm_bindgen] + pub async fn #method_name(&self, generator: js_sys::Function, callback: js_sys::Function) -> Option<#method_output> { + + // function into Rust futures Stream + let stream = Box::new(::usdpl_front::wasm::JsFunctionStream::<#method_input>::from_function(generator)); + + match self.service.#method_name(stream).await { + Ok(x) => { + while let Some(next_result) = x.next().await { + match next_result { + Err(e) => { + log::error!("service:{}|method:{}|error:{}", self.service.descriptor(), #method_name_str, e); + }, + Ok(item) => { + callback.call1(JsValue::undefined(), item.into_wasm_streamable()); + } + } + } + }, + Err(e) => { + // log error + log::error!("service:{}|method:{}|error:{}", self.service.descriptor(), #method_name_str, e); + None + } + } + } + }); + }, + } + + + + } quote::quote! { #(#gen_methods)* @@ -198,6 +333,7 @@ fn generate_wasm_struct_interop( .as_ref() .expect("Protobuf message needs a name") ); + let js_map_name = quote::format_ident!("{}", "js_map"); let mut gen_fields = Vec::with_capacity(descriptor.field.len()); let mut gen_into_fields = Vec::with_capacity(descriptor.field.len()); let mut gen_from_fields = Vec::with_capacity(descriptor.field.len()); @@ -288,17 +424,21 @@ fn generate_wasm_struct_interop( } else if descriptor.field.len() == 1 { let field = &descriptor.field[0]; //dbg!(descriptor, field); + let field_name_str = field + .name + .as_ref() + .expect("Protobuf message field needs a name"); let field_name = quote::format_ident!( "{}", - field - .name - .as_ref() - .expect("Protobuf message field needs a name") + field_name_str ); let type_enum = ProtobufType::from_field(field, service, is_known_map(field, known_maps)); let type_name = type_enum.to_tokens(); let wasm_type_name = type_enum.to_wasm_tokens(); + let into_wasm_streamable = quote::quote!{self.into_wasm_streamable()}; + let from_wasm_streamable = quote::quote!{#type_name::from_wasm_streamable(js)}; + quote::quote! { pub type #msg_name = #type_name; pub type #msg_name_wasm = #wasm_type_name; @@ -320,22 +460,41 @@ fn generate_wasm_struct_interop( } } + impl ::usdpl_front::wasm::FromWasmStreamableType for #msg_name { + fn from_wasm_streamable(js: JsValue) -> Result { + #from_wasm_streamable + } + } + + impl ::usdpl_front::wasm::IntoWasmStreamableType for #msg_name { + fn into_wasm_streamable(self) -> JsValue { + #into_wasm_streamable + } + } + #(#gen_nested_types)* #(#gen_enums)* } } else { + let mut gen_into_wasm_streamable_fields = Vec::with_capacity(descriptor.field.len()); + let mut gen_from_wasm_streamable_fields = Vec::with_capacity(descriptor.field.len()); + for field in &descriptor.field { + let field_name_str = field + .name + .as_ref() + .expect("Protobuf message field needs a name"); let field_name = quote::format_ident!( "{}", - field - .name - .as_ref() - .expect("Protobuf message field needs a name") + field_name_str ); let type_enum = ProtobufType::from_field(field, service, is_known_map(field, known_maps)); let type_name = type_enum.to_tokens(); + + let into_wasm_streamable = type_enum.to_into_wasm_streamable(field_name_str, &js_map_name); + let from_wasm_streamable = type_enum.to_from_wasm_streamable(field_name_str, &js_map_name); //let wasm_type_name = type_enum.to_wasm_tokens(); gen_fields.push(quote::quote! { pub #field_name: #type_name, @@ -347,6 +506,9 @@ fn generate_wasm_struct_interop( gen_from_fields.push(quote::quote! { #field_name: <_>::from(other.#field_name), }); + + gen_into_wasm_streamable_fields.push(into_wasm_streamable); + gen_from_wasm_streamable_fields.push(from_wasm_streamable); } let wasm_attribute_maybe = @@ -399,6 +561,23 @@ fn generate_wasm_struct_interop( } } + impl ::usdpl_front::wasm::FromWasmStreamableType for #msg_name { + fn from_wasm_streamable(js: JsValue) -> Result { + let #js_map_name = js_sys::Map::from(js); + Ok(Self { + #(#gen_from_wasm_streamable_fields)* + }) + } + } + + impl ::usdpl_front::wasm::IntoWasmStreamableType for #msg_name { + fn into_wasm_streamable(self) -> JsValue { + let #js_map_name = js_sys::Map::new(); + #(#gen_into_wasm_streamable_fields)* + #js_map_name.into() + } + } + #(#gen_nested_types)* #(#gen_enums)* @@ -551,6 +730,18 @@ impl ProtobufType { } } } + + fn to_into_wasm_streamable(&self, field_name: &str, js_map_name: &syn::Ident) -> proc_macro2::TokenStream { + //let type_tokens = self.to_tokens(); + //let field_ident = quote::format_ident!("{}", field_name); + quote::quote!{#js_map_name.set(#field_name.into(), self.field_ident);} + } + + fn to_from_wasm_streamable(&self, field_name: &str, js_map_name: &syn::Ident) -> proc_macro2::TokenStream { + let type_tokens = self.to_tokens(); + //let field_ident = quote::format_ident!("{}", field_name); + quote::quote!{#field_name: #type_tokens::from_wasm_streamable(#js_map_name.get(#field_name.into()))?,} + } } fn generate_wasm_enum_interop( @@ -815,8 +1006,10 @@ impl IServiceGenerator for WasmServiceGenerator { use usdpl_front::_helpers::wasm_bindgen_futures; use usdpl_front::_helpers::js_sys; use usdpl_front::_helpers::log; - - use ::nrpc::ClientService; + use usdpl_front::_helpers::futures; + use usdpl_front::_helpers::futures::StreamExt; + use usdpl_front::_helpers::nrpc::ClientService; + use usdpl_front::wasm::{IntoWasmStreamableType, FromWasmStreamableType}; use usdpl_front::wasm::*; diff --git a/usdpl-front/Cargo.toml b/usdpl-front/Cargo.toml index 93d7970..33a7877 100644 --- a/usdpl-front/Cargo.toml +++ b/usdpl-front/Cargo.toml @@ -20,7 +20,7 @@ encrypt = ["usdpl-core/encrypt", "obfstr", "hex"] [dependencies] wasm-bindgen = "0.2" wasm-bindgen-futures = "0.4" -gloo-net = { version = "0.2", features = ["websocket"] } +gloo-net = { version = "0.3", features = ["websocket"] } futures = "0.3" console_log = { version = "1.0", optional = true, features = ["color"] } @@ -45,7 +45,7 @@ async-channel = "1.8" obfstr = { version = "0.3", optional = true } hex = { version = "0.4", optional = true } -nrpc = { version = "0.7", path = "../../nRPC/nrpc" } +nrpc = { version = "0.10", path = "../../nRPC/nrpc", default-features = false} usdpl-core = { version = "0.11", path = "../usdpl-core" } prost = "0.11" log = "0.4" diff --git a/usdpl-front/src/client_handler.rs b/usdpl-front/src/client_handler.rs index 74e0089..9c3a703 100644 --- a/usdpl-front/src/client_handler.rs +++ b/usdpl-front/src/client_handler.rs @@ -1,8 +1,8 @@ use std::sync::atomic::{AtomicU64, Ordering}; -use futures::{SinkExt, StreamExt}; -use gloo_net::websocket::{futures::WebSocket, Message}; -use nrpc::{ClientHandler, ServiceError, _helpers::async_trait, _helpers::bytes}; +use futures::{SinkExt, StreamExt, future::{select, Either}}; +use gloo_net::websocket::{futures::WebSocket, Message, State}; +use nrpc::{ClientHandler, ServiceError, ServiceClientStream, _helpers::async_trait, _helpers::bytes}; use wasm_bindgen_futures::spawn_local; static LAST_ID: AtomicU64 = AtomicU64::new(0); @@ -13,24 +13,104 @@ pub struct WebSocketHandler { port: u16, } -async fn send_recv_ws(url: String, input: bytes::Bytes) -> Result, String> { - let mut ws = WebSocket::open(&url).map_err(|e| e.to_string())?; - ws.send(Message::Bytes(input.into())) - .await - .map_err(|e| e.to_string())?; - - read_next_incoming(ws).await -} - -async fn read_next_incoming(mut ws: WebSocket) -> Result, String> { - if let Some(msg) = ws.next().await { - match msg.map_err(|e| e.to_string())? { - Message::Bytes(b) => Ok(b), - Message::Text(_) => Err("Message::Text not allowed".into()), +async fn send_recv_ws<'a>(tx: async_channel::Sender>, url: String, mut input: ServiceClientStream<'a, bytes::Bytes>) { + let ws = match WebSocket::open(&url).map_err(|e| e.to_string()) { + Ok(x) => x, + Err(e) => { + tx.send(Err(e.to_string())).await.unwrap_or(()); + return; + } + }; + + let (mut input_done, mut output_done) = (false, false); + let mut last_ws_state = ws.state(); + let (mut ws_sink, mut ws_stream) = ws.split(); + let (mut left, mut right) = (input.next(), ws_stream.next()); + while let State::Open = last_ws_state { + if !input_done && !output_done { + match select(left, right).await { + Either::Left((next, outstanding)) => { + if let Some(next) = next { + match next { + Ok(next) => { + if let Err(e) = ws_sink.send(Message::Bytes(next.into())).await { + tx.send(Err(e.to_string())).await.unwrap_or(()); + } + }, + Err(e) => tx.send(Err(e.to_string())).await.unwrap_or(()) + } + } else { + input_done = true; + } + right = outstanding; + left = input.next(); + }, + Either::Right((response, outstanding)) => { + if let Some(next) = response { + match next { + Ok(Message::Bytes(b)) => tx.send(Ok(b.into())).await.unwrap_or(()), + Ok(_) => tx.send(Err("Message::Text not allowed".into())).await.unwrap_or(()), + Err(e) => tx.send(Err(e.to_string())).await.unwrap_or(()), + } + } else { + output_done = true; + } + left = outstanding; + let ws = ws_stream.reunite(ws_sink).unwrap(); + last_ws_state = ws.state(); + (ws_sink, ws_stream) = ws.split(); + right = ws_stream.next(); + } + } + } else if input_done { + if let Some(next) = right.await { + match next { + Ok(Message::Bytes(b)) => tx.send(Ok(b.into())).await.unwrap_or(()), + Ok(_) => tx.send(Err("Message::Text not allowed".into())).await.unwrap_or(()), + Err(e) => tx.send(Err(e.to_string())).await.unwrap_or(()), + } + } else { + output_done = true; + } + //left = outstanding; + let ws = ws_stream.reunite(ws_sink).unwrap(); + last_ws_state = ws.state(); + (ws_sink, ws_stream) = ws.split(); + right = ws_stream.next(); + } else { + } - } else { - Err("No response received".into()) } + /*spawn_local(async move { + while let State::Open = ws.state() { + if let Some(next) = input.next().await { + match next { + Ok(next) => { + if let Err(e) = ws.send(Message::Bytes(next.into())).await { + tx2.send(Err(e.to_string())).await.unwrap_or(()); + } + }, + Err(e) => tx2.send(Err(e.to_string())).await.unwrap_or(()) + } + } else { + break; + } + } + }); + + spawn_local(async move { + while let State::Open = ws.state() { + if let Some(next) = ws.next().await { + match next { + Ok(Message::Bytes(b)) => tx.send(Ok(b.into())).await.unwrap_or(()), + Ok(_) => tx.send(Err("Message::Text not allowed".into())).await.unwrap_or(()), + Err(e) => tx.send(Err(e.to_string())).await.unwrap_or(()), + } + } else { + break; + } + } + });*/ } #[derive(Debug)] @@ -44,6 +124,8 @@ impl std::fmt::Display for ErrorStr { impl std::error::Error for ErrorStr {} +const CHANNEL_BOUND: usize = 4; + impl WebSocketHandler { /// Instantiate the web socket client for connecting on the specified port pub fn new(port: u16) -> Self { @@ -51,32 +133,25 @@ impl WebSocketHandler { } } -#[async_trait::async_trait] -impl ClientHandler for WebSocketHandler { - async fn call( +#[async_trait::async_trait(?Send)] +impl ClientHandler<'static> for WebSocketHandler { + async fn call<'a: 'static>( &self, package: &str, service: &str, method: &str, - input: bytes::Bytes, - output: &mut bytes::BytesMut, - ) -> Result<(), ServiceError> { + input: ServiceClientStream<'a, bytes::Bytes>, + ) -> Result, ServiceError> { let id = LAST_ID.fetch_add(1, Ordering::SeqCst); let url = format!( "ws://usdpl-ws-{}.localhost:{}/{}.{}/{}", id, self.port, package, service, method, ); - let (tx, rx) = async_channel::bounded(1); - spawn_local(async move { - tx.send(send_recv_ws(url, input).await).await.unwrap_or(()); - }); + let (tx, rx) = async_channel::bounded(CHANNEL_BOUND); + spawn_local(send_recv_ws(tx, url, input)); - output.extend_from_slice( - &rx.recv() - .await - .map_err(|e| ServiceError::Method(Box::new(e)))? - .map_err(|e| ServiceError::Method(Box::new(ErrorStr(e))))?, - ); - Ok(()) + Ok(Box::new(rx.map(|buf_result: Result| buf_result + .map(|buf| bytes::Bytes::from(buf)) + .map_err(|e| ServiceError::Method(Box::new(ErrorStr(e))))))) } } diff --git a/usdpl-front/src/convert.rs b/usdpl-front/src/convert.rs index b074ae6..f0cc660 100644 --- a/usdpl-front/src/convert.rs +++ b/usdpl-front/src/convert.rs @@ -38,3 +38,11 @@ pub(crate) fn js_to_primitive(val: JsValue) -> Primitive { pub(crate) fn str_to_js(s: S) -> JsString { s.to_string().into() } + +pub(crate) fn js_to_str(js: JsValue) -> String { + if let Some(s) = js.as_string() { + s + } else { + format!("{:?}", js) + } +} diff --git a/usdpl-front/src/lib.rs b/usdpl-front/src/lib.rs index db31334..27a75f8 100644 --- a/usdpl-front/src/lib.rs +++ b/usdpl-front/src/lib.rs @@ -23,6 +23,8 @@ pub mod _helpers { pub use wasm_bindgen; pub use wasm_bindgen_futures; pub use log; + pub use futures; + pub use nrpc; } use std::sync::atomic::{AtomicU64, Ordering}; diff --git a/usdpl-front/src/wasm/js_function_stream.rs b/usdpl-front/src/wasm/js_function_stream.rs new file mode 100644 index 0000000..4bd5c02 --- /dev/null +++ b/usdpl-front/src/wasm/js_function_stream.rs @@ -0,0 +1,74 @@ +use core::pin::Pin; +use core::future::Future; + +use futures::{Stream, task::{Poll, Context}}; +use wasm_bindgen_futures::JsFuture; +use wasm_bindgen::JsValue; +use js_sys::{Function, Promise}; + +use nrpc::ServiceError; +use super::FromWasmStreamableType; +use crate::convert::js_to_str; + +/// futures::Stream wrapper for a JS async function that generates a new T-like value every call +pub struct JsFunctionStream { + function: Function, + promise: Option, + _idc: std::marker::PhantomData, +} + +impl JsFunctionStream { + /// Construct the function stream wrapper + pub fn from_function(f: Function) -> Self { + Self { + function: f, + promise: None, + _idc: std::marker::PhantomData::default(), + } + } +} + +impl Stream for JsFunctionStream { + type Item = Result; + + fn poll_next( + mut self: Pin<&mut Self>, + cx: &mut Context<'_> + ) -> Poll> { + // this is horrible, I'm sorry + let js_poll = if let Some(mut promise) = self.promise.take() { + let mut pin = Pin::new(&mut promise); + JsFuture::poll(pin.as_mut(), cx) + } else { + let function_result = match self.function.call0(&JsValue::undefined()) { + Ok(x) => x, + Err(e) => return Poll::Ready(Some(Err(ServiceError::Method(s_to_err(format!("JS function call error: {}", js_to_str(e))))))) + }; + + let js_promise = Promise::from(function_result); + let mut js_future = JsFuture::from(js_promise); + let mut pin = Pin::new(&mut js_future); + let poll = JsFuture::poll(pin.as_mut(), cx); + self.promise = Some(js_future); + poll + }; + js_poll.map(|t| match t { + Ok(t) => { + if t.is_null() || t.is_undefined() { + None + } else { + Some(T::from_wasm_streamable(t).map_err(|e| ServiceError::Method(s_to_err(format!("JS type conversion error: {}", e))))) + } + }, + Err(e) => Some(Err(ServiceError::Method(s_to_err(format!("JS function promise error: {}", js_to_str(e)))))) + }) + } +} + +fn s_to_err(s: String) -> Box<(dyn std::error::Error + Send + Sync + 'static)> { + s.into() +} + +fn _check_service_stream(js_stream: JsFunctionStream) { + let _: nrpc::ServiceClientStream<'static, T> = Box::new(js_stream); +} diff --git a/usdpl-front/src/wasm/mod.rs b/usdpl-front/src/wasm/mod.rs index 6e9d7b1..17bf56b 100644 --- a/usdpl-front/src/wasm/mod.rs +++ b/usdpl-front/src/wasm/mod.rs @@ -1,7 +1,11 @@ //! WASM <-> Rust interop utilities mod arrays; +mod js_function_stream; mod maps; +mod streaming; mod trivials; mod wasm_traits; +pub use js_function_stream::JsFunctionStream; pub use wasm_traits::*; +pub use streaming::*; diff --git a/usdpl-front/src/wasm/streaming.rs b/usdpl-front/src/wasm/streaming.rs new file mode 100644 index 0000000..9eea695 --- /dev/null +++ b/usdpl-front/src/wasm/streaming.rs @@ -0,0 +1,189 @@ +use wasm_bindgen::JsValue; + +/// Convert Rust type to WASM-compatible type involved in nRPC streaming +pub trait IntoWasmStreamableType { + /// Required method + fn into_wasm_streamable(self) -> JsValue; +} + +#[derive(Debug)] +/// Conversion error from FromWasmStreamableType +pub enum WasmStreamableConversionError { + /// JSValue underlying type is incorrect + UnexpectedType { + /// Expected Javascript type + expected: JsType, + /// Actual Javascript type + got: JsType, + }, +} + +impl core::fmt::Display for WasmStreamableConversionError { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Self::UnexpectedType { expected, got } => write!(f, "Unexpected type {}, expected {}", expected, got), + } + } +} + +impl std::error::Error for WasmStreamableConversionError {} + +/// Approximation of all possible JS types detectable through Wasm +#[allow(missing_docs)] +#[derive(Debug)] +pub enum JsType { + Number, + String, + Bool, + Array, + BigInt, + Function, + Symbol, + Undefined, + Null, + Object, + Unknown, +} + +impl core::fmt::Display for JsType { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Self::Number => write!(f, "number"), + Self::String => write!(f, "string"), + Self::Bool => write!(f, "boolean"), + Self::Array => write!(f, "array"), + Self::BigInt => write!(f, "bigint"), + Self::Function => write!(f, "function"), + Self::Symbol => write!(f, "symbol"), + Self::Undefined => write!(f, "undefined"), + Self::Null => write!(f, "null"), + Self::Object => write!(f, "object"), + Self::Unknown => write!(f, ""), + } + } +} + +impl JsType { + fn guess(js: &JsValue) -> JsType { + if js.as_f64().is_some() { + Self::Number + } else if js.as_string().is_some() { + Self::String + } else if js.as_bool().is_some() { + Self::Bool + } else if js.is_array() { + Self::Array + } else if js.is_bigint() { + Self::BigInt + } else if js.is_function() { + Self::Function + } else if js.is_symbol() { + Self::Symbol + } else if js.is_undefined() { + Self::Undefined + } else if js.is_null() { + Self::Null + } else if js.is_object() { + Self::Object + } else { + Self::Unknown + } + } +} + +/// Convert WASM-compatible type involved in nRPC streaming to Rust-centric type +pub trait FromWasmStreamableType: Sized { + /// Required method + fn from_wasm_streamable(js: JsValue) -> Result; +} + +macro_rules! trivial_convert_number { + ($ty: ty) => { + impl FromWasmStreamableType for $ty { + fn from_wasm_streamable(js: JsValue) -> Result { + if let Some(num) = js.as_f64() { + Ok(num as $ty) + } else { + Err(WasmStreamableConversionError::UnexpectedType { + expected: JsType::Number, + got: JsType::guess(&js), + }) + } + } + } + + impl IntoWasmStreamableType for $ty { + fn into_wasm_streamable(self) -> JsValue { + self.into() + } + } + }; +} + +trivial_convert_number! { f64 } +trivial_convert_number! { f32 } + +trivial_convert_number! { isize } +trivial_convert_number! { usize } + +trivial_convert_number! { i8 } +trivial_convert_number! { i16 } +trivial_convert_number! { i32 } +trivial_convert_number! { i64 } +trivial_convert_number! { i128 } + +trivial_convert_number! { u8 } +trivial_convert_number! { u16 } +trivial_convert_number! { u32 } +trivial_convert_number! { u64 } +trivial_convert_number! { u128 } + +impl FromWasmStreamableType for String { + fn from_wasm_streamable(js: JsValue) -> Result { + if let Some(s) = js.as_string() { + Ok(s) + } else { + Err(WasmStreamableConversionError::UnexpectedType { + expected: JsType::String, + got: JsType::guess(&js), + }) + } + } +} + +impl IntoWasmStreamableType for String { + fn into_wasm_streamable(self) -> JsValue { + self.into() + } +} + +impl FromWasmStreamableType for bool { + fn from_wasm_streamable(js: JsValue) -> Result { + if let Some(b) = js.as_bool() { + Ok(b) + } else { + Err(WasmStreamableConversionError::UnexpectedType { + expected: JsType::Bool, + got: JsType::guess(&js), + }) + } + } +} + +impl IntoWasmStreamableType for bool { + fn into_wasm_streamable(self) -> JsValue { + self.into() + } +} + +impl FromWasmStreamableType for () { + fn from_wasm_streamable(_js: JsValue) -> Result { + Ok(()) + } +} + +impl IntoWasmStreamableType for () { + fn into_wasm_streamable(self) -> JsValue { + JsValue::undefined() + } +}