From b5596cf0ba2e09b59b56fb718f88359e10466597 Mon Sep 17 00:00:00 2001 From: Tricked <72335827+SkyBlockDev@users.noreply.github.com> Date: Sat, 19 Feb 2022 09:12:12 +0100 Subject: [PATCH 01/11] feat: begin cloudflare worker stuff --- Cargo.lock | 517 +++++++++++++++++----- Cargo.toml | 1 + examples/cloudflare/.cargo-ok | 0 examples/cloudflare/.gitignore | 4 + examples/cloudflare/Cargo.lock | 703 ++++++++++++++++++++++++++++++ examples/cloudflare/Cargo.toml | 26 ++ examples/cloudflare/README.md | 41 ++ examples/cloudflare/src/lib.rs | 59 +++ examples/cloudflare/src/utils.rs | 12 + examples/cloudflare/wrangler.toml | 22 + github-rest/src/methods/misc.rs | 16 +- octocat-rs/Cargo.toml | 4 + octocat-rs/src/github/client.rs | 183 +++++++- octocat-rs/src/lib.rs | 3 + 14 files changed, 1463 insertions(+), 128 deletions(-) create mode 100644 examples/cloudflare/.cargo-ok create mode 100644 examples/cloudflare/.gitignore create mode 100644 examples/cloudflare/Cargo.lock create mode 100644 examples/cloudflare/Cargo.toml create mode 100644 examples/cloudflare/README.md create mode 100644 examples/cloudflare/src/lib.rs create mode 100644 examples/cloudflare/src/utils.rs create mode 100644 examples/cloudflare/wrangler.toml diff --git a/Cargo.lock b/Cargo.lock index f8822996..c4e7ecba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,9 +13,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.53" +version = "1.0.54" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94a45b455c14666b85fc40a019e8ab9eb75e3a124e05494f5397122bc9eb06e0" +checksum = "7a99269dff3bc004caa411f38845c20303f1e393ca2bd6581576fa3a7f59577d" [[package]] name = "async-trait" @@ -41,9 +41,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "base64" @@ -78,6 +78,15 @@ dependencies = [ "generic-array", ] +[[package]] +name = "block-buffer" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324" +dependencies = [ + "generic-array", +] + [[package]] name = "buf_redux" version = "0.8.4" @@ -108,9 +117,15 @@ checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" [[package]] name = "cc" -version = "1.0.72" +version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee" +checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" [[package]] name = "cfg-if" @@ -118,6 +133,50 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +dependencies = [ + "js-sys", + "num-integer", + "num-traits", + "wasm-bindgen", +] + +[[package]] +name = "chrono-tz" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58549f1842da3080ce63002102d5bc954c7bc843d4f47818e642abdc36253552" +dependencies = [ + "chrono", + "chrono-tz-build", + "phf", +] + +[[package]] +name = "chrono-tz-build" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db058d493fb2f65f41861bfed7e3fe6335264a9f0f92710cab5bdf01fef09069" +dependencies = [ + "parse-zoneinfo", + "phf", + "phf_codegen", +] + +[[package]] +name = "cloudflare" +version = "0.1.0" +dependencies = [ + "cfg-if 1.0.0", + "console_error_panic_hook", + "octocat-rs", + "serde_json", +] + [[package]] name = "commitsummary" version = "0.1.0" @@ -131,11 +190,21 @@ dependencies = [ "tokio", ] +[[package]] +name = "console_error_panic_hook" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" +dependencies = [ + "cfg-if 1.0.0", + "wasm-bindgen", +] + [[package]] name = "core-foundation" -version = "0.9.2" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6888e10551bb93e424d8df1d07f1a8b4fceb0001a3a4b048bfc47554946f47b3" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" dependencies = [ "core-foundation-sys", "libc", @@ -156,6 +225,16 @@ dependencies = [ "libc", ] +[[package]] +name = "crypto-common" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57952ca27b5e3606ff4dd79b0020231aaf9d6aa76dc05fd30137538c50bd3ce8" +dependencies = [ + "generic-array", + "typenum", +] + [[package]] name = "digest" version = "0.9.0" @@ -165,13 +244,23 @@ dependencies = [ "generic-array", ] +[[package]] +name = "digest" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506" +dependencies = [ + "block-buffer 0.10.2", + "crypto-common", +] + [[package]] name = "encoding_rs" version = "0.8.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7896dc8abb250ffdda33912550faa54c88ec8b998dec0b2c55ab224921ce11df" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] @@ -189,9 +278,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "1.6.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "779d043b6a0b90cc4c0ed7ee380a6504394cee7efd7db050e3774eee387324b2" +checksum = "c3fcf0cee53519c866c09b5de1f6c56ff9d647101f81c1964fa632e148896cdf" dependencies = [ "instant", ] @@ -229,9 +318,9 @@ dependencies = [ [[package]] name = "futures" -version = "0.3.19" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28560757fe2bb34e79f907794bb6b22ae8b0e5c669b638a1132f2592b19035b4" +checksum = "f73fe65f54d1e12b726f517d3e2135ca3125a437b6d998caf1962961f7172d9e" dependencies = [ "futures-channel", "futures-core", @@ -244,9 +333,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.19" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba3dda0b6588335f360afc675d0564c17a77a2bda81ca178a4b6081bd86c7f0b" +checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010" dependencies = [ "futures-core", "futures-sink", @@ -254,15 +343,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.19" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0c8ff0461b82559810cdccfde3215c3f373807f5e5232b71479bff7bb2583d7" +checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3" [[package]] name = "futures-executor" -version = "0.3.19" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29d6d2ff5bb10fb95c85b8ce46538a2e5f5e7fdc755623a7d4529ab8a4ed9d2a" +checksum = "9420b90cfa29e327d0429f19be13e7ddb68fa1cccb09d65e5706b8c7a749b8a6" dependencies = [ "futures-core", "futures-task", @@ -271,15 +360,15 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.19" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f9d34af5a1aac6fb380f735fe510746c38067c5bf16c7fd250280503c971b2" +checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b" [[package]] name = "futures-macro" -version = "0.3.19" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6dbd947adfffb0efc70599b3ddcf7b5597bb5fa9e245eb99f62b3a5f7bb8bd3c" +checksum = "33c1e13800337f4d4d7a316bf45a567dbcb6ffe087f16424852d97e97a91f512" dependencies = [ "proc-macro2", "quote", @@ -288,21 +377,21 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.19" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3055baccb68d74ff6480350f8d6eb8fcfa3aa11bdc1a1ae3afdd0514617d508" +checksum = "21163e139fa306126e6eedaf49ecdb4588f939600f0b1e770f4205ee4b7fa868" [[package]] name = "futures-task" -version = "0.3.19" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ee7c6485c30167ce4dfb83ac568a849fe53274c831081476ee13e0dce1aad72" +checksum = "57c66a976bf5909d801bbef33416c41372779507e7a6b3a5e25e4749c58f776a" [[package]] name = "futures-util" -version = "0.3.19" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b5cf40b47a271f77a8b1bec03ca09044d99d2372c0de244e66430761127164" +checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a" dependencies = [ "futures-channel", "futures-core", @@ -332,7 +421,7 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "418d37c8b1d42553c93648be529cb70f920d3baf8ef469b74b9638df426e0b4c" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "libc", "wasi", ] @@ -340,7 +429,7 @@ dependencies = [ [[package]] name = "github-api" version = "0.1.0" -source = "git+https://github.com/octocat-rs/github-api#6863a238c51ed4a142700a5158ee998b6f6e6c4c" +source = "git+https://github.com/octocat-rs/github-api#638ff4e6ce16e112d74845e04146b6d29d0543f2" dependencies = [ "serde", "serde_json", @@ -361,9 +450,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.10" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c9de88456263e249e241fcd211d3954e2c9b0ef7ccfc235a444eb367cae3689" +checksum = "d9f1f717ddc7b2ba36df7e871fd88db79326551d3d6f1fc406fbfd28b582ff8e" dependencies = [ "bytes", "fnv", @@ -386,9 +475,9 @@ checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" [[package]] name = "headers" -version = "0.3.5" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4c4eb0471fcb85846d8b0690695ef354f9afb11cb03cac2e1d7c9253351afb0" +checksum = "4cff78e5788be1e0ab65b04d306b2ed5092c815ec97ec70f4ebd5aee158aa55d" dependencies = [ "base64", "bitflags", @@ -397,7 +486,7 @@ dependencies = [ "http", "httpdate", "mime", - "sha-1", + "sha-1 0.10.0", ] [[package]] @@ -435,7 +524,7 @@ checksum = "31f4c6746584866f0feabcc69893c5b51beef3831656a968ed7ae254cdc4fd03" dependencies = [ "bytes", "fnv", - "itoa 1.0.1", + "itoa", ] [[package]] @@ -451,9 +540,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.5.1" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acd94fdbe1d4ff688b67b04eee2e17bd50995534a61539e45adfefb45e5e5503" +checksum = "9100414882e15fb7feccb4897e5f0ff0ff1ca7d1a86a23208ada4d7a18e6c6c4" [[package]] name = "httpdate" @@ -472,9 +561,9 @@ dependencies = [ [[package]] name = "hyper" -version = "0.14.16" +version = "0.14.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7ec3e62bdc98a2f0393a5048e4c30ef659440ea6e0e572965103e72bd836f55" +checksum = "043f0e083e9901b6cc658a77d1eb86f4fc650bbb977a4337dd63192826aa85dd" dependencies = [ "bytes", "futures-channel", @@ -485,7 +574,7 @@ dependencies = [ "http-body", "httparse", "httpdate", - "itoa 0.4.8", + "itoa", "pin-project-lite", "socket2", "tokio", @@ -534,7 +623,7 @@ version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] @@ -543,12 +632,6 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68f2d64f2edebec4ce84ad108148e67e1064789bee435edc5b60ad398714a3a9" -[[package]] -name = "itoa" -version = "0.4.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" - [[package]] name = "itoa" version = "1.0.1" @@ -572,15 +655,15 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.112" +version = "0.2.118" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125" +checksum = "06e509672465a0504304aa87f9f176f2b2b716ed8fb105ebe5c02dc6dce96a94" [[package]] name = "lock_api" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712a4d093c9976e24e7dbca41db895dabcbac38eb5f4045393d17a95bdfb1109" +checksum = "88943dd7ef4a2e5a4bfa2753aaab3013e34ce2533d1996fb18ef591e315e2b3b" dependencies = [ "scopeguard", ] @@ -591,7 +674,7 @@ version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] @@ -600,6 +683,12 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" +[[package]] +name = "matchit" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9376a4f0340565ad675d11fc1419227faf5f60cd7ac9cb2e7185a471f30af833" + [[package]] name = "memchr" version = "2.4.1" @@ -614,9 +703,9 @@ checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" [[package]] name = "mime_guess" -version = "2.0.3" +version = "2.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2684d4c2e97d99848d30b324b00c8fcc7e5c897b7cbb5819b09e7c90e8baf212" +checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" dependencies = [ "mime", "unicase", @@ -624,9 +713,9 @@ dependencies = [ [[package]] name = "mio" -version = "0.7.14" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8067b404fe97c70829f082dec8bcf4f71225d7eaea1d8645349cb76fa06205cc" +checksum = "ba272f85fa0b41fc91872be579b3bbe0f56b792aa361a380eb669469f68dafb2" dependencies = [ "libc", "log", @@ -682,13 +771,32 @@ dependencies = [ [[package]] name = "ntapi" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" +checksum = "c28774a7fd2fbb4f0babd8237ce554b73af68021b5f695a3cebd6c59bac0980f" dependencies = [ "winapi", ] +[[package]] +name = "num-integer" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +dependencies = [ + "autocfg", +] + [[package]] name = "num_cpus" version = "1.13.1" @@ -720,6 +828,7 @@ dependencies = [ "tokio", "toml", "warp", + "worker", ] [[package]] @@ -741,7 +850,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c7ae222234c30df141154f159066c5093ff73b63204dcda7121eb082fc56a95" dependencies = [ "bitflags", - "cfg-if", + "cfg-if 1.0.0", "foreign-types", "libc", "once_cell", @@ -769,27 +878,34 @@ dependencies = [ [[package]] name = "parking_lot" -version = "0.11.2" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" +checksum = "87f5ec2493a61ac0506c0f4199f99070cbe83857b0337006a30f3e6719b8ef58" dependencies = [ - "instant", "lock_api", "parking_lot_core", ] [[package]] name = "parking_lot_core" -version = "0.8.5" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" +checksum = "28141e0cc4143da2443301914478dc976a61ffdb3f043058310c70df2fed8954" dependencies = [ - "cfg-if", - "instant", + "cfg-if 1.0.0", "libc", "redox_syscall", "smallvec", - "winapi", + "windows-sys", +] + +[[package]] +name = "parse-zoneinfo" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c705f256449c60da65e11ff6626e0c16a0a0b96aaa348de61376b249bc340f41" +dependencies = [ + "regex", ] [[package]] @@ -798,6 +914,45 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator", + "phf_shared", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared", + "rand", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", + "uncased", +] + [[package]] name = "pin-project" version = "1.0.10" @@ -869,23 +1024,22 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quote" -version = "1.0.14" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47aa80447ce4daf1717500037052af176af5d38cc3e571d9ec1c7353fc10c87d" +checksum = "864d3e96a899863136fc6e99f3d7cae289dafe43bf2c5ac19b70df7210c0a145" dependencies = [ "proc-macro2", ] [[package]] name = "rand" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", "rand_chacha", "rand_core", - "rand_hc", ] [[package]] @@ -907,15 +1061,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rand_hc" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7" -dependencies = [ - "rand_core", -] - [[package]] name = "redox_syscall" version = "0.2.10" @@ -1029,9 +1174,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "security-framework" -version = "2.4.2" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525bc1abfda2e1998d152c45cf13e696f76d0a4972310b22fac1658b05df7c87" +checksum = "2dc14f172faf8a0194a3aded622712b0de276821addc574fa54fc0a1167e10dc" dependencies = [ "bitflags", "core-foundation", @@ -1042,9 +1187,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.4.2" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9dd14d83160b528b7bfd66439110573efcfbe281b17fc2ca9f39f550d619c7e" +checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" dependencies = [ "core-foundation-sys", "libc", @@ -1052,18 +1197,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.133" +version = "1.0.136" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97565067517b60e2d1ea8b268e59ce036de907ac523ad83a0475da04e818989a" +checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.133" +version = "1.0.136" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed201699328568d8d08208fdd080e3ff594e6c422e438b6705905da01005d537" +checksum = "08597e7152fcd306f41838ed3e37be9eaeed2b61c42e2117266a554fab4662f9" dependencies = [ "proc-macro2", "quote", @@ -1072,23 +1217,23 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.74" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee2bb9cd061c5865d345bb02ca49fcef1391741b672b54a0bf7b679badec3142" +checksum = "8e8d9fa5c3b304765ce1fd9c4c8a3de2c8db365a5b91be52f186efc675681d95" dependencies = [ - "itoa 1.0.1", + "itoa", "ryu", "serde", ] [[package]] name = "serde_urlencoded" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edfa57a7f8d9c1d260a549e7224100f6c43d43f9103e06dd8b4095a9b2b43ce9" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" dependencies = [ "form_urlencoded", - "itoa 0.4.8", + "itoa", "ryu", "serde", ] @@ -1099,13 +1244,24 @@ version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "99cd6713db3cf16b6c84e06321e049a9b9f699826e16096d23bbcc44d15d51a6" dependencies = [ - "block-buffer", - "cfg-if", + "block-buffer 0.9.0", + "cfg-if 1.0.0", "cpufeatures", - "digest", + "digest 0.9.0", "opaque-debug", ] +[[package]] +name = "sha-1" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "028f48d513f9678cda28f6e4064755b3fbb2af6acd672f2c209b62323f7aea0f" +dependencies = [ + "cfg-if 1.0.0", + "cpufeatures", + "digest 0.10.3", +] + [[package]] name = "signal-hook-registry" version = "1.4.0" @@ -1115,6 +1271,12 @@ dependencies = [ "libc", ] +[[package]] +name = "siphasher" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a86232ab60fa71287d7f2ddae4a7073f6b7aac33631c3015abb556f08c6d0a3e" + [[package]] name = "slab" version = "0.4.5" @@ -1129,9 +1291,9 @@ checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" [[package]] name = "socket2" -version = "0.4.2" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dc90fe6c7be1a323296982db1836d1ea9e47b6839496dde9a541bc496df3516" +checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" dependencies = [ "libc", "winapi", @@ -1161,9 +1323,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.85" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a684ac3dcd8913827e18cd09a68384ee66c1de24157e3c556c9ab16d85695fb7" +checksum = "8a65b3f4ffa0092e9887669db0eae07941f023991ab58ea44da8fe8e2d511c6b" dependencies = [ "proc-macro2", "quote", @@ -1176,7 +1338,7 @@ version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "fastrand", "libc", "redox_syscall", @@ -1230,9 +1392,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.15.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbbf1c778ec206785635ce8ad57fe52b3009ae9e0c9f574a728f3049d3e55838" +checksum = "2af73ac49756f3f7c01172e34a23e5d0216f6c32333757c2c61feb2bbff5a5ee" dependencies = [ "bytes", "libc", @@ -1243,6 +1405,7 @@ dependencies = [ "parking_lot", "pin-project-lite", "signal-hook-registry", + "socket2", "tokio-macros", "winapi", ] @@ -1323,11 +1486,11 @@ checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" [[package]] name = "tracing" -version = "0.1.29" +version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105" +checksum = "f6c650a8ef0cd2dd93736f033d21cbd1224c5a967aa0c258d00fcf7dafef9b9f" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "log", "pin-project-lite", "tracing-core", @@ -1335,9 +1498,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.21" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4ed65637b8390770814083d20756f87bfa2c21bf2f110babdc5438351746e4" +checksum = "03cfcb51380632a72d3111cb8d3447a8d908e577d31beeac006f836383d29a23" dependencies = [ "lazy_static", ] @@ -1361,7 +1524,7 @@ dependencies = [ "httparse", "log", "rand", - "sha-1", + "sha-1 0.9.8", "thiserror", "url", "utf-8", @@ -1382,6 +1545,15 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" +[[package]] +name = "uncased" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5baeed7327e25054889b9bd4f975f32e5f4c5d434042d59ab6cd4142c0a76ed0" +dependencies = [ + "version_check", +] + [[package]] name = "unicase" version = "2.6.0" @@ -1408,9 +1580,9 @@ dependencies = [ [[package]] name = "unicode-segmentation" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" +checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99" [[package]] name = "unicode-xid" @@ -1500,7 +1672,9 @@ version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "632f73e236b219150ea279196e54e610f5dbafa5d61786303d4da54f84e47fce" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", + "serde", + "serde_json", "wasm-bindgen-macro", ] @@ -1525,7 +1699,7 @@ version = "0.4.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e8d7523cb1f2a4c96c1317ca690031b714a51cc14e05f712446691f413f5d39" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "js-sys", "wasm-bindgen", "web-sys", @@ -1601,6 +1775,49 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-sys" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3df6e476185f92a12c072be4a189a0210dcdcf512a1891d6dff9edb874deadc6" +dependencies = [ + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_msvc" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8e92753b1c443191654ec532f14c199742964a061be25d77d7a96f09db20bf5" + +[[package]] +name = "windows_i686_gnu" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a711c68811799e017b6038e0922cb27a5e2f43a2ddb609fe0b6f3eeda9de615" + +[[package]] +name = "windows_i686_msvc" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "146c11bb1a02615db74680b32a68e2d61f553cc24c4eb5b4ca10311740e44172" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c912b12f7454c6620635bbff3450962753834be2a594819bd5e945af18ec64bc" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "504a2476202769977a040c6364301a3f65d0cc9e3fb08600b2bda150a0488316" + [[package]] name = "winreg" version = "0.7.0" @@ -1609,3 +1826,69 @@ checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69" dependencies = [ "winapi", ] + +[[package]] +name = "worker" +version = "0.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61ca7d7e62ce3c18176bafbb9efff5f2f599aefb01bf81a51e003f4fd47e2606" +dependencies = [ + "async-trait", + "chrono", + "chrono-tz", + "futures", + "http", + "js-sys", + "matchit", + "pin-project", + "serde", + "serde_json", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "worker-kv", + "worker-macros", + "worker-sys", +] + +[[package]] +name = "worker-kv" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "682cbd728f179cc810b2ab77a2534da817b973e190ab184ab8efe1058b0dba84" +dependencies = [ + "js-sys", + "serde", + "serde_json", + "thiserror", + "wasm-bindgen", + "wasm-bindgen-futures", +] + +[[package]] +name = "worker-macros" +version = "0.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69c2b482518c7ae1d3f72917864cbd068ca65f0236e5deec0039713321c68489" +dependencies = [ + "async-trait", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen", + "wasm-bindgen-futures", + "wasm-bindgen-macro-support", + "worker-sys", +] + +[[package]] +name = "worker-sys" +version = "0.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96a9f46a3d2efc59119aa60229bc00f01e5bd178ac8b3a7b5cdbe0b70909973d" +dependencies = [ + "cfg-if 0.1.10", + "js-sys", + "wasm-bindgen", + "web-sys", +] diff --git a/Cargo.toml b/Cargo.toml index 9c8423ad..5df8c1d5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ members = [ "github-rest", "examples/basic", "examples/commitsummary", + "examples/cloudflare", #"examples/config-file", ] default-members = ["octocat-rs", "github-rest"] diff --git a/examples/cloudflare/.cargo-ok b/examples/cloudflare/.cargo-ok new file mode 100644 index 00000000..e69de29b diff --git a/examples/cloudflare/.gitignore b/examples/cloudflare/.gitignore new file mode 100644 index 00000000..40e49041 --- /dev/null +++ b/examples/cloudflare/.gitignore @@ -0,0 +1,4 @@ +/target +**/*.rs.bk +wasm-pack.log +build/ \ No newline at end of file diff --git a/examples/cloudflare/Cargo.lock b/examples/cloudflare/Cargo.lock new file mode 100644 index 00000000..ce8dac3b --- /dev/null +++ b/examples/cloudflare/Cargo.lock @@ -0,0 +1,703 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "0.6.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81ce3d38065e618af2d7b77e10c5ad9a069859b4be3c2250f674af3840d9c8a5" +dependencies = [ + "memchr", +] + +[[package]] +name = "async-trait" +version = "0.1.51" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44318e776df68115a881de9a8fd1b9e53368d7a4a5ce4cc48517da3393233a5e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + +[[package]] +name = "bumpalo" +version = "3.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c59e7af012c713f529e7a3ee57ce9b31ddd858d4b512923602f74608b009631" + +[[package]] +name = "bytes" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +dependencies = [ + "libc", + "num-integer", + "num-traits", + "time", + "winapi", +] + +[[package]] +name = "chrono-tz" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa1878c18b5b01b9978d5f130fe366d434022004d12fb87c182e8459b427c4a3" +dependencies = [ + "chrono", + "parse-zoneinfo", +] + +[[package]] +name = "console_error_panic_hook" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8d976903543e0c48546a91908f21588a680a8c8f984df9a5d69feccb2b2a211" +dependencies = [ + "cfg-if 0.1.10", + "wasm-bindgen", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "form_urlencoded" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" +dependencies = [ + "matches", + "percent-encoding", +] + +[[package]] +name = "futures" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a12aa0eb539080d55c3f2d45a67c3b58b6b0773c1a3ca2dfec66d58c97fd66ca" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5da6ba8c3bb3c165d3c7319fc1cc8304facf1fb8db99c5de877183c08a273888" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88d1c26957f23603395cd326b0ffe64124b818f4449552f960d815cfba83a53d" + +[[package]] +name = "futures-executor" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45025be030969d763025784f7f355043dc6bc74093e4ecc5000ca4dc50d8745c" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "522de2a0fe3e380f1bc577ba0474108faf3f6b18321dbf60b3b9c39a75073377" + +[[package]] +name = "futures-macro" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18e4a4b95cea4b4ccbcf1c5675ca7c4ee4e9e75eb79944d07defde18068f79bb" +dependencies = [ + "autocfg", + "proc-macro-hack", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36ea153c13024fe480590b3e3d4cad89a0cfacecc24577b68f86c6ced9c2bc11" + +[[package]] +name = "futures-task" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d3d00f4eddb73e498a54394f228cd55853bdf059259e8e7bc6e69d408892e99" + +[[package]] +name = "futures-util" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36568465210a3a6ee45e1f165136d68671471a501e632e9a98d96872222b5481" +dependencies = [ + "autocfg", + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "proc-macro-hack", + "proc-macro-nested", + "slab", +] + +[[package]] +name = "http" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "527e8c9ac747e28542699a951517aa9a6945af506cd1f2e1b53a576c17b6cc11" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "idna" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" +dependencies = [ + "matches", + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "itoa" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" + +[[package]] +name = "js-sys" +version = "0.3.53" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4bf49d50e2961077d9c99f4b7997d770a1114f087c3c2e0069b36c13fc2979d" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.101" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3cb00336871be5ed2c8ed44b60ae9959dc5b9f08539422ed43f09e34ecaeba21" + +[[package]] +name = "log" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "matches" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" + +[[package]] +name = "matchit" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31cfc429bbf773f52282c32c240342a21495ce9fa1e3721998295d2027969f6a" + +[[package]] +name = "memchr" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" + +[[package]] +name = "memory_units" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" + +[[package]] +name = "name" +version = "0.1.0" +dependencies = [ + "cfg-if 0.1.10", + "console_error_panic_hook", + "serde_json", + "wee_alloc", + "worker", +] + +[[package]] +name = "num-integer" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +dependencies = [ + "autocfg", +] + +[[package]] +name = "parse-zoneinfo" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4ee19a3656dadae35a33467f9714f1228dd34766dbe49e10e656b5296867aea" +dependencies = [ + "regex", +] + +[[package]] +name = "percent-encoding" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" + +[[package]] +name = "pin-project-lite" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro-hack" +version = "0.5.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" + +[[package]] +name = "proc-macro-nested" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" + +[[package]] +name = "proc-macro2" +version = "1.0.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9f5105d4fdaab20335ca9565e106a5d9b82b6219b5ba735731124ac6711d23d" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "regex" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9329abc99e39129fcceabd24cf5d85b4671ef7c29c50e972bc5afe32438ec384" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", + "thread_local", + "utf8-ranges", +] + +[[package]] +name = "regex-syntax" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d707a4fa2637f2dca2ef9fd02225ec7661fe01a53623c1e6515b6916511f7a7" +dependencies = [ + "ucd-util", +] + +[[package]] +name = "ryu" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" + +[[package]] +name = "serde" +version = "1.0.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.67" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7f9e390c27c3c0ce8bc5d725f6e4d30a29d26659494aa4b17535f7522c5c950" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "slab" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c307a32c1c5c437f38c7fd45d753050587732ba8628319fbdf12a7e289ccc590" + +[[package]] +name = "syn" +version = "1.0.75" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7f58f7e8eaa0009c5fec437aabf511bd9933e4b2d7407bd05273c01a8906ea7" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "thread_local" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "time" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +dependencies = [ + "libc", + "wasi", + "winapi", +] + +[[package]] +name = "tinyvec" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "848a1e1181b9f6753b5e96a092749e29b11d19ede67dfbbd6c7dc7e0f49b5338" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" + +[[package]] +name = "ucd-util" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c85f514e095d348c279b1e5cd76795082cf15bd59b93207832abe0b1d8fed236" + +[[package]] +name = "unicode-bidi" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "246f4c42e67e7a4e3c6106ff716a5d067d4132a642840b242e357e468a2a0085" + +[[package]] +name = "unicode-normalization" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-xid" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" + +[[package]] +name = "url" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" +dependencies = [ + "form_urlencoded", + "idna", + "matches", + "percent-encoding", +] + +[[package]] +name = "utf8-ranges" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4ae116fef2b7fea257ed6440d3cfcff7f190865f170cdad00bb6465bf18ecba" + +[[package]] +name = "wasi" +version = "0.10.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" + +[[package]] +name = "wasm-bindgen" +version = "0.2.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ce9b1b516211d33767048e5d47fa2a381ed8b76fc48d2ce4aa39877f9f183e0" +dependencies = [ + "cfg-if 1.0.0", + "serde", + "serde_json", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfe8dc78e2326ba5f845f4b5bf548401604fa20b1dd1d365fb73b6c1d6364041" +dependencies = [ + "bumpalo", + "lazy_static", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95fded345a6559c2cfee778d562300c581f7d4ff3edb9b0d230d69800d213972" +dependencies = [ + "cfg-if 1.0.0", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44468aa53335841d9d6b6c023eaab07c0cd4bddbcfdee3e2bb1e8d2cb8069fef" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0195807922713af1e67dc66132c7328206ed9766af3858164fb583eedc25fbad" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acdb075a845574a1fa5f09fd77e43f7747599301ea3417a9fbffdeedfc1f4a29" + +[[package]] +name = "web-sys" +version = "0.3.53" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224b2f6b67919060055ef1a67807367c2066ed520c3862cc013d26cf893a783c" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "wee_alloc" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" +dependencies = [ + "cfg-if 0.1.10", + "libc", + "memory_units", + "winapi", +] + +[[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-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "worker" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c9f2133f202313d54963c4299b169cb7567e78bf7fe46d3a5fd42d2487a46bc" +dependencies = [ + "async-trait", + "chrono", + "chrono-tz", + "futures", + "http", + "js-sys", + "matchit", + "serde", + "serde_json", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "worker-kv", + "worker-macros", + "worker-sys", +] + +[[package]] +name = "worker-kv" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6efd1fb8c8e36b99d22a8f77024df57943bd79852e8842731df21292e68aaf93" +dependencies = [ + "js-sys", + "serde", + "serde_json", + "wasm-bindgen", + "wasm-bindgen-futures", +] + +[[package]] +name = "worker-macros" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffb0170a9530c0d137e38915a385837d47109b3717f2f1c83f1cbcadf246eccc" +dependencies = [ + "async-trait", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen", + "wasm-bindgen-futures", + "wasm-bindgen-macro-support", + "worker-sys", +] + +[[package]] +name = "worker-sys" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4604db1de9c0c8e9fe83a9825dbd34047d3c5741c8681f1fbccdd7cc9dd8bdb8" +dependencies = [ + "cfg-if 0.1.10", + "js-sys", + "wasm-bindgen", + "web-sys", +] diff --git a/examples/cloudflare/Cargo.toml b/examples/cloudflare/Cargo.toml new file mode 100644 index 00000000..294afeb9 --- /dev/null +++ b/examples/cloudflare/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "cloudflare" +version = "0.1.0" +authors = ["Tricked "] +edition = "2018" + +[lib] +crate-type = ["cdylib", "rlib"] + +[features] +default = ["console_error_panic_hook"] + +[dependencies] +cfg-if = "1.0.0" +serde_json = "1.0.79" +octocat-rs = { path = "../../octocat-rs", features = ["workers"] } + +# The `console_error_panic_hook` crate provides better debugging of panics by +# logging them with `console.error`. This is great for development, but requires +# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for +# code size when deploying. +console_error_panic_hook = { version = "0.1.7", optional = true } + +[profile.release] +# Tell `rustc` to optimize for small code size. +opt-level = "s" diff --git a/examples/cloudflare/README.md b/examples/cloudflare/README.md new file mode 100644 index 00000000..6a4a5b8d --- /dev/null +++ b/examples/cloudflare/README.md @@ -0,0 +1,41 @@ +# Getting Started + +A template for kick starting a Cloudflare worker project using [`workers-rs`](https://github.com/cloudflare/workers-rs). + +This template is designed for compiling Rust to WebAssembly and publishing the resulting worker to +Cloudflare's [edge infrastructure](https://www.cloudflare.com/network/). + +## Usage + +This template starts you off with a `src/lib.rs` file, acting as an entrypoint for requests hitting +your Worker. Feel free to add more code in this file, or create Rust modules anywhere else for this +project to use. + +With `wrangler`, you can build, test, and deploy your Worker with the following commands: + +```bash +# compiles your project to WebAssembly and will warn of any issues +wrangler build + +# run your Worker in an ideal development workflow (with a local server, file watcher & more) +wrangler dev + +# deploy your Worker globally to the Cloudflare network (update your wrangler.toml file for configuration) +wrangler publish +``` + +Read the latest `worker` crate documentation here: https://docs.rs/worker + +## WebAssembly + +`workers-rs` (the Rust SDK for Cloudflare Workers used in this template) is meant to be executed as +compiled WebAssembly, and as such so **must** all the code you write and depend upon. All crates and +modules used in Rust-based Workers projects have to compile to the `wasm32-unknown-unknown` triple. + +Read more about this on the [`workers-rs` project README](https://github.com/cloudflare/workers-rs). + +## Issues + +If you have any problems with the `worker` crate, please open an issue on the upstream project +issue tracker on the [`workers-rs` repository](https://github.com/cloudflare/workers-rs). + diff --git a/examples/cloudflare/src/lib.rs b/examples/cloudflare/src/lib.rs new file mode 100644 index 00000000..477e20ae --- /dev/null +++ b/examples/cloudflare/src/lib.rs @@ -0,0 +1,59 @@ +use octocat_rs::worker::{self::*, worker_sys::ResponseInit}; +use serde_json::json; +mod utils; +use async_trait::async_trait; + +fn log_request(req: &Request) { + console_log!( + "{} - [{}], located at: {:?}, within: {}", + Date::now().to_string(), + req.path(), + req.cf().coordinates().unwrap_or_default(), + req.cf().region().unwrap_or("unknown region".into()) + ); +} + +#[event(fetch)] +pub async fn main(req: Request, env: Env, _ctx: worker::Context) -> Result { + log_request(&req); + + #[derive(Debug)] + struct Handler {} + + #[derive(Debug)] + enum Message { + Stuff(&'static str), + } + #[async_trait::async_trait] + impl EventHandler for Handler { + type Message = Message; + type GitHubClient = Client; + + fn listener_port(&self) -> u16 { + 2022 + } + async fn message(&self, message: Self::Message) { + match message { + Message::Stuff(s) => { + println!("==> Message received: {s}"); + } + } + } + async fn commit_event( + &self, + _github_client: Arc, + _commit: PushEvent, + ) -> Command { + println!("Commit pushed!"); + + Command::perform(async { "Computation finished" }, Message::Stuff) + } + } + + ClientBuilder::new() + .event_handler(Handler {}) + .build()? + .handle(req) + .await; + Response::empty() +} diff --git a/examples/cloudflare/src/utils.rs b/examples/cloudflare/src/utils.rs new file mode 100644 index 00000000..aab768f6 --- /dev/null +++ b/examples/cloudflare/src/utils.rs @@ -0,0 +1,12 @@ +use cfg_if::cfg_if; + +cfg_if! { + // https://github.com/rustwasm/console_error_panic_hook#readme + if #[cfg(feature = "console_error_panic_hook")] { + extern crate console_error_panic_hook; + pub use self::console_error_panic_hook::set_once as set_panic_hook; + } else { + #[inline] + pub fn set_panic_hook() {} + } +} diff --git a/examples/cloudflare/wrangler.toml b/examples/cloudflare/wrangler.toml new file mode 100644 index 00000000..177b3b66 --- /dev/null +++ b/examples/cloudflare/wrangler.toml @@ -0,0 +1,22 @@ +name = "cloudflare" +type = "javascript" +workers_dev = true +compatibility_date = "2022-02-19" + +[vars] +WORKERS_RS_VERSION = "0.0.9" + +[build] +command = "cargo install -q worker-build && worker-build --release" # required + +[build.upload] +dir = "build/worker" +format = "modules" +main = "./shim.mjs" + +[[build.upload.rules]] +globs = ["**/*.wasm"] +type = "CompiledWasm" + +# read more about configuring your Worker via wrangler.toml at: +# https://developers.cloudflare.com/workers/cli-wrangler/configuration diff --git a/github-rest/src/methods/misc.rs b/github-rest/src/methods/misc.rs index 9283d371..00208364 100644 --- a/github-rest/src/methods/misc.rs +++ b/github-rest/src/methods/misc.rs @@ -12,14 +12,14 @@ where client.raw_req::(EndPoints::GetZen(), None, None).await } -pub async fn api_info(client: &T) -> Result -where - T: Requester, -{ - client - .req::(EndPoints::Get(), None, None) - .await -} +//pub async fn api_info(client: &T) -> Result +//where +// T: Requester, +//{ +// client +// .req::(EndPoints::Get(), None, None) +// .await +//} //Role enum used for add to org function determines the function a user has // within a organization diff --git a/octocat-rs/Cargo.toml b/octocat-rs/Cargo.toml index 3469310c..35d1a070 100644 --- a/octocat-rs/Cargo.toml +++ b/octocat-rs/Cargo.toml @@ -44,3 +44,7 @@ lazy_static = "1.4.0" strum_macros = "0.23" reqwest = "^0.11.8" strum = "0.23.0" +worker = { version = "0.0.9", optional = true } + +[features] +workers = ["worker"] diff --git a/octocat-rs/src/github/client.rs b/octocat-rs/src/github/client.rs index 34630bef..4bd8abb7 100644 --- a/octocat-rs/src/github/client.rs +++ b/octocat-rs/src/github/client.rs @@ -127,6 +127,186 @@ impl Client where T: Debug + EventHandler> + Send + Sync + 'static, { + #[cfg(feature = "workers")] + pub async fn handle(self,mut req: worker::Request) { + let _ = self.run().await.expect("Starting application: User-defined code"); + + let self_arc = Arc::new(self); + let thread_self = self_arc.clone(); + let thread_self_2 = self_arc.clone(); + let mut user_cmd = Command::none(); + macro_rules! event_push { + ($f:ident, $t:ty) => { + user_cmd = thread_self + .event_handler() + .$f( + thread_self.clone(), + (req).json::<$t>().await.expect("Failed to parse json") + ) + .await + }; + } + let ev = serde_json::from_str(&req.headers().get("x-github-event").unwrap().unwrap()) + .expect("Failed to parse headers"); + match ev { + EventTypes::Push => { + event_push!(commit_event, PushEvent); + } + EventTypes::GithubAppAuthorization => { + event_push!(app_authorization_event, AppAuthorizationEvent); + } + EventTypes::Installation => { + event_push!(installation_event, InstallationEvent); + } + EventTypes::InstallationRepositories => { + event_push!(installation_repositories_event, InstallationRepositoriesEvent); + } + EventTypes::DeployKey => { + event_push!(deploy_key_event, DeployKeyEvent); + } + EventTypes::Gollum => { + event_push!(gollum_event, GollumEvent); + } + EventTypes::Member => { + event_push!(member_event, MemberEvent); + } + EventTypes::Milestone => { + event_push!(milestone_event, MilestoneEvent); + } + EventTypes::Public => { + event_push!(public_event, PublicEvent); + } + EventTypes::Release => { + event_push!(release_event, ReleaseEvent); + } + EventTypes::Repository => { + event_push!(repository_event, RepositoryEvent); + } + EventTypes::RepositoryDispatch => { + event_push!(repository_dispatch_event, RepositoryDispatchEvent); + } + EventTypes::RepositoryImport => { + event_push!(repository_import_event, RepositoryImportEvent); + } + EventTypes::RepositoryVulnerabilityAlert => { + event_push!(repository_vulnerability_alert, RepositoryVulnerabilityAlertEvent); + } + EventTypes::SecretScanningAlert => { + event_push!(secret_scanning_alert, SecretScanningAlertEvent); + } + EventTypes::SecurityAdvisory => { + event_push!(security_advisory, SecurityAdvisoryEvent); + } + EventTypes::Star => { + event_push!(star_event, StarEvent); + } + EventTypes::Watch => { + event_push!(watch_event, WatchEvent); + } + EventTypes::PullRequest => { + event_push!(pull_request_event, PullRequestEvent); + } + EventTypes::PullRequestReview => { + event_push!(pull_request_review_event, PullRequestReviewEvent); + } + EventTypes::PullRequestReviewComment => { + event_push!(pull_request_review_comment_event, PullRequestReviewCommentEvent); + } + EventTypes::CommitComment => { + event_push!(commit_comment_event, CommitCommentEvent); + } + EventTypes::Status => { + event_push!(status_event, StatusEvent); + } + EventTypes::IssueComment => { + event_push!(issue_comment_event, IssueCommentEvent); + } + EventTypes::Issues => { + event_push!(issue_event, IssueEvent); + } + EventTypes::Label => { + event_push!(label_event, LabelEvent); + } + EventTypes::Discussion => { + event_push!(discussion_event, DiscussionEvent); + } + EventTypes::DiscussionComment => { + event_push!(discussion_comment_event, DiscussionCommentEvent); + } + EventTypes::BranchProtectionRule => { + event_push!(branch_protection_rule_event, BranchProtectionRuleEvent); + } + EventTypes::Create => { + event_push!(tag_created, CreateEvent); + } + EventTypes::Delete => { + event_push!(tag_deleted, DeleteEvent); + } + EventTypes::Fork => { + event_push!(repository_forked, ForkEvent); + } + EventTypes::CheckRun => { + event_push!(check_run, CheckRunEvent); + } + EventTypes::CheckSuite => { + event_push!(check_suite_event, CheckSuiteEvent); + } + EventTypes::CodeScanningAlert => { + event_push!(code_scanning_alert_event, CodeScanningAlertEvent); + } + EventTypes::Deployment => { + event_push!(deployment_event, DeploymentEvent); + } + EventTypes::DeploymentStatus => { + event_push!(deployment_status_event, DeploymentStatusEvent); + } + EventTypes::PageBuild => { + event_push!(page_build_event, PageBuildEvent); + } + EventTypes::WorkflowDispatch => { + event_push!(workflow_dispatch_event, WorkflowDispatchEvent); + } + EventTypes::WorkflowJob => { + event_push!(workflow_job, WorkflowJobEvent); + } + EventTypes::WorkflowRun => { + event_push!(workflow_run, WorkflowRunEvent); + } + EventTypes::Membership => { + event_push!(membership_event, MembershipEvent); + } + EventTypes::OrgBlock => { + event_push!(org_block_event, OrgBlockEvent); + } + EventTypes::Organization => { + event_push!(organization_event, OrganizationEvent); + } + EventTypes::Team => { + event_push!(team_event, TeamEvent); + } + EventTypes::TeamAdd => { + event_push!(team_add_event, TeamAddEvent); + } + EventTypes::Project => { + event_push!(project_event, ProjectEvent); + } + EventTypes::ProjectCard => {} + EventTypes::ProjectColumn => {} + EventTypes::MarketplacePurchase => {} + EventTypes::Meta => {} + EventTypes::Package => {} + EventTypes::Ping => {} + EventTypes::Sponsorship => {} + }; + + let mut cmd = user_cmd.into_futures(); + + while let Some(c) = cmd.pop() { + thread_self_2.event_handler().message(c.await).await; + } + } + + #[cfg(not(feature = "workers"))] pub async fn start(self) { let _ = self.run().await.expect("Starting application: User-defined code"); @@ -156,9 +336,6 @@ where }; } - dbg!(&ev); - dbg!(&body.to_string()); - let ev_h = async { match ev { EventTypes::Push => { diff --git a/octocat-rs/src/lib.rs b/octocat-rs/src/lib.rs index 93fca14a..505c8651 100644 --- a/octocat-rs/src/lib.rs +++ b/octocat-rs/src/lib.rs @@ -13,6 +13,9 @@ pub mod github; pub use github_api as api; pub use github_rest as rest; +#[cfg(feature="workers")] +pub use worker; + #[cfg(test)] mod tests { #[test] From 33ed0a4978a4a33ff05fd40ce1ae94b92a2be2e1 Mon Sep 17 00:00:00 2001 From: Proudmuslim Date: Sun, 20 Feb 2022 09:54:12 -0800 Subject: [PATCH 02/11] wip: Begin fixes (see comment) The wasm target won't build, we need to do a lot of stuff with features to ensure that tokio doesn't get compiled when attempting to use the target --- Cargo.lock | 80 +------- examples/cloudflare/Cargo.toml | 6 +- examples/cloudflare/deps | 343 ++++++++++++++++++++++++++++++++ examples/cloudflare/src/lib.rs | 87 ++++---- github-rest/Cargo.toml | 2 +- github-rest/src/methods/misc.rs | 15 +- octocat-rs/Cargo.toml | 9 +- octocat-rs/src/github/client.rs | 9 +- octocat-rs/src/lib.rs | 4 +- 9 files changed, 417 insertions(+), 138 deletions(-) create mode 100644 examples/cloudflare/deps diff --git a/Cargo.lock b/Cargo.lock index c4e7ecba..2340da00 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,15 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "aho-corasick" -version = "0.7.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" -dependencies = [ - "memchr", -] - [[package]] name = "anyhow" version = "1.0.54" @@ -28,17 +19,6 @@ dependencies = [ "syn", ] -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi", - "libc", - "winapi", -] - [[package]] name = "autocfg" version = "1.1.0" @@ -171,10 +151,14 @@ dependencies = [ name = "cloudflare" version = "0.1.0" dependencies = [ + "anyhow", + "async-trait", "cfg-if 1.0.0", "console_error_panic_hook", "octocat-rs", "serde_json", + "wasm-bindgen-futures", + "worker", ] [[package]] @@ -263,19 +247,6 @@ dependencies = [ "cfg-if 1.0.0", ] -[[package]] -name = "env_logger" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" -dependencies = [ - "atty", - "humantime", - "log", - "regex", - "termcolor", -] - [[package]] name = "fastrand" version = "1.7.0" @@ -445,7 +416,6 @@ dependencies = [ "serde", "serde_json", "strum", - "tokio", ] [[package]] @@ -550,15 +520,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" -[[package]] -name = "humantime" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" -dependencies = [ - "quick-error", -] - [[package]] name = "hyper" version = "0.14.17" @@ -816,9 +777,6 @@ dependencies = [ "futures", "github-api", "github-rest", - "lazy_static", - "log", - "pretty_env_logger", "reqwest", "serde", "serde_json", @@ -997,16 +955,6 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" -[[package]] -name = "pretty_env_logger" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "926d36b9553851b8b0005f1275891b392ee4d2d833852c417ed025477350fb9d" -dependencies = [ - "env_logger", - "log", -] - [[package]] name = "proc-macro2" version = "1.0.36" @@ -1076,8 +1024,6 @@ version = "1.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" dependencies = [ - "aho-corasick", - "memchr", "regex-syntax", ] @@ -1346,15 +1292,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "termcolor" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" -dependencies = [ - "winapi-util", -] - [[package]] name = "thiserror" version = "1.0.30" @@ -1760,15 +1697,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -[[package]] -name = "winapi-util" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" -dependencies = [ - "winapi", -] - [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" diff --git a/examples/cloudflare/Cargo.toml b/examples/cloudflare/Cargo.toml index 294afeb9..519a61a1 100644 --- a/examples/cloudflare/Cargo.toml +++ b/examples/cloudflare/Cargo.toml @@ -13,13 +13,17 @@ default = ["console_error_panic_hook"] [dependencies] cfg-if = "1.0.0" serde_json = "1.0.79" -octocat-rs = { path = "../../octocat-rs", features = ["workers"] } +octocat-rs = { path = "../../octocat-rs", features = ["workers"], default-features = false } +worker = "0.0.9" # The `console_error_panic_hook` crate provides better debugging of panics by # logging them with `console.error`. This is great for development, but requires # all the `std::fmt` and `std::panicking` infrastructure, so isn't great for # code size when deploying. console_error_panic_hook = { version = "0.1.7", optional = true } +async-trait = "0.1.52" +wasm-bindgen-futures = "0.4.1" +anyhow = "1" [profile.release] # Tell `rustc` to optimize for small code size. diff --git a/examples/cloudflare/deps b/examples/cloudflare/deps new file mode 100644 index 00000000..2aece43b --- /dev/null +++ b/examples/cloudflare/deps @@ -0,0 +1,343 @@ +cloudflare v0.1.0 (/home/twilight/CLionProjects/octocat-rs/examples/cloudflare) +├── anyhow v1.0.54 +├── async-trait v0.1.52 (proc-macro) +│ ├── proc-macro2 v1.0.36 +│ │ └── unicode-xid v0.2.2 +│ ├── quote v1.0.15 +│ │ └── proc-macro2 v1.0.36 (*) +│ └── syn v1.0.86 +│ ├── proc-macro2 v1.0.36 (*) +│ ├── quote v1.0.15 (*) +│ └── unicode-xid v0.2.2 +├── cfg-if v1.0.0 +├── console_error_panic_hook v0.1.7 +│ ├── cfg-if v1.0.0 +│ └── wasm-bindgen v0.2.78 +│ ├── cfg-if v1.0.0 +│ ├── serde v1.0.136 +│ │ └── serde_derive v1.0.136 (proc-macro) +│ │ ├── proc-macro2 v1.0.36 (*) +│ │ ├── quote v1.0.15 (*) +│ │ └── syn v1.0.86 (*) +│ ├── serde_json v1.0.79 +│ │ ├── itoa v1.0.1 +│ │ ├── ryu v1.0.9 +│ │ └── serde v1.0.136 (*) +│ └── wasm-bindgen-macro v0.2.78 (proc-macro) +│ ├── quote v1.0.15 (*) +│ └── wasm-bindgen-macro-support v0.2.78 +│ ├── proc-macro2 v1.0.36 (*) +│ ├── quote v1.0.15 (*) +│ ├── syn v1.0.86 (*) +│ ├── wasm-bindgen-backend v0.2.78 +│ │ ├── bumpalo v3.9.1 +│ │ ├── lazy_static v1.4.0 +│ │ ├── log v0.4.14 +│ │ │ └── cfg-if v1.0.0 +│ │ ├── proc-macro2 v1.0.36 (*) +│ │ ├── quote v1.0.15 (*) +│ │ ├── syn v1.0.86 (*) +│ │ └── wasm-bindgen-shared v0.2.78 +│ └── wasm-bindgen-shared v0.2.78 +├── octocat-rs v0.0.0 (/home/twilight/CLionProjects/octocat-rs/octocat-rs) +│ ├── anyhow v1.0.54 +│ ├── async-trait v0.1.52 (proc-macro) (*) +│ ├── futures v0.3.21 +│ │ ├── futures-channel v0.3.21 +│ │ │ ├── futures-core v0.3.21 +│ │ │ └── futures-sink v0.3.21 +│ │ ├── futures-core v0.3.21 +│ │ ├── futures-executor v0.3.21 +│ │ │ ├── futures-core v0.3.21 +│ │ │ ├── futures-task v0.3.21 +│ │ │ └── futures-util v0.3.21 +│ │ │ ├── futures-channel v0.3.21 (*) +│ │ │ ├── futures-core v0.3.21 +│ │ │ ├── futures-io v0.3.21 +│ │ │ ├── futures-macro v0.3.21 (proc-macro) +│ │ │ │ ├── proc-macro2 v1.0.36 (*) +│ │ │ │ ├── quote v1.0.15 (*) +│ │ │ │ └── syn v1.0.86 (*) +│ │ │ ├── futures-sink v0.3.21 +│ │ │ ├── futures-task v0.3.21 +│ │ │ ├── memchr v2.4.1 +│ │ │ ├── pin-project-lite v0.2.8 +│ │ │ ├── pin-utils v0.1.0 +│ │ │ └── slab v0.4.5 +│ │ ├── futures-io v0.3.21 +│ │ ├── futures-sink v0.3.21 +│ │ ├── futures-task v0.3.21 +│ │ └── futures-util v0.3.21 (*) +│ ├── github-api v0.1.0 (https://github.com/octocat-rs/github-api#638ff4e6) +│ │ ├── serde v1.0.136 (*) +│ │ └── serde_json v1.0.79 (*) +│ ├── github-rest v0.1.0 (/home/twilight/CLionProjects/octocat-rs/github-rest) +│ │ ├── async-trait v0.1.52 (proc-macro) (*) +│ │ ├── github-api v0.1.0 (https://github.com/octocat-rs/github-api#638ff4e6) (*) +│ │ ├── reqwest v0.11.9 +│ │ │ ├── base64 v0.13.0 +│ │ │ ├── bytes v1.1.0 +│ │ │ ├── encoding_rs v0.8.30 +│ │ │ │ └── cfg-if v1.0.0 +│ │ │ ├── futures-core v0.3.21 +│ │ │ ├── futures-util v0.3.21 (*) +│ │ │ ├── h2 v0.3.11 +│ │ │ │ ├── bytes v1.1.0 +│ │ │ │ ├── fnv v1.0.7 +│ │ │ │ ├── futures-core v0.3.21 +│ │ │ │ ├── futures-sink v0.3.21 +│ │ │ │ ├── futures-util v0.3.21 (*) +│ │ │ │ ├── http v0.2.6 +│ │ │ │ │ ├── bytes v1.1.0 +│ │ │ │ │ ├── fnv v1.0.7 +│ │ │ │ │ └── itoa v1.0.1 +│ │ │ │ ├── indexmap v1.8.0 +│ │ │ │ │ └── hashbrown v0.11.2 +│ │ │ │ │ [build-dependencies] +│ │ │ │ │ └── autocfg v1.1.0 +│ │ │ │ ├── slab v0.4.5 +│ │ │ │ ├── tokio v1.17.0 +│ │ │ │ │ ├── bytes v1.1.0 +│ │ │ │ │ ├── libc v0.2.118 +│ │ │ │ │ ├── memchr v2.4.1 +│ │ │ │ │ ├── mio v0.8.0 +│ │ │ │ │ │ ├── libc v0.2.118 +│ │ │ │ │ │ └── log v0.4.14 (*) +│ │ │ │ │ ├── num_cpus v1.13.1 +│ │ │ │ │ │ └── libc v0.2.118 +│ │ │ │ │ ├── once_cell v1.9.0 +│ │ │ │ │ ├── parking_lot v0.12.0 +│ │ │ │ │ │ ├── lock_api v0.4.6 +│ │ │ │ │ │ │ └── scopeguard v1.1.0 +│ │ │ │ │ │ └── parking_lot_core v0.9.1 +│ │ │ │ │ │ ├── cfg-if v1.0.0 +│ │ │ │ │ │ ├── libc v0.2.118 +│ │ │ │ │ │ └── smallvec v1.8.0 +│ │ │ │ │ ├── pin-project-lite v0.2.8 +│ │ │ │ │ ├── signal-hook-registry v1.4.0 +│ │ │ │ │ │ └── libc v0.2.118 +│ │ │ │ │ ├── socket2 v0.4.4 +│ │ │ │ │ │ └── libc v0.2.118 +│ │ │ │ │ └── tokio-macros v1.7.0 (proc-macro) +│ │ │ │ │ ├── proc-macro2 v1.0.36 (*) +│ │ │ │ │ ├── quote v1.0.15 (*) +│ │ │ │ │ └── syn v1.0.86 (*) +│ │ │ │ ├── tokio-util v0.6.9 +│ │ │ │ │ ├── bytes v1.1.0 +│ │ │ │ │ ├── futures-core v0.3.21 +│ │ │ │ │ ├── futures-sink v0.3.21 +│ │ │ │ │ ├── log v0.4.14 (*) +│ │ │ │ │ ├── pin-project-lite v0.2.8 +│ │ │ │ │ └── tokio v1.17.0 (*) +│ │ │ │ └── tracing v0.1.31 +│ │ │ │ ├── cfg-if v1.0.0 +│ │ │ │ ├── pin-project-lite v0.2.8 +│ │ │ │ └── tracing-core v0.1.22 +│ │ │ │ └── lazy_static v1.4.0 +│ │ │ ├── http v0.2.6 (*) +│ │ │ ├── http-body v0.4.4 +│ │ │ │ ├── bytes v1.1.0 +│ │ │ │ ├── http v0.2.6 (*) +│ │ │ │ └── pin-project-lite v0.2.8 +│ │ │ ├── hyper v0.14.17 +│ │ │ │ ├── bytes v1.1.0 +│ │ │ │ ├── futures-channel v0.3.21 (*) +│ │ │ │ ├── futures-core v0.3.21 +│ │ │ │ ├── futures-util v0.3.21 (*) +│ │ │ │ ├── h2 v0.3.11 (*) +│ │ │ │ ├── http v0.2.6 (*) +│ │ │ │ ├── http-body v0.4.4 (*) +│ │ │ │ ├── httparse v1.6.0 +│ │ │ │ ├── httpdate v1.0.2 +│ │ │ │ ├── itoa v1.0.1 +│ │ │ │ ├── pin-project-lite v0.2.8 +│ │ │ │ ├── socket2 v0.4.4 (*) +│ │ │ │ ├── tokio v1.17.0 (*) +│ │ │ │ ├── tower-service v0.3.1 +│ │ │ │ ├── tracing v0.1.31 (*) +│ │ │ │ └── want v0.3.0 +│ │ │ │ ├── log v0.4.14 (*) +│ │ │ │ └── try-lock v0.2.3 +│ │ │ ├── hyper-rustls v0.23.0 +│ │ │ │ ├── http v0.2.6 (*) +│ │ │ │ ├── hyper v0.14.17 (*) +│ │ │ │ ├── rustls v0.20.4 +│ │ │ │ │ ├── log v0.4.14 (*) +│ │ │ │ │ ├── ring v0.16.20 +│ │ │ │ │ │ ├── libc v0.2.118 +│ │ │ │ │ │ ├── once_cell v1.9.0 +│ │ │ │ │ │ ├── spin v0.5.2 +│ │ │ │ │ │ └── untrusted v0.7.1 +│ │ │ │ │ │ [build-dependencies] +│ │ │ │ │ │ └── cc v1.0.73 +│ │ │ │ │ ├── sct v0.7.0 +│ │ │ │ │ │ ├── ring v0.16.20 (*) +│ │ │ │ │ │ └── untrusted v0.7.1 +│ │ │ │ │ └── webpki v0.22.0 +│ │ │ │ │ ├── ring v0.16.20 (*) +│ │ │ │ │ └── untrusted v0.7.1 +│ │ │ │ ├── tokio v1.17.0 (*) +│ │ │ │ └── tokio-rustls v0.23.2 +│ │ │ │ ├── rustls v0.20.4 (*) +│ │ │ │ ├── tokio v1.17.0 (*) +│ │ │ │ └── webpki v0.22.0 (*) +│ │ │ ├── hyper-tls v0.5.0 +│ │ │ │ ├── bytes v1.1.0 +│ │ │ │ ├── hyper v0.14.17 (*) +│ │ │ │ ├── native-tls v0.2.8 +│ │ │ │ │ ├── log v0.4.14 (*) +│ │ │ │ │ ├── openssl v0.10.38 +│ │ │ │ │ │ ├── bitflags v1.3.2 +│ │ │ │ │ │ ├── cfg-if v1.0.0 +│ │ │ │ │ │ ├── foreign-types v0.3.2 +│ │ │ │ │ │ │ └── foreign-types-shared v0.1.1 +│ │ │ │ │ │ ├── libc v0.2.118 +│ │ │ │ │ │ ├── once_cell v1.9.0 +│ │ │ │ │ │ └── openssl-sys v0.9.72 +│ │ │ │ │ │ └── libc v0.2.118 +│ │ │ │ │ │ [build-dependencies] +│ │ │ │ │ │ ├── autocfg v1.1.0 +│ │ │ │ │ │ ├── cc v1.0.73 +│ │ │ │ │ │ └── pkg-config v0.3.24 +│ │ │ │ │ ├── openssl-probe v0.1.5 +│ │ │ │ │ └── openssl-sys v0.9.72 (*) +│ │ │ │ ├── tokio v1.17.0 (*) +│ │ │ │ └── tokio-native-tls v0.3.0 +│ │ │ │ ├── native-tls v0.2.8 (*) +│ │ │ │ └── tokio v1.17.0 (*) +│ │ │ ├── ipnet v2.3.1 +│ │ │ ├── lazy_static v1.4.0 +│ │ │ ├── log v0.4.14 (*) +│ │ │ ├── mime v0.3.16 +│ │ │ ├── native-tls v0.2.8 (*) +│ │ │ ├── percent-encoding v2.1.0 +│ │ │ ├── pin-project-lite v0.2.8 +│ │ │ ├── rustls v0.20.4 (*) +│ │ │ ├── rustls-pemfile v0.2.1 +│ │ │ │ └── base64 v0.13.0 +│ │ │ ├── serde v1.0.136 (*) +│ │ │ ├── serde_urlencoded v0.7.1 +│ │ │ │ ├── form_urlencoded v1.0.1 +│ │ │ │ │ ├── matches v0.1.9 +│ │ │ │ │ └── percent-encoding v2.1.0 +│ │ │ │ ├── itoa v1.0.1 +│ │ │ │ ├── ryu v1.0.9 +│ │ │ │ └── serde v1.0.136 (*) +│ │ │ ├── tokio v1.17.0 (*) +│ │ │ ├── tokio-native-tls v0.3.0 (*) +│ │ │ ├── tokio-rustls v0.23.2 (*) +│ │ │ ├── url v2.2.2 +│ │ │ │ ├── form_urlencoded v1.0.1 (*) +│ │ │ │ ├── idna v0.2.3 +│ │ │ │ │ ├── matches v0.1.9 +│ │ │ │ │ ├── unicode-bidi v0.3.7 +│ │ │ │ │ └── unicode-normalization v0.1.19 +│ │ │ │ │ └── tinyvec v1.5.1 +│ │ │ │ │ └── tinyvec_macros v0.1.0 +│ │ │ │ ├── matches v0.1.9 +│ │ │ │ └── percent-encoding v2.1.0 +│ │ │ └── webpki-roots v0.22.2 +│ │ │ └── webpki v0.22.0 (*) +│ │ ├── serde v1.0.136 (*) +│ │ ├── serde_json v1.0.79 (*) +│ │ └── strum v0.23.0 +│ │ └── strum_macros v0.23.1 (proc-macro) +│ │ ├── heck v0.3.3 +│ │ │ └── unicode-segmentation v1.9.0 +│ │ ├── proc-macro2 v1.0.36 (*) +│ │ ├── quote v1.0.15 (*) +│ │ ├── rustversion v1.0.6 (proc-macro) +│ │ └── syn v1.0.86 (*) +│ ├── reqwest v0.11.9 (*) +│ ├── serde v1.0.136 (*) +│ ├── serde_json v1.0.79 (*) +│ ├── strum v0.23.0 (*) +│ ├── strum_macros v0.23.1 (proc-macro) (*) +│ ├── thiserror v1.0.30 +│ │ └── thiserror-impl v1.0.30 (proc-macro) +│ │ ├── proc-macro2 v1.0.36 (*) +│ │ ├── quote v1.0.15 (*) +│ │ └── syn v1.0.86 (*) +│ ├── tokio v1.17.0 (*) +│ ├── toml v0.5.8 +│ │ └── serde v1.0.136 (*) +│ └── worker v0.0.9 +│ ├── async-trait v0.1.52 (proc-macro) (*) +│ ├── chrono v0.4.19 +│ │ ├── num-integer v0.1.44 +│ │ │ └── num-traits v0.2.14 +│ │ │ [build-dependencies] +│ │ │ └── autocfg v1.1.0 +│ │ │ [build-dependencies] +│ │ │ └── autocfg v1.1.0 +│ │ └── num-traits v0.2.14 (*) +│ ├── chrono-tz v0.6.1 +│ │ ├── chrono v0.4.19 (*) +│ │ └── phf v0.10.1 +│ │ └── phf_shared v0.10.0 +│ │ ├── siphasher v0.3.9 +│ │ └── uncased v0.9.6 +│ │ [build-dependencies] +│ │ └── version_check v0.9.4 +│ │ [build-dependencies] +│ │ └── chrono-tz-build v0.0.2 +│ │ ├── parse-zoneinfo v0.3.0 +│ │ │ └── regex v1.5.4 +│ │ │ └── regex-syntax v0.6.25 +│ │ ├── phf v0.10.1 (*) +│ │ └── phf_codegen v0.10.0 +│ │ ├── phf_generator v0.10.0 +│ │ │ ├── phf_shared v0.10.0 (*) +│ │ │ └── rand v0.8.5 +│ │ │ ├── libc v0.2.118 +│ │ │ ├── rand_chacha v0.3.1 +│ │ │ │ ├── ppv-lite86 v0.2.16 +│ │ │ │ └── rand_core v0.6.3 +│ │ │ │ └── getrandom v0.2.4 +│ │ │ │ ├── cfg-if v1.0.0 +│ │ │ │ └── libc v0.2.118 +│ │ │ └── rand_core v0.6.3 (*) +│ │ └── phf_shared v0.10.0 (*) +│ ├── futures v0.3.21 (*) +│ ├── http v0.2.6 (*) +│ ├── js-sys v0.3.55 +│ │ └── wasm-bindgen v0.2.78 (*) +│ ├── matchit v0.4.6 +│ ├── pin-project v1.0.10 +│ │ └── pin-project-internal v1.0.10 (proc-macro) +│ │ ├── proc-macro2 v1.0.36 (*) +│ │ ├── quote v1.0.15 (*) +│ │ └── syn v1.0.86 (*) +│ ├── serde v1.0.136 (*) +│ ├── serde_json v1.0.79 (*) +│ ├── url v2.2.2 (*) +│ ├── wasm-bindgen v0.2.78 (*) +│ ├── wasm-bindgen-futures v0.4.28 +│ │ ├── cfg-if v1.0.0 +│ │ ├── js-sys v0.3.55 (*) +│ │ └── wasm-bindgen v0.2.78 (*) +│ ├── worker-kv v0.5.1 +│ │ ├── js-sys v0.3.55 (*) +│ │ ├── serde v1.0.136 (*) +│ │ ├── serde_json v1.0.79 (*) +│ │ ├── thiserror v1.0.30 (*) +│ │ ├── wasm-bindgen v0.2.78 (*) +│ │ └── wasm-bindgen-futures v0.4.28 (*) +│ ├── worker-macros v0.0.4 (proc-macro) +│ │ ├── async-trait v0.1.52 (proc-macro) (*) +│ │ ├── proc-macro2 v1.0.36 (*) +│ │ ├── quote v1.0.15 (*) +│ │ ├── syn v1.0.86 (*) +│ │ ├── wasm-bindgen v0.2.78 (*) +│ │ ├── wasm-bindgen-futures v0.4.28 (*) +│ │ ├── wasm-bindgen-macro-support v0.2.78 (*) +│ │ └── worker-sys v0.0.4 +│ │ ├── cfg-if v0.1.10 +│ │ ├── js-sys v0.3.55 (*) +│ │ ├── wasm-bindgen v0.2.78 (*) +│ │ └── web-sys v0.3.55 +│ │ ├── js-sys v0.3.55 (*) +│ │ └── wasm-bindgen v0.2.78 (*) +│ └── worker-sys v0.0.4 (*) +├── serde_json v1.0.79 (*) +└── worker v0.0.9 (*) diff --git a/examples/cloudflare/src/lib.rs b/examples/cloudflare/src/lib.rs index 477e20ae..5638c502 100644 --- a/examples/cloudflare/src/lib.rs +++ b/examples/cloudflare/src/lib.rs @@ -1,7 +1,25 @@ -use octocat_rs::worker::{self::*, worker_sys::ResponseInit}; -use serde_json::json; -mod utils; +use std::sync::Arc; + use async_trait::async_trait; +use worker::{console_log, event, Date, Env, Request, Response}; + +use octocat_rs::{handler::EventHandler, rest::model::repositories::events::PushEvent, Client, ClientBuilder, Command}; + +mod utils; + +#[event(fetch)] +pub async fn main(req: Request, _env: Env, _ctx: worker::Context) -> anyhow::Result { + log_request(&req); + + ClientBuilder::new() + .event_handler(Handler {}) + .build()? + .handle(req) + .await; + + // This can't fail, so using anyhow::Result is preferred over worker::Result + Ok(Response::empty().unwrap()) +} fn log_request(req: &Request) { console_log!( @@ -9,51 +27,40 @@ fn log_request(req: &Request) { Date::now().to_string(), req.path(), req.cf().coordinates().unwrap_or_default(), - req.cf().region().unwrap_or("unknown region".into()) + req.cf().region().unwrap_or_else(|| "unknown region".into()) ); } -#[event(fetch)] -pub async fn main(req: Request, env: Env, _ctx: worker::Context) -> Result { - log_request(&req); +#[derive(Debug)] +struct Handler {} - #[derive(Debug)] - struct Handler {} +#[derive(Debug)] +enum Message { + Stuff(&'static str), +} - #[derive(Debug)] - enum Message { - Stuff(&'static str), - } - #[async_trait::async_trait] - impl EventHandler for Handler { - type Message = Message; - type GitHubClient = Client; +#[async_trait] +impl EventHandler for Handler { + type Message = Message; + type GitHubClient = Client; - fn listener_port(&self) -> u16 { - 2022 - } - async fn message(&self, message: Self::Message) { - match message { - Message::Stuff(s) => { - println!("==> Message received: {s}"); - } + fn listener_port(&self) -> u16 { + 2022 + } + async fn message(&self, message: Self::Message) { + match message { + Message::Stuff(s) => { + println!("==> Message received: {s}"); } } - async fn commit_event( - &self, - _github_client: Arc, - _commit: PushEvent, - ) -> Command { - println!("Commit pushed!"); - - Command::perform(async { "Computation finished" }, Message::Stuff) - } } + async fn commit_event( + &self, + _github_client: Arc, + _commit: PushEvent, + ) -> Command { + println!("Commit pushed!"); - ClientBuilder::new() - .event_handler(Handler {}) - .build()? - .handle(req) - .await; - Response::empty() + Command::perform(async { "Computation finished" }, Message::Stuff) + } } diff --git a/github-rest/Cargo.toml b/github-rest/Cargo.toml index a8f67b32..ced422e8 100644 --- a/github-rest/Cargo.toml +++ b/github-rest/Cargo.toml @@ -26,4 +26,4 @@ client = [] [dev-dependencies] -tokio = { version = "1.15.0", features = ["macros", "rt-multi-thread"] } +#tokio = { version = "1.15.0", features = ["macros", "rt-multi-thread"] } diff --git a/github-rest/src/methods/misc.rs b/github-rest/src/methods/misc.rs index 00208364..3591f7e6 100644 --- a/github-rest/src/methods/misc.rs +++ b/github-rest/src/methods/misc.rs @@ -3,6 +3,7 @@ use crate::model::organizations::AddToOrgResponse; use super::prelude::*; use serde::{Deserialize, Serialize}; +use serde_json::Value; use strum::{EnumString, EnumVariantNames}; pub async fn zen(client: &T) -> Result @@ -12,14 +13,12 @@ where client.raw_req::(EndPoints::GetZen(), None, None).await } -//pub async fn api_info(client: &T) -> Result -//where -// T: Requester, -//{ -// client -// .req::(EndPoints::Get(), None, None) -// .await -//} +pub async fn api_info(client: &T) -> Result +where + T: Requester, +{ + client.req::(EndPoints::Get(), None, None).await +} //Role enum used for add to org function determines the function a user has // within a organization diff --git a/octocat-rs/Cargo.toml b/octocat-rs/Cargo.toml index 35d1a070..4684f6b1 100644 --- a/octocat-rs/Cargo.toml +++ b/octocat-rs/Cargo.toml @@ -24,7 +24,7 @@ async-trait = "0.1.52" futures = "0.3" ## Webserver -warp = "0.3" +warp = { version = "0.3", optional = true} ## Serialization/Deserialization serde = { version = "^1", features = ["derive"] } @@ -35,16 +35,11 @@ toml = "0.5.8" thiserror = "1.0.30" anyhow = "1.0.51" -## Logging -pretty_env_logger = "0.4" -log = "0.4" - -## Util -lazy_static = "1.4.0" strum_macros = "0.23" reqwest = "^0.11.8" strum = "0.23.0" worker = { version = "0.0.9", optional = true } [features] +default = ["warp"] workers = ["worker"] diff --git a/octocat-rs/src/github/client.rs b/octocat-rs/src/github/client.rs index 4bd8abb7..103af515 100644 --- a/octocat-rs/src/github/client.rs +++ b/octocat-rs/src/github/client.rs @@ -5,7 +5,10 @@ use async_trait::async_trait; use github_api::end_points::EndPoints; use reqwest::Body; use serde::{de::DeserializeOwned, Serialize}; + +#[cfg(feature = "warp")] use tokio::sync::mpsc; +#[cfg(feature = "warp")] use warp::Filter; use github_rest::{ @@ -128,7 +131,7 @@ where T: Debug + EventHandler> + Send + Sync + 'static, { #[cfg(feature = "workers")] - pub async fn handle(self,mut req: worker::Request) { + pub async fn handle(self, mut req: worker::Request) { let _ = self.run().await.expect("Starting application: User-defined code"); let self_arc = Arc::new(self); @@ -141,7 +144,7 @@ where .event_handler() .$f( thread_self.clone(), - (req).json::<$t>().await.expect("Failed to parse json") + (req).json::<$t>().await.expect("Failed to parse json"), ) .await }; @@ -306,7 +309,7 @@ where } } - #[cfg(not(feature = "workers"))] + #[cfg(feature = "warp")] pub async fn start(self) { let _ = self.run().await.expect("Starting application: User-defined code"); diff --git a/octocat-rs/src/lib.rs b/octocat-rs/src/lib.rs index 505c8651..fe4b9fa3 100644 --- a/octocat-rs/src/lib.rs +++ b/octocat-rs/src/lib.rs @@ -13,8 +13,8 @@ pub mod github; pub use github_api as api; pub use github_rest as rest; -#[cfg(feature="workers")] -pub use worker; +#[cfg(all(feature = "warp", feature = "worker"))] +compile_error!("feature \"worker\" and feature \"warp\" cannot be enabled at the same time"); #[cfg(test)] mod tests { From f563df82c781721ef9d707e9917df21b290c36e2 Mon Sep 17 00:00:00 2001 From: Proudmuslim Date: Sun, 20 Feb 2022 16:05:48 -0800 Subject: [PATCH 03/11] wip(http client): Begin `Requester` implementation for `HttpClient` --- Cargo.lock | 2 ++ examples/cloudflare/src/lib.rs | 1 + github-rest/Cargo.toml | 2 +- octocat-rs/Cargo.toml | 4 ++- octocat-rs/src/github/http.rs | 53 ++++++++++++++++++++++++++++++++++ 5 files changed, 60 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2340da00..630fc671 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -416,6 +416,7 @@ dependencies = [ "serde", "serde_json", "strum", + "tokio", ] [[package]] @@ -780,6 +781,7 @@ dependencies = [ "reqwest", "serde", "serde_json", + "serde_urlencoded", "strum", "strum_macros", "thiserror", diff --git a/examples/cloudflare/src/lib.rs b/examples/cloudflare/src/lib.rs index 5638c502..3ed7c5aa 100644 --- a/examples/cloudflare/src/lib.rs +++ b/examples/cloudflare/src/lib.rs @@ -47,6 +47,7 @@ impl EventHandler for Handler { fn listener_port(&self) -> u16 { 2022 } + async fn message(&self, message: Self::Message) { match message { Message::Stuff(s) => { diff --git a/github-rest/Cargo.toml b/github-rest/Cargo.toml index ced422e8..a8f67b32 100644 --- a/github-rest/Cargo.toml +++ b/github-rest/Cargo.toml @@ -26,4 +26,4 @@ client = [] [dev-dependencies] -#tokio = { version = "1.15.0", features = ["macros", "rt-multi-thread"] } +tokio = { version = "1.15.0", features = ["macros", "rt-multi-thread"] } diff --git a/octocat-rs/Cargo.toml b/octocat-rs/Cargo.toml index 4684f6b1..52a03fbc 100644 --- a/octocat-rs/Cargo.toml +++ b/octocat-rs/Cargo.toml @@ -35,11 +35,13 @@ toml = "0.5.8" thiserror = "1.0.30" anyhow = "1.0.51" +## Util strum_macros = "0.23" reqwest = "^0.11.8" strum = "0.23.0" worker = { version = "0.0.9", optional = true } +serde_urlencoded = { version = "0.7.1", optional = true } [features] default = ["warp"] -workers = ["worker"] +workers = ["worker", "serde_urlencoded"] diff --git a/octocat-rs/src/github/http.rs b/octocat-rs/src/github/http.rs index 3282833d..2a2a1219 100644 --- a/octocat-rs/src/github/http.rs +++ b/octocat-rs/src/github/http.rs @@ -1,4 +1,5 @@ use async_trait::async_trait; +#[cfg(not(feature = "workers"))] use reqwest::{ header, header::{HeaderMap, HeaderValue}, @@ -7,6 +8,11 @@ use reqwest::{ use serde::{de::DeserializeOwned, Serialize}; use tokio::time::Duration; +#[cfg(feature = "workers")] +use worker::{Fetch, Request, Method}; +use worker::RequestInit; +use worker::ResponseBody::Body; + use github_rest::{ methods::prelude::{EndPoints, Methods}, GithubRestError, @@ -78,6 +84,7 @@ impl HttpClient { .unwrap() } + #[cfg(not(feature = "workers"))] fn http_auth(&self, req: RequestBuilder) -> RequestBuilder { if let Some(auth) = &self.auth { match auth { @@ -87,10 +94,16 @@ impl HttpClient { req } } + + #[cfg(feature = "workers")] + fn http_auth(&self, req: RequestBuilder) -> RequestBuilder { + todo!() + } } #[async_trait] impl github_rest::Requester for HttpClient { + #[cfg(not(feature = "workers"))] /// Returns the API response as a [`String`]. async fn raw_req(&self, url: EndPoints, query: Option<&T>, body: Option) -> Result where @@ -128,6 +141,46 @@ impl github_rest::Requester for HttpClient { Ok(txt) } + #[cfg(feature = "workers")] + /// Returns the API response as a [`String`]. + async fn raw_req(&self, url: EndPoints, query: Option<&T>, body: Option) -> Result + where + T: Serialize + ?Sized + Send + Sync, + V: Into + Send, + { + let path = format!("https://api.github.com{}", url.path()); + + let mut req: Request = match url.method() { + Methods::Get => Request::new(path.as_str(), Method::Get).unwrap(), + Methods::Post => Request::new(path.as_str(), Method::Post).unwrap(), + Methods::Patch => Request::new(path.as_str(), Method::Patch).unwrap(), + Methods::Delete => Request::new(path.as_str(), Method::Delete).unwrap(), + Methods::Put => Request::new(path.as_str(), Method::Put).unwrap(), + }; + + let _init = RequestInit::new(); + + if let Some(query) = query { + // TODO: Query + } + + if let Some(body) = body { + // TODO: Body + } + + let mut res = Fetch::Request(req).send().await?; + + match res.status_code() { + 200..=299 => {} + _ => { + return Err(GithubRestError::ResponseError(res.status(), res.text().await?)); + } + } + let txt = res.text().await?; + + Ok(txt) + } + async fn req( &self, url: EndPoints, From f6a7b4c00eb4c0cf13142308109350e1967e26fd Mon Sep 17 00:00:00 2001 From: Proudmuslim Date: Sun, 20 Feb 2022 19:10:27 -0800 Subject: [PATCH 04/11] [skip ci] fmt --- octocat-rs/src/github/http.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/octocat-rs/src/github/http.rs b/octocat-rs/src/github/http.rs index 2a2a1219..f6a6cd63 100644 --- a/octocat-rs/src/github/http.rs +++ b/octocat-rs/src/github/http.rs @@ -9,9 +9,7 @@ use serde::{de::DeserializeOwned, Serialize}; use tokio::time::Duration; #[cfg(feature = "workers")] -use worker::{Fetch, Request, Method}; -use worker::RequestInit; -use worker::ResponseBody::Body; +use worker::{Fetch, Method, Request, RequestInit, ResponseBody::Body}; use github_rest::{ methods::prelude::{EndPoints, Methods}, @@ -144,9 +142,9 @@ impl github_rest::Requester for HttpClient { #[cfg(feature = "workers")] /// Returns the API response as a [`String`]. async fn raw_req(&self, url: EndPoints, query: Option<&T>, body: Option) -> Result - where - T: Serialize + ?Sized + Send + Sync, - V: Into + Send, + where + T: Serialize + ?Sized + Send + Sync, + V: Into + Send, { let path = format!("https://api.github.com{}", url.path()); From bc5bd85d78ee80ee1700b5c38934c76853e9f70a Mon Sep 17 00:00:00 2001 From: Proudmuslim Date: Mon, 28 Feb 2022 17:06:30 -0800 Subject: [PATCH 05/11] [skip ci] wip: Continue work on wasm port There's still a lot of work to be done, I plan on clearing out most of the errors tomorrow --- Cargo.lock | 1 + github-rest/Cargo.toml | 10 +- github-rest/src/client.rs | 4 +- github-rest/src/lib.rs | 25 ++- github-rest/src/methods/mod.rs | 2 +- octocat-rs/Cargo.toml | 9 +- octocat-rs/deps | 224 ++++++++++++++++++++ octocat-rs/src/github/client.rs | 360 ++++++++++---------------------- octocat-rs/src/github/http.rs | 38 ++-- octocat-rs/src/github/mod.rs | 1 + octocat-rs/src/lib.rs | 4 +- 11 files changed, 401 insertions(+), 277 deletions(-) create mode 100644 octocat-rs/deps diff --git a/Cargo.lock b/Cargo.lock index 52c3ff78..74af7361 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -418,6 +418,7 @@ dependencies = [ "serde_json", "strum", "tokio", + "worker", ] [[package]] diff --git a/github-rest/Cargo.toml b/github-rest/Cargo.toml index 1ecc77fc..332e7adf 100644 --- a/github-rest/Cargo.toml +++ b/github-rest/Cargo.toml @@ -8,7 +8,6 @@ edition = "2021" [dependencies] ## HTTP github-api = { git = "https://github.com/octocat-rs/github-api" } -reqwest = { version = "0.11.8" } ## Serialization/Deserialization strum = { version = "0.23", features = ["derive"] } @@ -19,6 +18,13 @@ serde_json = "^1" async-trait = "0.1.52" paste = "1" +[target.'cfg(not(target_family = "wasm"))'.dependencies] +reqwest = { version = "0.11.8" } + +[target.'cfg(target_family = "wasm")'.dependencies] +worker = "0.0.9" + + [features] default = ["builders"] full = ["builders", "client"] @@ -26,5 +32,5 @@ builders = [] client = [] -[dev-dependencies] +[target.'cfg(not(target_family = "wasm"))'.dev-dependencies] tokio = { version = "1.15.0", features = ["macros", "rt-multi-thread"] } diff --git a/github-rest/src/client.rs b/github-rest/src/client.rs index 06411625..65281a43 100644 --- a/github-rest/src/client.rs +++ b/github-rest/src/client.rs @@ -59,7 +59,7 @@ impl Requester for DefaultRequest { async fn raw_req(&self, url: EndPoints, query: Option<&T>, body: Option) -> Result where T: Serialize + ?Sized + std::marker::Send + std::marker::Sync, - V: Into + std::marker::Send, + V: Into + std::marker::Send, { let path = format!("https://api.github.com{}", url.path()); @@ -100,7 +100,7 @@ impl Requester for DefaultRequest { ) -> Result where T: Serialize + ?Sized + std::marker::Send + std::marker::Sync, - V: Into + std::marker::Send, + V: Into + std::marker::Send, { let r = self.raw_req(url, query, body).await?; Ok(serde_json::from_str(&r)?) diff --git a/github-rest/src/lib.rs b/github-rest/src/lib.rs index 258ff0f7..a8b1f556 100644 --- a/github-rest/src/lib.rs +++ b/github-rest/src/lib.rs @@ -1,3 +1,4 @@ +#![feature(associated_type_defaults)] #![deny(rust_2018_idioms)] use core::fmt; @@ -6,8 +7,11 @@ use std::error::Error; use async_trait::async_trait; pub use github_api::end_points; use github_api::end_points::EndPoints; +#[cfg(not(target_family = "wasm"))] use reqwest::{Body, StatusCode}; use serde::{de::DeserializeOwned, Serialize}; +#[cfg(target_family = "wasm")] +use worker::wasm_bindgen::JsValue; #[cfg(feature = "builders")] pub mod builders; @@ -18,7 +22,10 @@ pub mod model; #[derive(Debug)] pub enum GithubRestError { + #[cfg(not(target_family = "wasm"))] ReqwestError(reqwest::Error), + #[cfg(target_family = "wasm")] + WorkerError(worker::Error), JsonError(serde_json::Error), ResponseError(StatusCode, String), AnyError(), @@ -32,12 +39,20 @@ impl fmt::Display for GithubRestError { impl Error for GithubRestError {} +#[cfg(not(target_family = "wasm"))] impl From for GithubRestError { fn from(e: reqwest::Error) -> Self { GithubRestError::ReqwestError(e) } } +#[cfg(target_family = "wasm")] +impl From for GithubRestError { + fn from(e: worker::Error) -> Self { + GithubRestError::WorkerError(e) + } +} + impl From for GithubRestError { fn from(e: serde_json::Error) -> Self { GithubRestError::JsonError(e) @@ -46,6 +61,12 @@ impl From for GithubRestError { #[async_trait] pub trait Requester: Send + Sync { + #[cfg(not(target_family = "wasm"))] + type Body: From = Body; + + #[cfg(target_family = "wasm")] + type Body: From = JsValue; + async fn raw_req( &self, url: EndPoints, @@ -54,7 +75,7 @@ pub trait Requester: Send + Sync { ) -> Result where T: Serialize + ?Sized + std::marker::Send + std::marker::Sync, - V: Into + std::marker::Send; + V: Into + std::marker::Send; async fn req( &self, @@ -64,5 +85,5 @@ pub trait Requester: Send + Sync { ) -> Result where T: Serialize + ?Sized + std::marker::Send + std::marker::Sync, - V: Into + std::marker::Send; + V: Into + std::marker::Send; } diff --git a/github-rest/src/methods/mod.rs b/github-rest/src/methods/mod.rs index 0f67aa08..00a39226 100644 --- a/github-rest/src/methods/mod.rs +++ b/github-rest/src/methods/mod.rs @@ -11,7 +11,7 @@ mod misc; mod users; pub(crate) mod util; -///Prelude mod used for methods +/// Prelude mod used for methods pub mod prelude { pub use github_api::end_points::*; pub use reqwest::Body; diff --git a/octocat-rs/Cargo.toml b/octocat-rs/Cargo.toml index 52a03fbc..7ba0f717 100644 --- a/octocat-rs/Cargo.toml +++ b/octocat-rs/Cargo.toml @@ -19,12 +19,12 @@ github-rest = { path = "../github-rest" } github-api = { git = "https://github.com/octocat-rs/github-api" } ## Async -tokio = { version = "1", features = ["full"] } +tokio = { version = "1", features = ["full"], optional = true } async-trait = "0.1.52" futures = "0.3" ## Webserver -warp = { version = "0.3", optional = true} +warp = { version = "0.3", optional = true } ## Serialization/Deserialization serde = { version = "^1", features = ["derive"] } @@ -37,11 +37,12 @@ anyhow = "1.0.51" ## Util strum_macros = "0.23" -reqwest = "^0.11.8" +reqwest = { version = "^0.11.8", optional = true } strum = "0.23.0" worker = { version = "0.0.9", optional = true } serde_urlencoded = { version = "0.7.1", optional = true } [features] -default = ["warp"] +default = [ "native" ] +native = ["warp", "tokio", "reqwest"] workers = ["worker", "serde_urlencoded"] diff --git a/octocat-rs/deps b/octocat-rs/deps new file mode 100644 index 00000000..d31e4d1b --- /dev/null +++ b/octocat-rs/deps @@ -0,0 +1,224 @@ +octocat-rs v0.0.0 (/home/twilight/CLionProjects/octocat-rs/octocat-rs) +├── anyhow v1.0.54 +├── async-trait v0.1.52 (proc-macro) +│ ├── proc-macro2 v1.0.36 +│ │ └── unicode-xid v0.2.2 +│ ├── quote v1.0.15 +│ │ └── proc-macro2 v1.0.36 (*) +│ └── syn v1.0.86 +│ ├── proc-macro2 v1.0.36 (*) +│ ├── quote v1.0.15 (*) +│ └── unicode-xid v0.2.2 +├── futures v0.3.21 +│ ├── futures-channel v0.3.21 +│ │ ├── futures-core v0.3.21 +│ │ └── futures-sink v0.3.21 +│ ├── futures-core v0.3.21 +│ ├── futures-executor v0.3.21 +│ │ ├── futures-core v0.3.21 +│ │ ├── futures-task v0.3.21 +│ │ └── futures-util v0.3.21 +│ │ ├── futures-channel v0.3.21 (*) +│ │ ├── futures-core v0.3.21 +│ │ ├── futures-io v0.3.21 +│ │ ├── futures-macro v0.3.21 (proc-macro) +│ │ │ ├── proc-macro2 v1.0.36 (*) +│ │ │ ├── quote v1.0.15 (*) +│ │ │ └── syn v1.0.86 (*) +│ │ ├── futures-sink v0.3.21 +│ │ ├── futures-task v0.3.21 +│ │ ├── memchr v2.4.1 +│ │ ├── pin-project-lite v0.2.8 +│ │ ├── pin-utils v0.1.0 +│ │ └── slab v0.4.5 +│ ├── futures-io v0.3.21 +│ ├── futures-sink v0.3.21 +│ ├── futures-task v0.3.21 +│ └── futures-util v0.3.21 (*) +├── github-api v0.1.0 (https://github.com/octocat-rs/github-api#638ff4e6) +│ ├── serde v1.0.136 +│ │ └── serde_derive v1.0.136 (proc-macro) +│ │ ├── proc-macro2 v1.0.36 (*) +│ │ ├── quote v1.0.15 (*) +│ │ └── syn v1.0.86 (*) +│ └── serde_json v1.0.79 +│ ├── itoa v1.0.1 +│ ├── ryu v1.0.9 +│ └── serde v1.0.136 (*) +├── github-rest v0.1.0 (/home/twilight/CLionProjects/octocat-rs/github-rest) +│ ├── async-trait v0.1.52 (proc-macro) (*) +│ ├── github-api v0.1.0 (https://github.com/octocat-rs/github-api#638ff4e6) (*) +│ ├── paste v1.0.6 (proc-macro) +│ ├── reqwest v0.11.9 +│ │ ├── bytes v1.1.0 +│ │ ├── http v0.2.6 +│ │ │ ├── bytes v1.1.0 +│ │ │ ├── fnv v1.0.7 +│ │ │ └── itoa v1.0.1 +│ │ ├── js-sys v0.3.55 +│ │ │ └── wasm-bindgen v0.2.78 +│ │ │ ├── cfg-if v1.0.0 +│ │ │ ├── serde v1.0.136 (*) +│ │ │ ├── serde_json v1.0.79 (*) +│ │ │ └── wasm-bindgen-macro v0.2.78 (proc-macro) +│ │ │ ├── quote v1.0.15 (*) +│ │ │ └── wasm-bindgen-macro-support v0.2.78 +│ │ │ ├── proc-macro2 v1.0.36 (*) +│ │ │ ├── quote v1.0.15 (*) +│ │ │ ├── syn v1.0.86 (*) +│ │ │ ├── wasm-bindgen-backend v0.2.78 +│ │ │ │ ├── bumpalo v3.9.1 +│ │ │ │ ├── lazy_static v1.4.0 +│ │ │ │ ├── log v0.4.14 +│ │ │ │ │ └── cfg-if v1.0.0 +│ │ │ │ ├── proc-macro2 v1.0.36 (*) +│ │ │ │ ├── quote v1.0.15 (*) +│ │ │ │ ├── syn v1.0.86 (*) +│ │ │ │ └── wasm-bindgen-shared v0.2.78 +│ │ │ └── wasm-bindgen-shared v0.2.78 +│ │ ├── serde v1.0.136 (*) +│ │ ├── serde_json v1.0.79 (*) +│ │ ├── serde_urlencoded v0.7.1 +│ │ │ ├── form_urlencoded v1.0.1 +│ │ │ │ ├── matches v0.1.9 +│ │ │ │ └── percent-encoding v2.1.0 +│ │ │ ├── itoa v1.0.1 +│ │ │ ├── ryu v1.0.9 +│ │ │ └── serde v1.0.136 (*) +│ │ ├── url v2.2.2 +│ │ │ ├── form_urlencoded v1.0.1 (*) +│ │ │ ├── idna v0.2.3 +│ │ │ │ ├── matches v0.1.9 +│ │ │ │ ├── unicode-bidi v0.3.7 +│ │ │ │ └── unicode-normalization v0.1.19 +│ │ │ │ └── tinyvec v1.5.1 +│ │ │ │ └── tinyvec_macros v0.1.0 +│ │ │ ├── matches v0.1.9 +│ │ │ └── percent-encoding v2.1.0 +│ │ ├── wasm-bindgen v0.2.78 (*) +│ │ ├── wasm-bindgen-futures v0.4.28 +│ │ │ ├── cfg-if v1.0.0 +│ │ │ ├── js-sys v0.3.55 (*) +│ │ │ └── wasm-bindgen v0.2.78 (*) +│ │ └── web-sys v0.3.55 +│ │ ├── js-sys v0.3.55 (*) +│ │ └── wasm-bindgen v0.2.78 (*) +│ ├── serde v1.0.136 (*) +│ ├── serde_json v1.0.79 (*) +│ └── strum v0.23.0 +│ └── strum_macros v0.23.1 (proc-macro) +│ ├── heck v0.3.3 +│ │ └── unicode-segmentation v1.9.0 +│ ├── proc-macro2 v1.0.36 (*) +│ ├── quote v1.0.15 (*) +│ ├── rustversion v1.0.6 (proc-macro) +│ └── syn v1.0.86 (*) +├── serde v1.0.136 (*) +├── serde_json v1.0.79 (*) +├── serde_urlencoded v0.7.1 (*) +├── strum v0.23.0 (*) +├── strum_macros v0.23.1 (proc-macro) (*) +├── thiserror v1.0.30 +│ └── thiserror-impl v1.0.30 (proc-macro) +│ ├── proc-macro2 v1.0.36 (*) +│ ├── quote v1.0.15 (*) +│ └── syn v1.0.86 (*) +├── toml v0.5.8 +│ └── serde v1.0.136 (*) +└── worker v0.0.9 + ├── async-trait v0.1.52 (proc-macro) (*) + ├── chrono v0.4.19 + │ ├── js-sys v0.3.55 (*) + │ ├── num-integer v0.1.44 + │ │ └── num-traits v0.2.14 + │ │ [build-dependencies] + │ │ └── autocfg v1.1.0 + │ │ [build-dependencies] + │ │ └── autocfg v1.1.0 + │ ├── num-traits v0.2.14 (*) + │ └── wasm-bindgen v0.2.78 (*) + ├── chrono-tz v0.6.1 + │ ├── chrono v0.4.19 (*) + │ └── phf v0.10.1 + │ └── phf_shared v0.10.0 + │ ├── siphasher v0.3.9 + │ └── uncased v0.9.6 + │ [build-dependencies] + │ └── version_check v0.9.4 + │ [build-dependencies] + │ └── chrono-tz-build v0.0.2 + │ ├── parse-zoneinfo v0.3.0 + │ │ └── regex v1.5.4 + │ │ └── regex-syntax v0.6.25 + │ ├── phf v0.10.1 + │ │ └── phf_shared v0.10.0 + │ │ ├── siphasher v0.3.9 + │ │ └── uncased v0.9.6 + │ │ [build-dependencies] + │ │ └── version_check v0.9.4 + │ └── phf_codegen v0.10.0 + │ ├── phf_generator v0.10.0 + │ │ ├── phf_shared v0.10.0 (*) + │ │ └── rand v0.8.5 + │ │ ├── libc v0.2.118 + │ │ ├── rand_chacha v0.3.1 + │ │ │ ├── ppv-lite86 v0.2.16 + │ │ │ └── rand_core v0.6.3 + │ │ │ └── getrandom v0.2.4 + │ │ │ ├── cfg-if v1.0.0 + │ │ │ └── libc v0.2.118 + │ │ └── rand_core v0.6.3 (*) + │ └── phf_shared v0.10.0 (*) + ├── futures v0.3.21 (*) + ├── http v0.2.6 (*) + ├── js-sys v0.3.55 (*) + ├── matchit v0.4.6 + ├── pin-project v1.0.10 + │ └── pin-project-internal v1.0.10 (proc-macro) + │ ├── proc-macro2 v1.0.36 (*) + │ ├── quote v1.0.15 (*) + │ └── syn v1.0.86 (*) + ├── serde v1.0.136 (*) + ├── serde_json v1.0.79 (*) + ├── url v2.2.2 (*) + ├── wasm-bindgen v0.2.78 (*) + ├── wasm-bindgen-futures v0.4.28 (*) + ├── worker-kv v0.5.1 + │ ├── js-sys v0.3.55 (*) + │ ├── serde v1.0.136 (*) + │ ├── serde_json v1.0.79 (*) + │ ├── thiserror v1.0.30 (*) + │ ├── wasm-bindgen v0.2.78 (*) + │ └── wasm-bindgen-futures v0.4.28 (*) + ├── worker-macros v0.0.4 (proc-macro) + │ ├── async-trait v0.1.52 (proc-macro) (*) + │ ├── proc-macro2 v1.0.36 (*) + │ ├── quote v1.0.15 (*) + │ ├── syn v1.0.86 (*) + │ ├── wasm-bindgen v0.2.78 + │ │ ├── cfg-if v1.0.0 + │ │ ├── serde v1.0.136 + │ │ │ └── serde_derive v1.0.136 (proc-macro) (*) + │ │ ├── serde_json v1.0.79 + │ │ │ ├── itoa v1.0.1 + │ │ │ ├── ryu v1.0.9 + │ │ │ └── serde v1.0.136 (*) + │ │ └── wasm-bindgen-macro v0.2.78 (proc-macro) (*) + │ ├── wasm-bindgen-futures v0.4.28 + │ │ ├── cfg-if v1.0.0 + │ │ ├── js-sys v0.3.55 + │ │ │ └── wasm-bindgen v0.2.78 (*) + │ │ └── wasm-bindgen v0.2.78 (*) + │ ├── wasm-bindgen-macro-support v0.2.78 (*) + │ └── worker-sys v0.0.4 + │ ├── cfg-if v0.1.10 + │ ├── js-sys v0.3.55 (*) + │ ├── wasm-bindgen v0.2.78 (*) + │ └── web-sys v0.3.55 + │ ├── js-sys v0.3.55 (*) + │ └── wasm-bindgen v0.2.78 (*) + └── worker-sys v0.0.4 + ├── cfg-if v0.1.10 + ├── js-sys v0.3.55 (*) + ├── wasm-bindgen v0.2.78 (*) + └── web-sys v0.3.55 (*) diff --git a/octocat-rs/src/github/client.rs b/octocat-rs/src/github/client.rs index 1d45da30..2670d953 100644 --- a/octocat-rs/src/github/client.rs +++ b/octocat-rs/src/github/client.rs @@ -6,12 +6,11 @@ use std::{fmt::Debug, sync::Arc}; use anyhow::Result; use async_trait::async_trait; use github_api::end_points::EndPoints; -use reqwest::Body; use serde::{de::DeserializeOwned, Serialize}; -#[cfg(feature = "warp")] +#[cfg(feature = "native")] use tokio::sync::mpsc; -#[cfg(feature = "warp")] +#[cfg(feature = "native")] use warp::Filter; use github_rest::{ @@ -109,7 +108,7 @@ where ) -> std::result::Result where T: Serialize + ?Sized + Send + Sync, - V: Into + Send, + V: Into + Send, { self.http_client.raw_req(url, query, body).await } @@ -122,187 +121,209 @@ where ) -> std::result::Result where T: Serialize + ?Sized + Send + Sync, - V: Into + Send, + V: Into + Send, { self.http_client.req(url, query, body).await } } -impl Client -where - T: Debug + EventHandler> + Send + Sync + 'static, -{ - #[cfg(feature = "workers")] - pub async fn handle(self, mut req: worker::Request) { - let _ = self.run().await.expect("Starting application: User-defined code"); - - let self_arc = Arc::new(self); - let thread_self = self_arc.clone(); - let thread_self_2 = self_arc.clone(); - let mut user_cmd = Command::none(); - macro_rules! event_push { - ($f:ident, $t:ty) => { - user_cmd = thread_self - .event_handler() - .$f( - thread_self.clone(), - (req).json::<$t>().await.expect("Failed to parse json"), - ) - .await - }; - } - let ev = serde_json::from_str(&req.headers().get("x-github-event").unwrap().unwrap()) - .expect("Failed to parse headers"); - match ev { +macro_rules! event_handle { + ($ev:ident) => { + match $ev { EventTypes::Push => { - event_push!(commit_event, PushEvent); + event_push!(commit_event, PushEvent) } EventTypes::GithubAppAuthorization => { - event_push!(app_authorization_event, AppAuthorizationEvent); + event_push!(app_authorization_event, AppAuthorizationEvent) } EventTypes::Installation => { - event_push!(installation_event, InstallationEvent); + event_push!(installation_event, InstallationEvent) } EventTypes::InstallationRepositories => { - event_push!(installation_repositories_event, InstallationRepositoriesEvent); + event_push!(installation_repositories_event, InstallationRepositoriesEvent) } EventTypes::DeployKey => { - event_push!(deploy_key_event, DeployKeyEvent); + event_push!(deploy_key_event, DeployKeyEvent) } EventTypes::Gollum => { - event_push!(gollum_event, GollumEvent); + event_push!(gollum_event, GollumEvent) } EventTypes::Member => { - event_push!(member_event, MemberEvent); + event_push!(member_event, MemberEvent) } EventTypes::Milestone => { - event_push!(milestone_event, MilestoneEvent); + event_push!(milestone_event, MilestoneEvent) } EventTypes::Public => { - event_push!(public_event, PublicEvent); + event_push!(public_event, PublicEvent) } EventTypes::Release => { - event_push!(release_event, ReleaseEvent); + event_push!(release_event, ReleaseEvent) } EventTypes::Repository => { - event_push!(repository_event, RepositoryEvent); + event_push!(repository_event, RepositoryEvent) } EventTypes::RepositoryDispatch => { - event_push!(repository_dispatch_event, RepositoryDispatchEvent); + event_push!(repository_dispatch_event, RepositoryDispatchEvent) } EventTypes::RepositoryImport => { - event_push!(repository_import_event, RepositoryImportEvent); + event_push!(repository_import_event, RepositoryImportEvent) } EventTypes::RepositoryVulnerabilityAlert => { - event_push!(repository_vulnerability_alert, RepositoryVulnerabilityAlertEvent); + event_push!(repository_vulnerability_alert, RepositoryVulnerabilityAlertEvent) } EventTypes::SecretScanningAlert => { - event_push!(secret_scanning_alert, SecretScanningAlertEvent); + event_push!(secret_scanning_alert, SecretScanningAlertEvent) } EventTypes::SecurityAdvisory => { - event_push!(security_advisory, SecurityAdvisoryEvent); + event_push!(security_advisory, SecurityAdvisoryEvent) } EventTypes::Star => { - event_push!(star_event, StarEvent); + event_push!(star_event, StarEvent) } EventTypes::Watch => { - event_push!(watch_event, WatchEvent); + event_push!(watch_event, WatchEvent) } EventTypes::PullRequest => { - event_push!(pull_request_event, PullRequestEvent); + event_push!(pull_request_event, PullRequestEvent) } EventTypes::PullRequestReview => { - event_push!(pull_request_review_event, PullRequestReviewEvent); + event_push!(pull_request_review_event, PullRequestReviewEvent) } EventTypes::PullRequestReviewComment => { - event_push!(pull_request_review_comment_event, PullRequestReviewCommentEvent); + event_push!(pull_request_review_comment_event, PullRequestReviewCommentEvent) } EventTypes::CommitComment => { - event_push!(commit_comment_event, CommitCommentEvent); + event_push!(commit_comment_event, CommitCommentEvent) } EventTypes::Status => { - event_push!(status_event, StatusEvent); + event_push!(status_event, StatusEvent) } EventTypes::IssueComment => { - event_push!(issue_comment_event, IssueCommentEvent); + event_push!(issue_comment_event, IssueCommentEvent) } EventTypes::Issues => { - event_push!(issue_event, IssueEvent); + event_push!(issue_event, IssueEvent) } EventTypes::Label => { - event_push!(label_event, LabelEvent); + event_push!(label_event, LabelEvent) } EventTypes::Discussion => { - event_push!(discussion_event, DiscussionEvent); + event_push!(discussion_event, DiscussionEvent) } EventTypes::DiscussionComment => { - event_push!(discussion_comment_event, DiscussionCommentEvent); + event_push!(discussion_comment_event, DiscussionCommentEvent) } EventTypes::BranchProtectionRule => { - event_push!(branch_protection_rule_event, BranchProtectionRuleEvent); + event_push!(branch_protection_rule_event, BranchProtectionRuleEvent) } EventTypes::Create => { - event_push!(tag_created, CreateEvent); + event_push!(tag_created, CreateEvent) } EventTypes::Delete => { - event_push!(tag_deleted, DeleteEvent); + event_push!(tag_deleted, DeleteEvent) } EventTypes::Fork => { - event_push!(repository_forked, ForkEvent); + event_push!(repository_forked, ForkEvent) } EventTypes::CheckRun => { - event_push!(check_run, CheckRunEvent); + event_push!(check_run, CheckRunEvent) } EventTypes::CheckSuite => { - event_push!(check_suite_event, CheckSuiteEvent); + event_push!(check_suite_event, CheckSuiteEvent) } EventTypes::CodeScanningAlert => { - event_push!(code_scanning_alert_event, CodeScanningAlertEvent); + event_push!(code_scanning_alert_event, CodeScanningAlertEvent) } EventTypes::Deployment => { - event_push!(deployment_event, DeploymentEvent); + event_push!(deployment_event, DeploymentEvent) } EventTypes::DeploymentStatus => { - event_push!(deployment_status_event, DeploymentStatusEvent); + event_push!(deployment_status_event, DeploymentStatusEvent) } EventTypes::PageBuild => { - event_push!(page_build_event, PageBuildEvent); + event_push!(page_build_event, PageBuildEvent) } EventTypes::WorkflowDispatch => { - event_push!(workflow_dispatch_event, WorkflowDispatchEvent); + event_push!(workflow_dispatch_event, WorkflowDispatchEvent) } EventTypes::WorkflowJob => { - event_push!(workflow_job, WorkflowJobEvent); + event_push!(workflow_job, WorkflowJobEvent) } EventTypes::WorkflowRun => { - event_push!(workflow_run, WorkflowRunEvent); + event_push!(workflow_run, WorkflowRunEvent) } EventTypes::Membership => { - event_push!(membership_event, MembershipEvent); + event_push!(membership_event, MembershipEvent) } EventTypes::OrgBlock => { - event_push!(org_block_event, OrgBlockEvent); + event_push!(org_block_event, OrgBlockEvent) } EventTypes::Organization => { - event_push!(organization_event, OrganizationEvent); + event_push!(organization_event, OrganizationEvent) } EventTypes::Team => { - event_push!(team_event, TeamEvent); + event_push!(team_event, TeamEvent) } EventTypes::TeamAdd => { - event_push!(team_add_event, TeamAddEvent); + event_push!(team_add_event, TeamAddEvent) } EventTypes::Project => { - event_push!(project_event, ProjectEvent); - } - EventTypes::ProjectCard => {} - EventTypes::ProjectColumn => {} - EventTypes::MarketplacePurchase => {} - EventTypes::Meta => {} - EventTypes::Package => {} - EventTypes::Ping => {} - EventTypes::Sponsorship => {} - }; + event_push!(project_event, ProjectEvent) + } + EventTypes::ProjectCard => { + event_push!(project_card_event, ProjectCardEvent) + } + EventTypes::ProjectColumn => { + event_push!(project_column_event, ProjectColumnEvent) + } + EventTypes::MarketplacePurchase => { + event_push!(marketplace_purchase_event, MarketplacePurchaseEvent) + } + EventTypes::Meta => { + event_push!(meta_event, MetaEvent) + } + EventTypes::Package => { + event_push!(package_event, PackageEvent) + } + EventTypes::Ping => { + event_push!(ping_event, PingEvent) + } + EventTypes::Sponsorship => { + event_push!(sponsorship_event, SponsorshipEvent) + } + } + }; +} + +impl Client +where + T: Debug + EventHandler> + Send + Sync + 'static, +{ + #[cfg(all(target_family = "wasm", feature = "workers"))] + pub async fn handle(self, mut req: worker::Request) { + let _ = self.run().await.expect("Starting application: User-defined code"); + + let self_arc = Arc::new(self); + let thread_self = self_arc.clone(); + let thread_self_2 = self_arc.clone(); + + let ev = serde_json::from_str(&req.headers().get("x-github-event").unwrap().unwrap()) + .expect("Failed to parse headers"); + + macro_rules! event_push { + ($f:ident, $t:ty) => { + thread_self + .event_handler() + .$f( + thread_self.clone(), + (req).json::<$t>().await.expect("Failed to parse json"), + ) + .await + }; + } + + let user_cmd = event_handle!(ev); let mut cmd = user_cmd.into_futures(); @@ -340,170 +361,7 @@ where } let ev_h = async { - let user_cmd = match ev { - EventTypes::Push => { - event_push!(commit_event, PushEvent) - } - EventTypes::GithubAppAuthorization => { - event_push!(app_authorization_event, AppAuthorizationEvent) - } - EventTypes::Installation => { - event_push!(installation_event, InstallationEvent) - } - EventTypes::InstallationRepositories => { - event_push!(installation_repositories_event, InstallationRepositoriesEvent) - } - EventTypes::DeployKey => { - event_push!(deploy_key_event, DeployKeyEvent) - } - EventTypes::Gollum => { - event_push!(gollum_event, GollumEvent) - } - EventTypes::Member => { - event_push!(member_event, MemberEvent) - } - EventTypes::Milestone => { - event_push!(milestone_event, MilestoneEvent) - } - EventTypes::Public => { - event_push!(public_event, PublicEvent) - } - EventTypes::Release => { - event_push!(release_event, ReleaseEvent) - } - EventTypes::Repository => { - event_push!(repository_event, RepositoryEvent) - } - EventTypes::RepositoryDispatch => { - event_push!(repository_dispatch_event, RepositoryDispatchEvent) - } - EventTypes::RepositoryImport => { - event_push!(repository_import_event, RepositoryImportEvent) - } - EventTypes::RepositoryVulnerabilityAlert => { - event_push!(repository_vulnerability_alert, RepositoryVulnerabilityAlertEvent) - } - EventTypes::SecretScanningAlert => { - event_push!(secret_scanning_alert, SecretScanningAlertEvent) - } - EventTypes::SecurityAdvisory => { - event_push!(security_advisory, SecurityAdvisoryEvent) - } - EventTypes::Star => { - event_push!(star_event, StarEvent) - } - EventTypes::Watch => { - event_push!(watch_event, WatchEvent) - } - EventTypes::PullRequest => { - event_push!(pull_request_event, PullRequestEvent) - } - EventTypes::PullRequestReview => { - event_push!(pull_request_review_event, PullRequestReviewEvent) - } - EventTypes::PullRequestReviewComment => { - event_push!(pull_request_review_comment_event, PullRequestReviewCommentEvent) - } - EventTypes::CommitComment => { - event_push!(commit_comment_event, CommitCommentEvent) - } - EventTypes::Status => { - event_push!(status_event, StatusEvent) - } - EventTypes::IssueComment => { - event_push!(issue_comment_event, IssueCommentEvent) - } - EventTypes::Issues => { - event_push!(issue_event, IssueEvent) - } - EventTypes::Label => { - event_push!(label_event, LabelEvent) - } - EventTypes::Discussion => { - event_push!(discussion_event, DiscussionEvent) - } - EventTypes::DiscussionComment => { - event_push!(discussion_comment_event, DiscussionCommentEvent) - } - EventTypes::BranchProtectionRule => { - event_push!(branch_protection_rule_event, BranchProtectionRuleEvent) - } - EventTypes::Create => { - event_push!(tag_created, CreateEvent) - } - EventTypes::Delete => { - event_push!(tag_deleted, DeleteEvent) - } - EventTypes::Fork => { - event_push!(repository_forked, ForkEvent) - } - EventTypes::CheckRun => { - event_push!(check_run, CheckRunEvent) - } - EventTypes::CheckSuite => { - event_push!(check_suite_event, CheckSuiteEvent) - } - EventTypes::CodeScanningAlert => { - event_push!(code_scanning_alert_event, CodeScanningAlertEvent) - } - EventTypes::Deployment => { - event_push!(deployment_event, DeploymentEvent) - } - EventTypes::DeploymentStatus => { - event_push!(deployment_status_event, DeploymentStatusEvent) - } - EventTypes::PageBuild => { - event_push!(page_build_event, PageBuildEvent) - } - EventTypes::WorkflowDispatch => { - event_push!(workflow_dispatch_event, WorkflowDispatchEvent) - } - EventTypes::WorkflowJob => { - event_push!(workflow_job, WorkflowJobEvent) - } - EventTypes::WorkflowRun => { - event_push!(workflow_run, WorkflowRunEvent) - } - EventTypes::Membership => { - event_push!(membership_event, MembershipEvent) - } - EventTypes::OrgBlock => { - event_push!(org_block_event, OrgBlockEvent) - } - EventTypes::Organization => { - event_push!(organization_event, OrganizationEvent) - } - EventTypes::Team => { - event_push!(team_event, TeamEvent) - } - EventTypes::TeamAdd => { - event_push!(team_add_event, TeamAddEvent) - } - EventTypes::Project => { - event_push!(project_event, ProjectEvent) - } - EventTypes::ProjectCard => { - event_push!(project_card_event, ProjectCardEvent) - } - EventTypes::ProjectColumn => { - event_push!(project_column_event, ProjectColumnEvent) - } - EventTypes::MarketplacePurchase => { - event_push!(marketplace_purchase_event, MarketplacePurchaseEvent) - } - EventTypes::Meta => { - event_push!(meta_event, MetaEvent) - } - EventTypes::Package => { - event_push!(package_event, PackageEvent) - } - EventTypes::Ping => { - event_push!(ping_event, PingEvent) - } - EventTypes::Sponsorship => { - event_push!(sponsorship_event, SponsorshipEvent) - } - }; + let user_cmd = event_handle!(ev); if !user_cmd.is_empty() { let _ = &tx.send(user_cmd).await; diff --git a/octocat-rs/src/github/http.rs b/octocat-rs/src/github/http.rs index fc4ee044..033dfb11 100644 --- a/octocat-rs/src/github/http.rs +++ b/octocat-rs/src/github/http.rs @@ -1,16 +1,17 @@ //! Contains [`HttpClient`]. use async_trait::async_trait; -#[cfg(not(feature = "workers"))] +#[cfg(feature = "native")] use reqwest::{ header, header::{HeaderMap, HeaderValue}, Body, RequestBuilder, }; use serde::{de::DeserializeOwned, Serialize}; +#[cfg(feature = "native")] use tokio::time::Duration; -#[cfg(feature = "workers")] +#[cfg(all(target_family = "wasm", feature = "workers"))] use worker::{Fetch, Method, Request, RequestInit, ResponseBody::Body}; use github_rest::{ @@ -27,11 +28,15 @@ const ACCEPT_HEADER_PARSE_ERROR: &str = "HttpClient: Parsing accept header"; /// /// [`Requester`]: github_rest::Requester pub struct HttpClient { + #[cfg(feature = "native")] client: reqwest::Client, + #[cfg(all(target_family = "wasm", feature = "workers"))] + user_agent: Option, auth: Option, } impl HttpClient { + #[cfg(feature = "native")] pub fn new(auth: Option, user_agent: Option) -> Self { let mut headers = HeaderMap::new(); @@ -59,12 +64,18 @@ impl HttpClient { } } + #[cfg(all(target_family = "wasm", feature = "workers"))] + pub fn new(auth: Option, user_agent: Option) -> Self { + HttpClient { user_agent, auth } + } + /// Updates the authorization used by the current client. pub fn set_auth(&mut self, auth: Authorization) { self.auth = Some(auth); } /// Set the user agent used by the current client. + #[cfg(feature = "native")] pub fn set_ua(&mut self, user_agent: String) { let mut headers = HeaderMap::new(); @@ -84,7 +95,13 @@ impl HttpClient { .unwrap() } - #[cfg(not(feature = "workers"))] + /// Set the user agent used by the current client. + #[cfg(all(target_family = "wasm", feature = "workers"))] + pub fn set_ua(&mut self, user_agent: String) { + self.user_agent = Some(user_agent); + } + + #[cfg(feature = "default")] fn http_auth(&self, req: RequestBuilder) -> RequestBuilder { if let Some(auth) = &self.auth { match auth { @@ -94,21 +111,16 @@ impl HttpClient { req } } - - #[cfg(feature = "workers")] - fn http_auth(&self, req: RequestBuilder) -> RequestBuilder { - todo!() - } } #[async_trait] impl github_rest::Requester for HttpClient { - #[cfg(not(feature = "workers"))] /// Returns the API response as a [`String`]. + #[cfg(feature = "native")] async fn raw_req(&self, url: EndPoints, query: Option<&T>, body: Option) -> Result where T: Serialize + ?Sized + Send + Sync, - V: Into + Send, + V: Into + Send, { let path = format!("https://api.github.com{}", url.path()); @@ -141,12 +153,12 @@ impl github_rest::Requester for HttpClient { Ok(txt) } - #[cfg(feature = "workers")] /// Returns the API response as a [`String`]. + #[cfg(all(target_family = "wasm", feature = "workers"))] async fn raw_req(&self, url: EndPoints, query: Option<&T>, body: Option) -> Result where T: Serialize + ?Sized + Send + Sync, - V: Into + Send, + V: Into + Send, { let path = format!("https://api.github.com{}", url.path()); @@ -189,7 +201,7 @@ impl github_rest::Requester for HttpClient { ) -> Result where T: Serialize + ?Sized + Send + Sync, - V: Into + Send, + V: Into + Send, { let r = self.raw_req(url, query, body).await?; Ok(serde_json::from_str(&r)?) diff --git a/octocat-rs/src/github/mod.rs b/octocat-rs/src/github/mod.rs index 1075d4ea..2b47529d 100644 --- a/octocat-rs/src/github/mod.rs +++ b/octocat-rs/src/github/mod.rs @@ -34,6 +34,7 @@ mod tests { let _client = ClientBuilder::build_unconfigured(); } + #[cfg(feature = "native")] #[tokio::test] async fn standard() { #[derive(Debug)] diff --git a/octocat-rs/src/lib.rs b/octocat-rs/src/lib.rs index fe4b9fa3..95106fed 100644 --- a/octocat-rs/src/lib.rs +++ b/octocat-rs/src/lib.rs @@ -13,8 +13,8 @@ pub mod github; pub use github_api as api; pub use github_rest as rest; -#[cfg(all(feature = "warp", feature = "worker"))] -compile_error!("feature \"worker\" and feature \"warp\" cannot be enabled at the same time"); +#[cfg(all(feature = "default", feature = "workers"))] +compile_error!("feature \"default\" and feature \"workers\" cannot be enabled at the same time"); #[cfg(test)] mod tests { From e39928396f03fc3573cac78903e0a57e47c5a316 Mon Sep 17 00:00:00 2001 From: Proudmuslim Date: Tue, 1 Mar 2022 11:21:05 -0800 Subject: [PATCH 06/11] [skip ci] wip: Begin work on `Send` wrappers for non `Send` types present in `wasm_bindgen` See the TODO on `RequestInitWrapper` for more information --- github-rest/src/lib.rs | 5 +++++ github-rest/src/methods/mod.rs | 1 + octocat-rs/src/github/http.rs | 18 ++++++++++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/github-rest/src/lib.rs b/github-rest/src/lib.rs index a8b1f556..62c24aeb 100644 --- a/github-rest/src/lib.rs +++ b/github-rest/src/lib.rs @@ -7,8 +7,10 @@ use std::error::Error; use async_trait::async_trait; pub use github_api::end_points; use github_api::end_points::EndPoints; + #[cfg(not(target_family = "wasm"))] use reqwest::{Body, StatusCode}; + use serde::{de::DeserializeOwned, Serialize}; #[cfg(target_family = "wasm")] use worker::wasm_bindgen::JsValue; @@ -26,7 +28,10 @@ pub enum GithubRestError { ReqwestError(reqwest::Error), #[cfg(target_family = "wasm")] WorkerError(worker::Error), + #[cfg(target_family = "wasm")] + ResponseError(u16, String), JsonError(serde_json::Error), + #[cfg(not(target_family = "wasm"))] ResponseError(StatusCode, String), AnyError(), } diff --git a/github-rest/src/methods/mod.rs b/github-rest/src/methods/mod.rs index 00a39226..e63a4925 100644 --- a/github-rest/src/methods/mod.rs +++ b/github-rest/src/methods/mod.rs @@ -14,6 +14,7 @@ pub(crate) mod util; /// Prelude mod used for methods pub mod prelude { pub use github_api::end_points::*; + #[cfg(not(target_family = "wasm"))] pub use reqwest::Body; pub use serde::{Deserialize, Serialize}; diff --git a/octocat-rs/src/github/http.rs b/octocat-rs/src/github/http.rs index 033dfb11..25e4e281 100644 --- a/octocat-rs/src/github/http.rs +++ b/octocat-rs/src/github/http.rs @@ -12,7 +12,10 @@ use serde::{de::DeserializeOwned, Serialize}; use tokio::time::Duration; #[cfg(all(target_family = "wasm", feature = "workers"))] -use worker::{Fetch, Method, Request, RequestInit, ResponseBody::Body}; +use worker::{CfProperties, Fetch, Headers, Method, Request, RequestInit, RequestRedirect, ResponseBody::Body}; + +#[cfg(all(target_family = "wasm", feature = "workers"))] +use std::collections::HashMap; use github_rest::{ methods::prelude::{EndPoints, Methods}, @@ -24,6 +27,17 @@ use crate::github::Authorization; const USER_AGENT_PARSE_ERROR: &str = "HttpClient: Parsing user agent"; const ACCEPT_HEADER_PARSE_ERROR: &str = "HttpClient: Parsing accept header"; +// TODO: Body field + actually use this to substitute RequestInit +// Issue with some more info on why JsValue isn't `Send`: +#[cfg(all(target_family = "wasm", feature = "workers"))] +#[derive(Default, Debug)] +pub struct RequestInitWrapper { + headers: HashMap, + method: Method, + cf: CfProperties, + redirect: RequestRedirect, +} + /// An implementer of the [`Requester`] trait. /// /// [`Requester`]: github_rest::Requester @@ -185,7 +199,7 @@ impl github_rest::Requester for HttpClient { match res.status_code() { 200..=299 => {} _ => { - return Err(GithubRestError::ResponseError(res.status(), res.text().await?)); + return Err(GithubRestError::ResponseError(res.status_code(), res.text().await?)); } } let txt = res.text().await?; From 52baf30d6d9b5050f2fd8773b619945ada6ac1a8 Mon Sep 17 00:00:00 2001 From: Proudmuslim Date: Thu, 3 Mar 2022 15:00:08 -0800 Subject: [PATCH 07/11] :tada: wip: Complete basic support! See the todos I made for the minor stuff that still needs to be added in- I might have missed some stuff, but I'm too happy to care right now --- examples/cloudflare/Cargo.toml | 4 +- examples/cloudflare/deps | 343 -------------------------------- examples/cloudflare/src/lib.rs | 46 +++-- octocat-rs/deps | 224 --------------------- octocat-rs/src/github/client.rs | 9 +- octocat-rs/src/github/http.rs | 83 ++++---- octocat-rs/src/github/mod.rs | 10 +- rust-toolchain.toml | 3 + 8 files changed, 82 insertions(+), 640 deletions(-) delete mode 100644 examples/cloudflare/deps delete mode 100644 octocat-rs/deps create mode 100644 rust-toolchain.toml diff --git a/examples/cloudflare/Cargo.toml b/examples/cloudflare/Cargo.toml index 519a61a1..b6fac066 100644 --- a/examples/cloudflare/Cargo.toml +++ b/examples/cloudflare/Cargo.toml @@ -12,8 +12,8 @@ default = ["console_error_panic_hook"] [dependencies] cfg-if = "1.0.0" -serde_json = "1.0.79" -octocat-rs = { path = "../../octocat-rs", features = ["workers"], default-features = false } +serde_json = "1" +octocat-rs = { path = "../../octocat-rs", default-features = false, features = ["workers"] } worker = "0.0.9" # The `console_error_panic_hook` crate provides better debugging of panics by diff --git a/examples/cloudflare/deps b/examples/cloudflare/deps deleted file mode 100644 index 2aece43b..00000000 --- a/examples/cloudflare/deps +++ /dev/null @@ -1,343 +0,0 @@ -cloudflare v0.1.0 (/home/twilight/CLionProjects/octocat-rs/examples/cloudflare) -├── anyhow v1.0.54 -├── async-trait v0.1.52 (proc-macro) -│ ├── proc-macro2 v1.0.36 -│ │ └── unicode-xid v0.2.2 -│ ├── quote v1.0.15 -│ │ └── proc-macro2 v1.0.36 (*) -│ └── syn v1.0.86 -│ ├── proc-macro2 v1.0.36 (*) -│ ├── quote v1.0.15 (*) -│ └── unicode-xid v0.2.2 -├── cfg-if v1.0.0 -├── console_error_panic_hook v0.1.7 -│ ├── cfg-if v1.0.0 -│ └── wasm-bindgen v0.2.78 -│ ├── cfg-if v1.0.0 -│ ├── serde v1.0.136 -│ │ └── serde_derive v1.0.136 (proc-macro) -│ │ ├── proc-macro2 v1.0.36 (*) -│ │ ├── quote v1.0.15 (*) -│ │ └── syn v1.0.86 (*) -│ ├── serde_json v1.0.79 -│ │ ├── itoa v1.0.1 -│ │ ├── ryu v1.0.9 -│ │ └── serde v1.0.136 (*) -│ └── wasm-bindgen-macro v0.2.78 (proc-macro) -│ ├── quote v1.0.15 (*) -│ └── wasm-bindgen-macro-support v0.2.78 -│ ├── proc-macro2 v1.0.36 (*) -│ ├── quote v1.0.15 (*) -│ ├── syn v1.0.86 (*) -│ ├── wasm-bindgen-backend v0.2.78 -│ │ ├── bumpalo v3.9.1 -│ │ ├── lazy_static v1.4.0 -│ │ ├── log v0.4.14 -│ │ │ └── cfg-if v1.0.0 -│ │ ├── proc-macro2 v1.0.36 (*) -│ │ ├── quote v1.0.15 (*) -│ │ ├── syn v1.0.86 (*) -│ │ └── wasm-bindgen-shared v0.2.78 -│ └── wasm-bindgen-shared v0.2.78 -├── octocat-rs v0.0.0 (/home/twilight/CLionProjects/octocat-rs/octocat-rs) -│ ├── anyhow v1.0.54 -│ ├── async-trait v0.1.52 (proc-macro) (*) -│ ├── futures v0.3.21 -│ │ ├── futures-channel v0.3.21 -│ │ │ ├── futures-core v0.3.21 -│ │ │ └── futures-sink v0.3.21 -│ │ ├── futures-core v0.3.21 -│ │ ├── futures-executor v0.3.21 -│ │ │ ├── futures-core v0.3.21 -│ │ │ ├── futures-task v0.3.21 -│ │ │ └── futures-util v0.3.21 -│ │ │ ├── futures-channel v0.3.21 (*) -│ │ │ ├── futures-core v0.3.21 -│ │ │ ├── futures-io v0.3.21 -│ │ │ ├── futures-macro v0.3.21 (proc-macro) -│ │ │ │ ├── proc-macro2 v1.0.36 (*) -│ │ │ │ ├── quote v1.0.15 (*) -│ │ │ │ └── syn v1.0.86 (*) -│ │ │ ├── futures-sink v0.3.21 -│ │ │ ├── futures-task v0.3.21 -│ │ │ ├── memchr v2.4.1 -│ │ │ ├── pin-project-lite v0.2.8 -│ │ │ ├── pin-utils v0.1.0 -│ │ │ └── slab v0.4.5 -│ │ ├── futures-io v0.3.21 -│ │ ├── futures-sink v0.3.21 -│ │ ├── futures-task v0.3.21 -│ │ └── futures-util v0.3.21 (*) -│ ├── github-api v0.1.0 (https://github.com/octocat-rs/github-api#638ff4e6) -│ │ ├── serde v1.0.136 (*) -│ │ └── serde_json v1.0.79 (*) -│ ├── github-rest v0.1.0 (/home/twilight/CLionProjects/octocat-rs/github-rest) -│ │ ├── async-trait v0.1.52 (proc-macro) (*) -│ │ ├── github-api v0.1.0 (https://github.com/octocat-rs/github-api#638ff4e6) (*) -│ │ ├── reqwest v0.11.9 -│ │ │ ├── base64 v0.13.0 -│ │ │ ├── bytes v1.1.0 -│ │ │ ├── encoding_rs v0.8.30 -│ │ │ │ └── cfg-if v1.0.0 -│ │ │ ├── futures-core v0.3.21 -│ │ │ ├── futures-util v0.3.21 (*) -│ │ │ ├── h2 v0.3.11 -│ │ │ │ ├── bytes v1.1.0 -│ │ │ │ ├── fnv v1.0.7 -│ │ │ │ ├── futures-core v0.3.21 -│ │ │ │ ├── futures-sink v0.3.21 -│ │ │ │ ├── futures-util v0.3.21 (*) -│ │ │ │ ├── http v0.2.6 -│ │ │ │ │ ├── bytes v1.1.0 -│ │ │ │ │ ├── fnv v1.0.7 -│ │ │ │ │ └── itoa v1.0.1 -│ │ │ │ ├── indexmap v1.8.0 -│ │ │ │ │ └── hashbrown v0.11.2 -│ │ │ │ │ [build-dependencies] -│ │ │ │ │ └── autocfg v1.1.0 -│ │ │ │ ├── slab v0.4.5 -│ │ │ │ ├── tokio v1.17.0 -│ │ │ │ │ ├── bytes v1.1.0 -│ │ │ │ │ ├── libc v0.2.118 -│ │ │ │ │ ├── memchr v2.4.1 -│ │ │ │ │ ├── mio v0.8.0 -│ │ │ │ │ │ ├── libc v0.2.118 -│ │ │ │ │ │ └── log v0.4.14 (*) -│ │ │ │ │ ├── num_cpus v1.13.1 -│ │ │ │ │ │ └── libc v0.2.118 -│ │ │ │ │ ├── once_cell v1.9.0 -│ │ │ │ │ ├── parking_lot v0.12.0 -│ │ │ │ │ │ ├── lock_api v0.4.6 -│ │ │ │ │ │ │ └── scopeguard v1.1.0 -│ │ │ │ │ │ └── parking_lot_core v0.9.1 -│ │ │ │ │ │ ├── cfg-if v1.0.0 -│ │ │ │ │ │ ├── libc v0.2.118 -│ │ │ │ │ │ └── smallvec v1.8.0 -│ │ │ │ │ ├── pin-project-lite v0.2.8 -│ │ │ │ │ ├── signal-hook-registry v1.4.0 -│ │ │ │ │ │ └── libc v0.2.118 -│ │ │ │ │ ├── socket2 v0.4.4 -│ │ │ │ │ │ └── libc v0.2.118 -│ │ │ │ │ └── tokio-macros v1.7.0 (proc-macro) -│ │ │ │ │ ├── proc-macro2 v1.0.36 (*) -│ │ │ │ │ ├── quote v1.0.15 (*) -│ │ │ │ │ └── syn v1.0.86 (*) -│ │ │ │ ├── tokio-util v0.6.9 -│ │ │ │ │ ├── bytes v1.1.0 -│ │ │ │ │ ├── futures-core v0.3.21 -│ │ │ │ │ ├── futures-sink v0.3.21 -│ │ │ │ │ ├── log v0.4.14 (*) -│ │ │ │ │ ├── pin-project-lite v0.2.8 -│ │ │ │ │ └── tokio v1.17.0 (*) -│ │ │ │ └── tracing v0.1.31 -│ │ │ │ ├── cfg-if v1.0.0 -│ │ │ │ ├── pin-project-lite v0.2.8 -│ │ │ │ └── tracing-core v0.1.22 -│ │ │ │ └── lazy_static v1.4.0 -│ │ │ ├── http v0.2.6 (*) -│ │ │ ├── http-body v0.4.4 -│ │ │ │ ├── bytes v1.1.0 -│ │ │ │ ├── http v0.2.6 (*) -│ │ │ │ └── pin-project-lite v0.2.8 -│ │ │ ├── hyper v0.14.17 -│ │ │ │ ├── bytes v1.1.0 -│ │ │ │ ├── futures-channel v0.3.21 (*) -│ │ │ │ ├── futures-core v0.3.21 -│ │ │ │ ├── futures-util v0.3.21 (*) -│ │ │ │ ├── h2 v0.3.11 (*) -│ │ │ │ ├── http v0.2.6 (*) -│ │ │ │ ├── http-body v0.4.4 (*) -│ │ │ │ ├── httparse v1.6.0 -│ │ │ │ ├── httpdate v1.0.2 -│ │ │ │ ├── itoa v1.0.1 -│ │ │ │ ├── pin-project-lite v0.2.8 -│ │ │ │ ├── socket2 v0.4.4 (*) -│ │ │ │ ├── tokio v1.17.0 (*) -│ │ │ │ ├── tower-service v0.3.1 -│ │ │ │ ├── tracing v0.1.31 (*) -│ │ │ │ └── want v0.3.0 -│ │ │ │ ├── log v0.4.14 (*) -│ │ │ │ └── try-lock v0.2.3 -│ │ │ ├── hyper-rustls v0.23.0 -│ │ │ │ ├── http v0.2.6 (*) -│ │ │ │ ├── hyper v0.14.17 (*) -│ │ │ │ ├── rustls v0.20.4 -│ │ │ │ │ ├── log v0.4.14 (*) -│ │ │ │ │ ├── ring v0.16.20 -│ │ │ │ │ │ ├── libc v0.2.118 -│ │ │ │ │ │ ├── once_cell v1.9.0 -│ │ │ │ │ │ ├── spin v0.5.2 -│ │ │ │ │ │ └── untrusted v0.7.1 -│ │ │ │ │ │ [build-dependencies] -│ │ │ │ │ │ └── cc v1.0.73 -│ │ │ │ │ ├── sct v0.7.0 -│ │ │ │ │ │ ├── ring v0.16.20 (*) -│ │ │ │ │ │ └── untrusted v0.7.1 -│ │ │ │ │ └── webpki v0.22.0 -│ │ │ │ │ ├── ring v0.16.20 (*) -│ │ │ │ │ └── untrusted v0.7.1 -│ │ │ │ ├── tokio v1.17.0 (*) -│ │ │ │ └── tokio-rustls v0.23.2 -│ │ │ │ ├── rustls v0.20.4 (*) -│ │ │ │ ├── tokio v1.17.0 (*) -│ │ │ │ └── webpki v0.22.0 (*) -│ │ │ ├── hyper-tls v0.5.0 -│ │ │ │ ├── bytes v1.1.0 -│ │ │ │ ├── hyper v0.14.17 (*) -│ │ │ │ ├── native-tls v0.2.8 -│ │ │ │ │ ├── log v0.4.14 (*) -│ │ │ │ │ ├── openssl v0.10.38 -│ │ │ │ │ │ ├── bitflags v1.3.2 -│ │ │ │ │ │ ├── cfg-if v1.0.0 -│ │ │ │ │ │ ├── foreign-types v0.3.2 -│ │ │ │ │ │ │ └── foreign-types-shared v0.1.1 -│ │ │ │ │ │ ├── libc v0.2.118 -│ │ │ │ │ │ ├── once_cell v1.9.0 -│ │ │ │ │ │ └── openssl-sys v0.9.72 -│ │ │ │ │ │ └── libc v0.2.118 -│ │ │ │ │ │ [build-dependencies] -│ │ │ │ │ │ ├── autocfg v1.1.0 -│ │ │ │ │ │ ├── cc v1.0.73 -│ │ │ │ │ │ └── pkg-config v0.3.24 -│ │ │ │ │ ├── openssl-probe v0.1.5 -│ │ │ │ │ └── openssl-sys v0.9.72 (*) -│ │ │ │ ├── tokio v1.17.0 (*) -│ │ │ │ └── tokio-native-tls v0.3.0 -│ │ │ │ ├── native-tls v0.2.8 (*) -│ │ │ │ └── tokio v1.17.0 (*) -│ │ │ ├── ipnet v2.3.1 -│ │ │ ├── lazy_static v1.4.0 -│ │ │ ├── log v0.4.14 (*) -│ │ │ ├── mime v0.3.16 -│ │ │ ├── native-tls v0.2.8 (*) -│ │ │ ├── percent-encoding v2.1.0 -│ │ │ ├── pin-project-lite v0.2.8 -│ │ │ ├── rustls v0.20.4 (*) -│ │ │ ├── rustls-pemfile v0.2.1 -│ │ │ │ └── base64 v0.13.0 -│ │ │ ├── serde v1.0.136 (*) -│ │ │ ├── serde_urlencoded v0.7.1 -│ │ │ │ ├── form_urlencoded v1.0.1 -│ │ │ │ │ ├── matches v0.1.9 -│ │ │ │ │ └── percent-encoding v2.1.0 -│ │ │ │ ├── itoa v1.0.1 -│ │ │ │ ├── ryu v1.0.9 -│ │ │ │ └── serde v1.0.136 (*) -│ │ │ ├── tokio v1.17.0 (*) -│ │ │ ├── tokio-native-tls v0.3.0 (*) -│ │ │ ├── tokio-rustls v0.23.2 (*) -│ │ │ ├── url v2.2.2 -│ │ │ │ ├── form_urlencoded v1.0.1 (*) -│ │ │ │ ├── idna v0.2.3 -│ │ │ │ │ ├── matches v0.1.9 -│ │ │ │ │ ├── unicode-bidi v0.3.7 -│ │ │ │ │ └── unicode-normalization v0.1.19 -│ │ │ │ │ └── tinyvec v1.5.1 -│ │ │ │ │ └── tinyvec_macros v0.1.0 -│ │ │ │ ├── matches v0.1.9 -│ │ │ │ └── percent-encoding v2.1.0 -│ │ │ └── webpki-roots v0.22.2 -│ │ │ └── webpki v0.22.0 (*) -│ │ ├── serde v1.0.136 (*) -│ │ ├── serde_json v1.0.79 (*) -│ │ └── strum v0.23.0 -│ │ └── strum_macros v0.23.1 (proc-macro) -│ │ ├── heck v0.3.3 -│ │ │ └── unicode-segmentation v1.9.0 -│ │ ├── proc-macro2 v1.0.36 (*) -│ │ ├── quote v1.0.15 (*) -│ │ ├── rustversion v1.0.6 (proc-macro) -│ │ └── syn v1.0.86 (*) -│ ├── reqwest v0.11.9 (*) -│ ├── serde v1.0.136 (*) -│ ├── serde_json v1.0.79 (*) -│ ├── strum v0.23.0 (*) -│ ├── strum_macros v0.23.1 (proc-macro) (*) -│ ├── thiserror v1.0.30 -│ │ └── thiserror-impl v1.0.30 (proc-macro) -│ │ ├── proc-macro2 v1.0.36 (*) -│ │ ├── quote v1.0.15 (*) -│ │ └── syn v1.0.86 (*) -│ ├── tokio v1.17.0 (*) -│ ├── toml v0.5.8 -│ │ └── serde v1.0.136 (*) -│ └── worker v0.0.9 -│ ├── async-trait v0.1.52 (proc-macro) (*) -│ ├── chrono v0.4.19 -│ │ ├── num-integer v0.1.44 -│ │ │ └── num-traits v0.2.14 -│ │ │ [build-dependencies] -│ │ │ └── autocfg v1.1.0 -│ │ │ [build-dependencies] -│ │ │ └── autocfg v1.1.0 -│ │ └── num-traits v0.2.14 (*) -│ ├── chrono-tz v0.6.1 -│ │ ├── chrono v0.4.19 (*) -│ │ └── phf v0.10.1 -│ │ └── phf_shared v0.10.0 -│ │ ├── siphasher v0.3.9 -│ │ └── uncased v0.9.6 -│ │ [build-dependencies] -│ │ └── version_check v0.9.4 -│ │ [build-dependencies] -│ │ └── chrono-tz-build v0.0.2 -│ │ ├── parse-zoneinfo v0.3.0 -│ │ │ └── regex v1.5.4 -│ │ │ └── regex-syntax v0.6.25 -│ │ ├── phf v0.10.1 (*) -│ │ └── phf_codegen v0.10.0 -│ │ ├── phf_generator v0.10.0 -│ │ │ ├── phf_shared v0.10.0 (*) -│ │ │ └── rand v0.8.5 -│ │ │ ├── libc v0.2.118 -│ │ │ ├── rand_chacha v0.3.1 -│ │ │ │ ├── ppv-lite86 v0.2.16 -│ │ │ │ └── rand_core v0.6.3 -│ │ │ │ └── getrandom v0.2.4 -│ │ │ │ ├── cfg-if v1.0.0 -│ │ │ │ └── libc v0.2.118 -│ │ │ └── rand_core v0.6.3 (*) -│ │ └── phf_shared v0.10.0 (*) -│ ├── futures v0.3.21 (*) -│ ├── http v0.2.6 (*) -│ ├── js-sys v0.3.55 -│ │ └── wasm-bindgen v0.2.78 (*) -│ ├── matchit v0.4.6 -│ ├── pin-project v1.0.10 -│ │ └── pin-project-internal v1.0.10 (proc-macro) -│ │ ├── proc-macro2 v1.0.36 (*) -│ │ ├── quote v1.0.15 (*) -│ │ └── syn v1.0.86 (*) -│ ├── serde v1.0.136 (*) -│ ├── serde_json v1.0.79 (*) -│ ├── url v2.2.2 (*) -│ ├── wasm-bindgen v0.2.78 (*) -│ ├── wasm-bindgen-futures v0.4.28 -│ │ ├── cfg-if v1.0.0 -│ │ ├── js-sys v0.3.55 (*) -│ │ └── wasm-bindgen v0.2.78 (*) -│ ├── worker-kv v0.5.1 -│ │ ├── js-sys v0.3.55 (*) -│ │ ├── serde v1.0.136 (*) -│ │ ├── serde_json v1.0.79 (*) -│ │ ├── thiserror v1.0.30 (*) -│ │ ├── wasm-bindgen v0.2.78 (*) -│ │ └── wasm-bindgen-futures v0.4.28 (*) -│ ├── worker-macros v0.0.4 (proc-macro) -│ │ ├── async-trait v0.1.52 (proc-macro) (*) -│ │ ├── proc-macro2 v1.0.36 (*) -│ │ ├── quote v1.0.15 (*) -│ │ ├── syn v1.0.86 (*) -│ │ ├── wasm-bindgen v0.2.78 (*) -│ │ ├── wasm-bindgen-futures v0.4.28 (*) -│ │ ├── wasm-bindgen-macro-support v0.2.78 (*) -│ │ └── worker-sys v0.0.4 -│ │ ├── cfg-if v0.1.10 -│ │ ├── js-sys v0.3.55 (*) -│ │ ├── wasm-bindgen v0.2.78 (*) -│ │ └── web-sys v0.3.55 -│ │ ├── js-sys v0.3.55 (*) -│ │ └── wasm-bindgen v0.2.78 (*) -│ └── worker-sys v0.0.4 (*) -├── serde_json v1.0.79 (*) -└── worker v0.0.9 (*) diff --git a/examples/cloudflare/src/lib.rs b/examples/cloudflare/src/lib.rs index 3ed7c5aa..cdb65010 100644 --- a/examples/cloudflare/src/lib.rs +++ b/examples/cloudflare/src/lib.rs @@ -1,34 +1,35 @@ use std::sync::Arc; use async_trait::async_trait; -use worker::{console_log, event, Date, Env, Request, Response}; +use worker::{console_log, event, Env, Request, Response, Router}; -use octocat_rs::{handler::EventHandler, rest::model::repositories::events::PushEvent, Client, ClientBuilder, Command}; +use octocat_rs::{ + handler::EventHandler, + rest::model::{misc::events::MarketplacePurchaseEvent, repositories::events::PushEvent}, + Client, ClientBuilder, Command, +}; mod utils; #[event(fetch)] -pub async fn main(req: Request, _env: Env, _ctx: worker::Context) -> anyhow::Result { - log_request(&req); +pub async fn main(req: Request, env: Env, _ctx: worker::Context) -> worker::Result { + utils::set_panic_hook(); - ClientBuilder::new() - .event_handler(Handler {}) - .build()? - .handle(req) - .await; + let router = Router::new(); + let r = router + .post_async("/payload", |mut req, _| async { + // TODO: Don't construct this every time + let client = ClientBuilder::new().event_handler(Handler {}).build().unwrap(); + client.handle(req).await; - // This can't fail, so using anyhow::Result is preferred over worker::Result - Ok(Response::empty().unwrap()) -} + Response::empty() + }) + .get("/worker-version", |_, ctx| { + let version = ctx.var("WORKERS_RS_VERSION")?.to_string(); + Response::ok(version) + }); -fn log_request(req: &Request) { - console_log!( - "{} - [{}], located at: {:?}, within: {}", - Date::now().to_string(), - req.path(), - req.cf().coordinates().unwrap_or_default(), - req.cf().region().unwrap_or_else(|| "unknown region".into()) - ); + r.run(req, env).await } #[derive(Debug)] @@ -51,16 +52,17 @@ impl EventHandler for Handler { async fn message(&self, message: Self::Message) { match message { Message::Stuff(s) => { - println!("==> Message received: {s}"); + console_log!("==> Message received: {s}"); } } } + async fn commit_event( &self, _github_client: Arc, _commit: PushEvent, ) -> Command { - println!("Commit pushed!"); + console_log!("Commit pushed!"); Command::perform(async { "Computation finished" }, Message::Stuff) } diff --git a/octocat-rs/deps b/octocat-rs/deps deleted file mode 100644 index d31e4d1b..00000000 --- a/octocat-rs/deps +++ /dev/null @@ -1,224 +0,0 @@ -octocat-rs v0.0.0 (/home/twilight/CLionProjects/octocat-rs/octocat-rs) -├── anyhow v1.0.54 -├── async-trait v0.1.52 (proc-macro) -│ ├── proc-macro2 v1.0.36 -│ │ └── unicode-xid v0.2.2 -│ ├── quote v1.0.15 -│ │ └── proc-macro2 v1.0.36 (*) -│ └── syn v1.0.86 -│ ├── proc-macro2 v1.0.36 (*) -│ ├── quote v1.0.15 (*) -│ └── unicode-xid v0.2.2 -├── futures v0.3.21 -│ ├── futures-channel v0.3.21 -│ │ ├── futures-core v0.3.21 -│ │ └── futures-sink v0.3.21 -│ ├── futures-core v0.3.21 -│ ├── futures-executor v0.3.21 -│ │ ├── futures-core v0.3.21 -│ │ ├── futures-task v0.3.21 -│ │ └── futures-util v0.3.21 -│ │ ├── futures-channel v0.3.21 (*) -│ │ ├── futures-core v0.3.21 -│ │ ├── futures-io v0.3.21 -│ │ ├── futures-macro v0.3.21 (proc-macro) -│ │ │ ├── proc-macro2 v1.0.36 (*) -│ │ │ ├── quote v1.0.15 (*) -│ │ │ └── syn v1.0.86 (*) -│ │ ├── futures-sink v0.3.21 -│ │ ├── futures-task v0.3.21 -│ │ ├── memchr v2.4.1 -│ │ ├── pin-project-lite v0.2.8 -│ │ ├── pin-utils v0.1.0 -│ │ └── slab v0.4.5 -│ ├── futures-io v0.3.21 -│ ├── futures-sink v0.3.21 -│ ├── futures-task v0.3.21 -│ └── futures-util v0.3.21 (*) -├── github-api v0.1.0 (https://github.com/octocat-rs/github-api#638ff4e6) -│ ├── serde v1.0.136 -│ │ └── serde_derive v1.0.136 (proc-macro) -│ │ ├── proc-macro2 v1.0.36 (*) -│ │ ├── quote v1.0.15 (*) -│ │ └── syn v1.0.86 (*) -│ └── serde_json v1.0.79 -│ ├── itoa v1.0.1 -│ ├── ryu v1.0.9 -│ └── serde v1.0.136 (*) -├── github-rest v0.1.0 (/home/twilight/CLionProjects/octocat-rs/github-rest) -│ ├── async-trait v0.1.52 (proc-macro) (*) -│ ├── github-api v0.1.0 (https://github.com/octocat-rs/github-api#638ff4e6) (*) -│ ├── paste v1.0.6 (proc-macro) -│ ├── reqwest v0.11.9 -│ │ ├── bytes v1.1.0 -│ │ ├── http v0.2.6 -│ │ │ ├── bytes v1.1.0 -│ │ │ ├── fnv v1.0.7 -│ │ │ └── itoa v1.0.1 -│ │ ├── js-sys v0.3.55 -│ │ │ └── wasm-bindgen v0.2.78 -│ │ │ ├── cfg-if v1.0.0 -│ │ │ ├── serde v1.0.136 (*) -│ │ │ ├── serde_json v1.0.79 (*) -│ │ │ └── wasm-bindgen-macro v0.2.78 (proc-macro) -│ │ │ ├── quote v1.0.15 (*) -│ │ │ └── wasm-bindgen-macro-support v0.2.78 -│ │ │ ├── proc-macro2 v1.0.36 (*) -│ │ │ ├── quote v1.0.15 (*) -│ │ │ ├── syn v1.0.86 (*) -│ │ │ ├── wasm-bindgen-backend v0.2.78 -│ │ │ │ ├── bumpalo v3.9.1 -│ │ │ │ ├── lazy_static v1.4.0 -│ │ │ │ ├── log v0.4.14 -│ │ │ │ │ └── cfg-if v1.0.0 -│ │ │ │ ├── proc-macro2 v1.0.36 (*) -│ │ │ │ ├── quote v1.0.15 (*) -│ │ │ │ ├── syn v1.0.86 (*) -│ │ │ │ └── wasm-bindgen-shared v0.2.78 -│ │ │ └── wasm-bindgen-shared v0.2.78 -│ │ ├── serde v1.0.136 (*) -│ │ ├── serde_json v1.0.79 (*) -│ │ ├── serde_urlencoded v0.7.1 -│ │ │ ├── form_urlencoded v1.0.1 -│ │ │ │ ├── matches v0.1.9 -│ │ │ │ └── percent-encoding v2.1.0 -│ │ │ ├── itoa v1.0.1 -│ │ │ ├── ryu v1.0.9 -│ │ │ └── serde v1.0.136 (*) -│ │ ├── url v2.2.2 -│ │ │ ├── form_urlencoded v1.0.1 (*) -│ │ │ ├── idna v0.2.3 -│ │ │ │ ├── matches v0.1.9 -│ │ │ │ ├── unicode-bidi v0.3.7 -│ │ │ │ └── unicode-normalization v0.1.19 -│ │ │ │ └── tinyvec v1.5.1 -│ │ │ │ └── tinyvec_macros v0.1.0 -│ │ │ ├── matches v0.1.9 -│ │ │ └── percent-encoding v2.1.0 -│ │ ├── wasm-bindgen v0.2.78 (*) -│ │ ├── wasm-bindgen-futures v0.4.28 -│ │ │ ├── cfg-if v1.0.0 -│ │ │ ├── js-sys v0.3.55 (*) -│ │ │ └── wasm-bindgen v0.2.78 (*) -│ │ └── web-sys v0.3.55 -│ │ ├── js-sys v0.3.55 (*) -│ │ └── wasm-bindgen v0.2.78 (*) -│ ├── serde v1.0.136 (*) -│ ├── serde_json v1.0.79 (*) -│ └── strum v0.23.0 -│ └── strum_macros v0.23.1 (proc-macro) -│ ├── heck v0.3.3 -│ │ └── unicode-segmentation v1.9.0 -│ ├── proc-macro2 v1.0.36 (*) -│ ├── quote v1.0.15 (*) -│ ├── rustversion v1.0.6 (proc-macro) -│ └── syn v1.0.86 (*) -├── serde v1.0.136 (*) -├── serde_json v1.0.79 (*) -├── serde_urlencoded v0.7.1 (*) -├── strum v0.23.0 (*) -├── strum_macros v0.23.1 (proc-macro) (*) -├── thiserror v1.0.30 -│ └── thiserror-impl v1.0.30 (proc-macro) -│ ├── proc-macro2 v1.0.36 (*) -│ ├── quote v1.0.15 (*) -│ └── syn v1.0.86 (*) -├── toml v0.5.8 -│ └── serde v1.0.136 (*) -└── worker v0.0.9 - ├── async-trait v0.1.52 (proc-macro) (*) - ├── chrono v0.4.19 - │ ├── js-sys v0.3.55 (*) - │ ├── num-integer v0.1.44 - │ │ └── num-traits v0.2.14 - │ │ [build-dependencies] - │ │ └── autocfg v1.1.0 - │ │ [build-dependencies] - │ │ └── autocfg v1.1.0 - │ ├── num-traits v0.2.14 (*) - │ └── wasm-bindgen v0.2.78 (*) - ├── chrono-tz v0.6.1 - │ ├── chrono v0.4.19 (*) - │ └── phf v0.10.1 - │ └── phf_shared v0.10.0 - │ ├── siphasher v0.3.9 - │ └── uncased v0.9.6 - │ [build-dependencies] - │ └── version_check v0.9.4 - │ [build-dependencies] - │ └── chrono-tz-build v0.0.2 - │ ├── parse-zoneinfo v0.3.0 - │ │ └── regex v1.5.4 - │ │ └── regex-syntax v0.6.25 - │ ├── phf v0.10.1 - │ │ └── phf_shared v0.10.0 - │ │ ├── siphasher v0.3.9 - │ │ └── uncased v0.9.6 - │ │ [build-dependencies] - │ │ └── version_check v0.9.4 - │ └── phf_codegen v0.10.0 - │ ├── phf_generator v0.10.0 - │ │ ├── phf_shared v0.10.0 (*) - │ │ └── rand v0.8.5 - │ │ ├── libc v0.2.118 - │ │ ├── rand_chacha v0.3.1 - │ │ │ ├── ppv-lite86 v0.2.16 - │ │ │ └── rand_core v0.6.3 - │ │ │ └── getrandom v0.2.4 - │ │ │ ├── cfg-if v1.0.0 - │ │ │ └── libc v0.2.118 - │ │ └── rand_core v0.6.3 (*) - │ └── phf_shared v0.10.0 (*) - ├── futures v0.3.21 (*) - ├── http v0.2.6 (*) - ├── js-sys v0.3.55 (*) - ├── matchit v0.4.6 - ├── pin-project v1.0.10 - │ └── pin-project-internal v1.0.10 (proc-macro) - │ ├── proc-macro2 v1.0.36 (*) - │ ├── quote v1.0.15 (*) - │ └── syn v1.0.86 (*) - ├── serde v1.0.136 (*) - ├── serde_json v1.0.79 (*) - ├── url v2.2.2 (*) - ├── wasm-bindgen v0.2.78 (*) - ├── wasm-bindgen-futures v0.4.28 (*) - ├── worker-kv v0.5.1 - │ ├── js-sys v0.3.55 (*) - │ ├── serde v1.0.136 (*) - │ ├── serde_json v1.0.79 (*) - │ ├── thiserror v1.0.30 (*) - │ ├── wasm-bindgen v0.2.78 (*) - │ └── wasm-bindgen-futures v0.4.28 (*) - ├── worker-macros v0.0.4 (proc-macro) - │ ├── async-trait v0.1.52 (proc-macro) (*) - │ ├── proc-macro2 v1.0.36 (*) - │ ├── quote v1.0.15 (*) - │ ├── syn v1.0.86 (*) - │ ├── wasm-bindgen v0.2.78 - │ │ ├── cfg-if v1.0.0 - │ │ ├── serde v1.0.136 - │ │ │ └── serde_derive v1.0.136 (proc-macro) (*) - │ │ ├── serde_json v1.0.79 - │ │ │ ├── itoa v1.0.1 - │ │ │ ├── ryu v1.0.9 - │ │ │ └── serde v1.0.136 (*) - │ │ └── wasm-bindgen-macro v0.2.78 (proc-macro) (*) - │ ├── wasm-bindgen-futures v0.4.28 - │ │ ├── cfg-if v1.0.0 - │ │ ├── js-sys v0.3.55 - │ │ │ └── wasm-bindgen v0.2.78 (*) - │ │ └── wasm-bindgen v0.2.78 (*) - │ ├── wasm-bindgen-macro-support v0.2.78 (*) - │ └── worker-sys v0.0.4 - │ ├── cfg-if v0.1.10 - │ ├── js-sys v0.3.55 (*) - │ ├── wasm-bindgen v0.2.78 (*) - │ └── web-sys v0.3.55 - │ ├── js-sys v0.3.55 (*) - │ └── wasm-bindgen v0.2.78 (*) - └── worker-sys v0.0.4 - ├── cfg-if v0.1.10 - ├── js-sys v0.3.55 (*) - ├── wasm-bindgen v0.2.78 (*) - └── web-sys v0.3.55 (*) diff --git a/octocat-rs/src/github/client.rs b/octocat-rs/src/github/client.rs index 2670d953..44471fcb 100644 --- a/octocat-rs/src/github/client.rs +++ b/octocat-rs/src/github/client.rs @@ -13,6 +13,9 @@ use tokio::sync::mpsc; #[cfg(feature = "native")] use warp::Filter; +#[cfg(all(target_family = "wasm", feature = "workers"))] +use std::str::FromStr; + use github_rest::{ model::{ apps::events::{AppAuthorizationEvent, InstallationEvent, InstallationRepositoriesEvent}, @@ -69,6 +72,7 @@ where T: std::fmt::Debug + EventHandler> + Send + Sync, { handler: T, + // TODO: Wasm support for this field max_payload_size: u64, http_client: HttpClient, } @@ -302,13 +306,12 @@ where { #[cfg(all(target_family = "wasm", feature = "workers"))] pub async fn handle(self, mut req: worker::Request) { - let _ = self.run().await.expect("Starting application: User-defined code"); - let self_arc = Arc::new(self); let thread_self = self_arc.clone(); let thread_self_2 = self_arc.clone(); + worker::console_log!("{:#?}", &req.headers().get("X-GitHub-Event")); - let ev = serde_json::from_str(&req.headers().get("x-github-event").unwrap().unwrap()) + let ev = EventTypes::from_str(req.headers().get("X-GitHub-Event").unwrap().unwrap().as_str()) .expect("Failed to parse headers"); macro_rules! event_push { diff --git a/octocat-rs/src/github/http.rs b/octocat-rs/src/github/http.rs index 25e4e281..ae49b59f 100644 --- a/octocat-rs/src/github/http.rs +++ b/octocat-rs/src/github/http.rs @@ -5,17 +5,14 @@ use async_trait::async_trait; use reqwest::{ header, header::{HeaderMap, HeaderValue}, - Body, RequestBuilder, + RequestBuilder, }; use serde::{de::DeserializeOwned, Serialize}; #[cfg(feature = "native")] use tokio::time::Duration; #[cfg(all(target_family = "wasm", feature = "workers"))] -use worker::{CfProperties, Fetch, Headers, Method, Request, RequestInit, RequestRedirect, ResponseBody::Body}; - -#[cfg(all(target_family = "wasm", feature = "workers"))] -use std::collections::HashMap; +use worker::{Fetch, Method, Request, RequestInit}; use github_rest::{ methods::prelude::{EndPoints, Methods}, @@ -27,17 +24,6 @@ use crate::github::Authorization; const USER_AGENT_PARSE_ERROR: &str = "HttpClient: Parsing user agent"; const ACCEPT_HEADER_PARSE_ERROR: &str = "HttpClient: Parsing accept header"; -// TODO: Body field + actually use this to substitute RequestInit -// Issue with some more info on why JsValue isn't `Send`: -#[cfg(all(target_family = "wasm", feature = "workers"))] -#[derive(Default, Debug)] -pub struct RequestInitWrapper { - headers: HashMap, - method: Method, - cf: CfProperties, - redirect: RequestRedirect, -} - /// An implementer of the [`Requester`] trait. /// /// [`Requester`]: github_rest::Requester @@ -176,35 +162,31 @@ impl github_rest::Requester for HttpClient { { let path = format!("https://api.github.com{}", url.path()); - let mut req: Request = match url.method() { - Methods::Get => Request::new(path.as_str(), Method::Get).unwrap(), - Methods::Post => Request::new(path.as_str(), Method::Post).unwrap(), - Methods::Patch => Request::new(path.as_str(), Method::Patch).unwrap(), - Methods::Delete => Request::new(path.as_str(), Method::Delete).unwrap(), - Methods::Put => Request::new(path.as_str(), Method::Put).unwrap(), - }; + futures::executor::block_on(async move { + let mut init = RequestInit::new(); + init.with_method(BadWrapper::new(url.method()).into()); - let _init = RequestInit::new(); + if let Some(_query) = query { + // TODO: Query + } - if let Some(query) = query { - // TODO: Query - } + if let Some(body) = body { + init.with_body(Some(body.into())); + } - if let Some(body) = body { - // TODO: Body - } + let req = Request::new_with_init(path.as_str(), &init)?; - let mut res = Fetch::Request(req).send().await?; + let mut res = Fetch::Request(req).send().await?; - match res.status_code() { - 200..=299 => {} - _ => { - return Err(GithubRestError::ResponseError(res.status_code(), res.text().await?)); + match res.status_code() { + 200..=299 => {} + _ => { + return Err(GithubRestError::ResponseError(res.status_code(), res.text().await?)); + } } - } - let txt = res.text().await?; - Ok(txt) + Ok(res.text().await?) + }) } async fn req( @@ -221,3 +203,28 @@ impl github_rest::Requester for HttpClient { Ok(serde_json::from_str(&r)?) } } + +#[cfg(all(target_family = "wasm", feature = "workers"))] +struct BadWrapper { + pub(crate) inner: T, +} + +#[cfg(all(target_family = "wasm", feature = "workers"))] +impl BadWrapper { + fn new(inner: T) -> Self { + BadWrapper { inner } + } +} + +#[cfg(all(target_family = "wasm", feature = "workers"))] +impl From> for Method { + fn from(v: BadWrapper) -> Self { + match v.inner { + Methods::Get => Method::Get, + Methods::Post => Method::Post, + Methods::Patch => Method::Patch, + Methods::Delete => Method::Delete, + Methods::Put => Method::Put, + } + } +} diff --git a/octocat-rs/src/github/mod.rs b/octocat-rs/src/github/mod.rs index 2b47529d..5bf2de8d 100644 --- a/octocat-rs/src/github/mod.rs +++ b/octocat-rs/src/github/mod.rs @@ -14,20 +14,14 @@ pub mod util; #[cfg(test)] mod tests { - use std::sync::Arc; - + use crate::{github::ClientBuilder, handler::EventHandler, Client, Command, DefaultEventHandler}; use async_trait::async_trait; use futures::FutureExt; - use github_rest::{ model::{commits::comments::CommitComment, repositories::events::PushEvent}, GithubRestError, }; - - use crate::{ - github::{command::Command, handler::EventHandler, ClientBuilder}, - Client, DefaultEventHandler, - }; + use std::sync::Arc; #[test] fn default_everything() { diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 00000000..a25e7e06 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "nightly" + From f6aad5c15ab3ce8643856db641100887aed2fde1 Mon Sep 17 00:00:00 2001 From: Proudmuslim Date: Fri, 4 Mar 2022 16:40:22 -0800 Subject: [PATCH 08/11] wip: Cleanup, add headers to `EventHandler::raw_req` --- Cargo.lock | 2 +- examples/cloudflare/Cargo.toml | 2 +- examples/cloudflare/src/lib.rs | 6 +----- github-rest/src/builders/pull_requests.rs | 1 - github-rest/src/client.rs | 6 ++---- github-rest/src/model/pull_requests/events.rs | 1 - .../src/model/repositories/repositories.rs | 1 - octocat-rs/src/github/http.rs | 19 +++++++++++++++---- 8 files changed, 20 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 74af7361..e5a574ff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -153,8 +153,8 @@ version = "0.1.0" dependencies = [ "anyhow", "async-trait", - "cfg-if 1.0.0", "console_error_panic_hook", + "lazy_static", "octocat-rs", "serde_json", "wasm-bindgen-futures", diff --git a/examples/cloudflare/Cargo.toml b/examples/cloudflare/Cargo.toml index b6fac066..b8d43c31 100644 --- a/examples/cloudflare/Cargo.toml +++ b/examples/cloudflare/Cargo.toml @@ -11,7 +11,7 @@ crate-type = ["cdylib", "rlib"] default = ["console_error_panic_hook"] [dependencies] -cfg-if = "1.0.0" +lazy_static = "1.4" serde_json = "1" octocat-rs = { path = "../../octocat-rs", default-features = false, features = ["workers"] } worker = "0.0.9" diff --git a/examples/cloudflare/src/lib.rs b/examples/cloudflare/src/lib.rs index cdb65010..707cb9cd 100644 --- a/examples/cloudflare/src/lib.rs +++ b/examples/cloudflare/src/lib.rs @@ -3,11 +3,7 @@ use std::sync::Arc; use async_trait::async_trait; use worker::{console_log, event, Env, Request, Response, Router}; -use octocat_rs::{ - handler::EventHandler, - rest::model::{misc::events::MarketplacePurchaseEvent, repositories::events::PushEvent}, - Client, ClientBuilder, Command, -}; +use octocat_rs::{handler::EventHandler, rest::model::repositories::events::PushEvent, Client, ClientBuilder, Command}; mod utils; diff --git a/github-rest/src/builders/pull_requests.rs b/github-rest/src/builders/pull_requests.rs index 9a0b694e..28c48bfc 100644 --- a/github-rest/src/builders/pull_requests.rs +++ b/github-rest/src/builders/pull_requests.rs @@ -45,7 +45,6 @@ mod tests { #[tokio::test] async fn test_get_pulls_builder() { - // TODO: Fix the error in the model let r = GetPullsBuilder::new() .owner("microsoft") .repo("vscode") diff --git a/github-rest/src/client.rs b/github-rest/src/client.rs index 65281a43..6448a31a 100644 --- a/github-rest/src/client.rs +++ b/github-rest/src/client.rs @@ -2,13 +2,11 @@ //! own client. you can still do this though by implementing the [`Requester`] //! trait -use std::fmt::Display; -//TODO: lock this behind a feature -//TODO: Replace all Strings with T: into use async_trait::async_trait; use github_api::end_points::{EndPoints, Methods}; -use reqwest::{header, Body}; +use reqwest::header; use serde::{de::DeserializeOwned, Serialize}; +use std::fmt::Display; use crate::{GithubRestError, Requester}; diff --git a/github-rest/src/model/pull_requests/events.rs b/github-rest/src/model/pull_requests/events.rs index a6c00172..1fba4adf 100644 --- a/github-rest/src/model/pull_requests/events.rs +++ b/github-rest/src/model/pull_requests/events.rs @@ -49,7 +49,6 @@ pub mod nested { Unlocked, } - // TODO: Move this to some type of shared module as `IssueEvent` uses it #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct IssueChanges { pub title: Option, diff --git a/github-rest/src/model/repositories/repositories.rs b/github-rest/src/model/repositories/repositories.rs index 2ba481be..872ff8fb 100644 --- a/github-rest/src/model/repositories/repositories.rs +++ b/github-rest/src/model/repositories/repositories.rs @@ -145,7 +145,6 @@ pub struct CodeScanningAlert { pub url: String, pub html_url: String, pub instances: Vec, - // TODO: Find possible values pub state: String, // Don't know if it's unix millis or DateTime pub fixed_at: Option, diff --git a/octocat-rs/src/github/http.rs b/octocat-rs/src/github/http.rs index ae49b59f..8d97bbc4 100644 --- a/octocat-rs/src/github/http.rs +++ b/octocat-rs/src/github/http.rs @@ -12,7 +12,7 @@ use serde::{de::DeserializeOwned, Serialize}; use tokio::time::Duration; #[cfg(all(target_family = "wasm", feature = "workers"))] -use worker::{Fetch, Method, Request, RequestInit}; +use worker::{Fetch, Method, Request, RequestInit, Headers}; use github_rest::{ methods::prelude::{EndPoints, Methods}, @@ -160,16 +160,27 @@ impl github_rest::Requester for HttpClient { T: Serialize + ?Sized + Send + Sync, V: Into + Send, { - let path = format!("https://api.github.com{}", url.path()); + let mut path = format!("https://api.github.com{}", url.path()); + + if let Some(q) = query { + path.push_str(serde_urlencoded::to_string(q).expect("Invalid query").as_str()); + } futures::executor::block_on(async move { let mut init = RequestInit::new(); init.with_method(BadWrapper::new(url.method()).into()); - if let Some(_query) = query { - // TODO: Query + let mut headers = Headers::new(); + headers + .append("accept", "application/vnd.github.v3+json") + .expect(ACCEPT_HEADER_PARSE_ERROR); + + if let Some(ua) = &self.user_agent { + headers.append("user-agent", ua).expect(USER_AGENT_PARSE_ERROR); } + init.with_headers(headers); + if let Some(body) = body { init.with_body(Some(body.into())); } From 32fcb083ab0259e45bccf23d5804637d8160fa4e Mon Sep 17 00:00:00 2001 From: Proudmuslim Date: Sat, 5 Mar 2022 12:32:13 -0800 Subject: [PATCH 09/11] wip: Implement auth + webhook secret header support Secret header is only supported on wasm at the moment because I'm too lazy to take 5 minutes and do it --- Cargo.lock | 31 +++++++++++++++++++++++++++++++ examples/cloudflare/Cargo.toml | 1 + examples/cloudflare/src/lib.rs | 8 +++++--- octocat-rs/Cargo.toml | 5 ++++- octocat-rs/src/github/client.rs | 29 ++++++++++++++++++++++++++++- octocat-rs/src/github/handler.rs | 5 +++++ octocat-rs/src/github/http.rs | 30 ++++++++++++++++++++++++++++-- 7 files changed, 102 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e5a574ff..ad77f43d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -153,6 +153,7 @@ version = "0.1.0" dependencies = [ "anyhow", "async-trait", + "cfg-if 1.0.0", "console_error_panic_hook", "lazy_static", "octocat-rs", @@ -236,6 +237,7 @@ checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506" dependencies = [ "block-buffer 0.10.2", "crypto-common", + "subtle", ] [[package]] @@ -489,6 +491,15 @@ dependencies = [ "libc", ] +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest 0.10.3", +] + [[package]] name = "http" version = "0.2.6" @@ -777,13 +788,16 @@ version = "0.0.0" dependencies = [ "anyhow", "async-trait", + "base64", "futures", "github-api", "github-rest", + "hmac", "reqwest", "serde", "serde_json", "serde_urlencoded", + "sha2", "strum", "strum_macros", "thiserror", @@ -1218,6 +1232,17 @@ dependencies = [ "digest 0.10.3", ] +[[package]] +name = "sha2" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55deaec60f81eefe3cce0dc50bda92d6d8e88f2a27df7c5033b42afeb1ed2676" +dependencies = [ + "cfg-if 1.0.0", + "cpufeatures", + "digest 0.10.3", +] + [[package]] name = "signal-hook-registry" version = "1.4.0" @@ -1277,6 +1302,12 @@ dependencies = [ "syn", ] +[[package]] +name = "subtle" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" + [[package]] name = "syn" version = "1.0.86" diff --git a/examples/cloudflare/Cargo.toml b/examples/cloudflare/Cargo.toml index b8d43c31..9cea2e6e 100644 --- a/examples/cloudflare/Cargo.toml +++ b/examples/cloudflare/Cargo.toml @@ -15,6 +15,7 @@ lazy_static = "1.4" serde_json = "1" octocat-rs = { path = "../../octocat-rs", default-features = false, features = ["workers"] } worker = "0.0.9" +cfg-if = "1" # The `console_error_panic_hook` crate provides better debugging of panics by # logging them with `console.error`. This is great for development, but requires diff --git a/examples/cloudflare/src/lib.rs b/examples/cloudflare/src/lib.rs index 707cb9cd..1d22cd25 100644 --- a/examples/cloudflare/src/lib.rs +++ b/examples/cloudflare/src/lib.rs @@ -13,12 +13,14 @@ pub async fn main(req: Request, env: Env, _ctx: worker::Context) -> worker::Resu let router = Router::new(); let r = router - .post_async("/payload", |mut req, _| async { + .post_async("/payload", |req, _| async { // TODO: Don't construct this every time let client = ClientBuilder::new().event_handler(Handler {}).build().unwrap(); - client.handle(req).await; - Response::empty() + match client.handle(req).await { + Some((msg, code)) => Response::error(msg, code), + None => Response::empty(), + } }) .get("/worker-version", |_, ctx| { let version = ctx.var("WORKERS_RS_VERSION")?.to_string(); diff --git a/octocat-rs/Cargo.toml b/octocat-rs/Cargo.toml index 7ba0f717..e667b5d9 100644 --- a/octocat-rs/Cargo.toml +++ b/octocat-rs/Cargo.toml @@ -41,8 +41,11 @@ reqwest = { version = "^0.11.8", optional = true } strum = "0.23.0" worker = { version = "0.0.9", optional = true } serde_urlencoded = { version = "0.7.1", optional = true } +base64 = { version = "0.13.0", optional = true } +hmac = { version = "0.12.1", optional = true } +sha2 = { version = "0.10.2", optional = true } [features] default = [ "native" ] native = ["warp", "tokio", "reqwest"] -workers = ["worker", "serde_urlencoded"] +workers = ["worker", "serde_urlencoded", "base64", "hmac", "sha2"] diff --git a/octocat-rs/src/github/client.rs b/octocat-rs/src/github/client.rs index 44471fcb..b0840a39 100644 --- a/octocat-rs/src/github/client.rs +++ b/octocat-rs/src/github/client.rs @@ -13,6 +13,10 @@ use tokio::sync::mpsc; #[cfg(feature = "native")] use warp::Filter; +#[cfg(all(target_family = "wasm", feature = "workers"))] +use hmac::{Hmac, Mac}; +#[cfg(all(target_family = "wasm", feature = "workers"))] +use sha2::Sha256; #[cfg(all(target_family = "wasm", feature = "workers"))] use std::str::FromStr; @@ -49,6 +53,9 @@ use github_rest::{ use crate::github::{handler::EventHandler, util::Authorization, DefaultEventHandler, HttpClient}; +#[cfg(all(target_family = "wasm", feature = "workers"))] +type HmacSha256 = Hmac; + #[async_trait] pub trait GitHubClient: Requester + Sized { type HttpClient: Requester + Send + Sync; @@ -305,7 +312,7 @@ where T: Debug + EventHandler> + Send + Sync + 'static, { #[cfg(all(target_family = "wasm", feature = "workers"))] - pub async fn handle(self, mut req: worker::Request) { + pub async fn handle(self, mut req: worker::Request) -> Option<(&'static str, u16)> { let self_arc = Arc::new(self); let thread_self = self_arc.clone(); let thread_self_2 = self_arc.clone(); @@ -314,6 +321,24 @@ where let ev = EventTypes::from_str(req.headers().get("X-GitHub-Event").unwrap().unwrap().as_str()) .expect("Failed to parse headers"); + if let Some(secret) = self_arc.handler.listener_secret() { + match req.headers().get("X-Hub-Signature-256").unwrap() { + Some(hash) => { + if !secret.is_empty() { + let mut mac = HmacSha256::new_from_slice(secret).unwrap(); + mac.update(req.text().await.unwrap().as_bytes()); + + let result = mac.finalize().into_bytes(); + + if !result[..].eq_ignore_ascii_case(&hash.as_bytes()[..]) { + return Some(("Signatures don't match!", 400)); + } + } + } + None => return Some(("Missing X-Hub-Signature-256 header!", 401)), + } + } + macro_rules! event_push { ($f:ident, $t:ty) => { thread_self @@ -333,6 +358,8 @@ where while let Some(c) = cmd.pop() { thread_self_2.event_handler().message(c.await).await; } + + None } #[cfg(feature = "warp")] diff --git a/octocat-rs/src/github/handler.rs b/octocat-rs/src/github/handler.rs index 1de25061..101d9822 100644 --- a/octocat-rs/src/github/handler.rs +++ b/octocat-rs/src/github/handler.rs @@ -52,6 +52,11 @@ pub trait EventHandler { "/payload" } + /// The webhook secret. Defaults to none. + fn listener_secret(&self) -> Option<&[u8]> { + None + } + async fn message(&self, message: Self::Message) { {} } diff --git a/octocat-rs/src/github/http.rs b/octocat-rs/src/github/http.rs index 8d97bbc4..ee0a9e49 100644 --- a/octocat-rs/src/github/http.rs +++ b/octocat-rs/src/github/http.rs @@ -12,7 +12,11 @@ use serde::{de::DeserializeOwned, Serialize}; use tokio::time::Duration; #[cfg(all(target_family = "wasm", feature = "workers"))] -use worker::{Fetch, Method, Request, RequestInit, Headers}; +use base64::write::EncoderWriter as Base64Encoder; +#[cfg(all(target_family = "wasm", feature = "workers"))] +use std::io::Write; +#[cfg(all(target_family = "wasm", feature = "workers"))] +use worker::{Fetch, Headers, Method, Request, RequestInit}; use github_rest::{ methods::prelude::{EndPoints, Methods}, @@ -101,7 +105,7 @@ impl HttpClient { self.user_agent = Some(user_agent); } - #[cfg(feature = "default")] + #[cfg(feature = "native")] fn http_auth(&self, req: RequestBuilder) -> RequestBuilder { if let Some(auth) = &self.auth { match auth { @@ -175,6 +179,28 @@ impl github_rest::Requester for HttpClient { .append("accept", "application/vnd.github.v3+json") .expect(ACCEPT_HEADER_PARSE_ERROR); + if let Some(auth) = &self.auth { + match auth { + Authorization::PersonalToken { username, token } => { + let mut header_value = b"Basic ".to_vec(); + + { + let mut encoder = Base64Encoder::new(&mut header_value, base64::STANDARD); + + write!(encoder, "{username}:").unwrap(); + write!(encoder, "{token}").unwrap(); + } + + headers + .append( + "authorization", + std::str::from_utf8(&header_value).expect("Failed to parse header value"), + ) + .unwrap(); + } + } + } + if let Some(ua) = &self.user_agent { headers.append("user-agent", ua).expect(USER_AGENT_PARSE_ERROR); } From bfa59c513547080b9c62319ae65300735be5d67d Mon Sep 17 00:00:00 2001 From: Proudmuslim Date: Sun, 6 Mar 2022 20:07:08 -0800 Subject: [PATCH 10/11] wip: Disable `payload_size` in `Client` for wasm targets --- octocat-rs/src/github/client.rs | 13 ++++++++++++- octocat-rs/src/github/client_builder.rs | 6 ++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/octocat-rs/src/github/client.rs b/octocat-rs/src/github/client.rs index b0840a39..be9a4a55 100644 --- a/octocat-rs/src/github/client.rs +++ b/octocat-rs/src/github/client.rs @@ -79,7 +79,7 @@ where T: std::fmt::Debug + EventHandler> + Send + Sync, { handler: T, - // TODO: Wasm support for this field + #[cfg(feature = "native")] max_payload_size: u64, http_client: HttpClient, } @@ -101,6 +101,7 @@ where &self.handler } + #[cfg(feature = "native")] fn payload_size(&self) -> u64 { self.max_payload_size } @@ -421,6 +422,7 @@ where } /// Creates a new [`Client`]. + #[cfg(feature = "native")] pub fn new(handler: T, auth: Option, user_agent: Option, payload_size: Option) -> Self { Self { handler, @@ -429,6 +431,14 @@ where } } + #[cfg(all(target_family = "wasm", feature = "workers"))] + pub fn new(handler: T, auth: Option, user_agent: Option) -> Self { + Self { + handler, + http_client: HttpClient::new(auth, user_agent), + } + } + /// Updates the authorization parameter in the current [`Client`] instance. pub fn set_auth(mut self, auth: Authorization) -> Self { self.http_client.set_auth(auth); @@ -440,6 +450,7 @@ impl Default for Client { fn default() -> Client { Client { handler: DefaultEventHandler, + #[cfg(feature = "native")] max_payload_size: 1024 * 8192, http_client: HttpClient::new(None, None), } diff --git a/octocat-rs/src/github/client_builder.rs b/octocat-rs/src/github/client_builder.rs index 1f98332d..53438685 100644 --- a/octocat-rs/src/github/client_builder.rs +++ b/octocat-rs/src/github/client_builder.rs @@ -14,6 +14,7 @@ where handler: Option, auth: Option, user_agent: Option, + #[cfg(feature = "native")] payload_size: Option, } @@ -25,6 +26,7 @@ where pub fn new() -> Self { Self::default() } + /// Adds an [`EventHandler`] to the current builder. pub fn event_handler(mut self, event_handler: T) -> Self { self.handler = Some(event_handler); @@ -33,6 +35,7 @@ where /// Sets the maximum payload size that the listener can receive from GitHub /// in MiB. Default: 8. + #[cfg(feature = "native")] pub fn payload_size(mut self, size: u64) -> Self { self.payload_size = Some(size); self @@ -110,6 +113,7 @@ where self.handler.unwrap(), self.auth, self.user_agent, + #[cfg(feature = "native")] self.payload_size, )) } @@ -129,6 +133,7 @@ impl ClientBuilder { DefaultEventHandler::new(), self.auth, self.user_agent, + #[cfg(feature = "native")] self.payload_size, )) } @@ -142,6 +147,7 @@ where Self { handler: None, auth: None, + #[cfg(feature = "native")] payload_size: None, user_agent: None, } From 333a5de814b75f98424cdb578caba9692e680a0d Mon Sep 17 00:00:00 2001 From: Proudmuslim Date: Mon, 7 Mar 2022 15:17:07 -0800 Subject: [PATCH 11/11] [skip ci] Prepare for merge --- octocat-rs/src/github/client.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/octocat-rs/src/github/client.rs b/octocat-rs/src/github/client.rs index be9a4a55..67130322 100644 --- a/octocat-rs/src/github/client.rs +++ b/octocat-rs/src/github/client.rs @@ -322,6 +322,7 @@ where let ev = EventTypes::from_str(req.headers().get("X-GitHub-Event").unwrap().unwrap().as_str()) .expect("Failed to parse headers"); + // TODO: Native support for this. if let Some(secret) = self_arc.handler.listener_secret() { match req.headers().get("X-Hub-Signature-256").unwrap() { Some(hash) => {