From c227b484dc3bcda0fd987acbaa5dd5371a2a738d Mon Sep 17 00:00:00 2001 From: DragonBillow Date: Fri, 8 Sep 2023 12:12:40 +0800 Subject: [PATCH] feat: add some data struct --- .gitignore | 1 + Cargo.lock | 720 +++++++++++++++++++++++++++++++++++ Cargo.toml | 17 + src/data.rs | 6 + src/data/packages.rs | 273 +++++++++++++ src/data/packages/default.rs | 17 + src/data/packages/ignore.rs | 7 + src/data/response.rs | 56 +++ src/data/response/file.rs | 70 ++++ src/main.rs | 21 + src/request.rs | 26 ++ src/request/enums.rs | 68 ++++ src/request/flags.rs | 98 +++++ src/request/request_body.rs | 53 +++ 14 files changed, 1433 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 src/data.rs create mode 100644 src/data/packages.rs create mode 100644 src/data/packages/default.rs create mode 100644 src/data/packages/ignore.rs create mode 100644 src/data/response.rs create mode 100644 src/data/response/file.rs create mode 100644 src/main.rs create mode 100644 src/request.rs create mode 100644 src/request/enums.rs create mode 100644 src/request/flags.rs create mode 100644 src/request/request_body.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..8f98750 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,720 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "backtrace" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" +dependencies = [ + "serde", +] + +[[package]] +name = "bytes" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" + +[[package]] +name = "cc" +version = "1.0.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +dependencies = [ + "libc", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "futures-channel" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" + +[[package]] +name = "futures-sink" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" + +[[package]] +name = "futures-task" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" + +[[package]] +name = "futures-util" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "pin-utils", +] + +[[package]] +name = "gimli" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" + +[[package]] +name = "h2" +version = "0.3.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91fc23aa11be92976ef4729127f1a74adf36d8436f7816b185d18df956790833" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap 1.9.3", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "hashbrown" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" + +[[package]] +name = "hermit-abi" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" + +[[package]] +name = "http" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.0-rc.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "951dfc2e32ac02d67c90c0d65bd27009a635dc9b381a2cc7d284ab01e3a0150d" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "httparse" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "hyper" +version = "1.0.0-rc.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d280a71f348bcc670fc55b02b63c53a04ac0bf2daff2980795aeaf53edae10e6" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "tokio", + "tracing", + "want", +] + +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", +] + +[[package]] +name = "indexmap" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" +dependencies = [ + "equivalent", + "hashbrown 0.14.0", +] + +[[package]] +name = "itoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" + +[[package]] +name = "libc" +version = "0.2.147" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" + +[[package]] +name = "lock_api" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" + +[[package]] +name = "memchr" +version = "2.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c" + +[[package]] +name = "miniz_oxide" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" +dependencies = [ + "libc", + "wasi", + "windows-sys", +] + +[[package]] +name = "nix_vscode" +version = "0.1.0" +dependencies = [ + "bitflags 2.4.0", + "hyper", + "log", + "semver", + "serde", + "serde_json", + "tokio", + "toml", + "tracing", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" + +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" +dependencies = [ + "bitflags 1.3.2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" + +[[package]] +name = "ryu" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "semver" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" + +[[package]] +name = "serde" +version = "1.0.188" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.188" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.105" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "693151e1ac27563d6dbcec9dee9fbd5da8539b20fa14ad3752b2e6d363ace360" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_spanned" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96426c9936fd7a0124915f9185ea1d20aa9445cc9821142f0a73bc9207a2e186" +dependencies = [ + "serde", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" + +[[package]] +name = "socket2" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2538b18701741680e0322a2302176d3253a35388e2e62f172f64f4f16605f877" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "syn" +version = "2.0.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "718fa2415bcb8d8bd775917a1bf12a7931b6dfa890753378538118181e0cb398" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17ed6077ed6cd6c74735e21f37eb16dc3935f96878b1fe961074089cc80893f9" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys", +] + +[[package]] +name = "tokio-macros" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-util" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "806fe8c2c87eccc8b3267cbae29ed3ab2d0bd37fca70ab622e46aaa9375ddb7d" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", + "tracing", +] + +[[package]] +name = "toml" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17e963a819c331dcacd7ab957d80bc2b9a9c1e71c804826d2f283dd65306542" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.19.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8123f27e969974a3dfba720fdb560be359f57b44302d280ba72e76a74480e8a" +dependencies = [ + "indexmap 2.0.0", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] + +[[package]] +name = "tracing" +version = "0.1.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" +dependencies = [ + "cfg-if", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "try-lock" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" + +[[package]] +name = "unicode-ident" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "winnow" +version = "0.5.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c2e3184b9c4e92ad5167ca73039d0c42476302ab603e2fec4487511f38ccefc" +dependencies = [ + "memchr", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..c47a1dc --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "nix_vscode" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +serde = { version = "1.0.188", features = ["derive", "alloc", "rc"] } +serde_json = "1.0.105" +toml = "0.7.6" +hyper = { version = "1.0.0-rc.4", features = ["full"] } +tokio = { version = "1.32.0", features = ["full"] } +log = "0.4.20" +tracing = "0.1.37" +semver = "1.0.18" +bitflags = { version = "2.4.0", features = ["serde", "std"] } diff --git a/src/data.rs b/src/data.rs new file mode 100644 index 0000000..9d66755 --- /dev/null +++ b/src/data.rs @@ -0,0 +1,6 @@ +// https://github.com/microsoft/vscode/blob/d187d50a482ff80dcf74c35affb09dda1a7cd2fe/src/vs/platform/extensionManagement/common/extensionGalleryService.ts +mod packages; +mod response; + +pub use packages::*; +pub use response::*; diff --git a/src/data/packages.rs b/src/data/packages.rs new file mode 100644 index 0000000..c2a656f --- /dev/null +++ b/src/data/packages.rs @@ -0,0 +1,273 @@ +// https://github.com/lbwa/package-json-rs/blob/main/src/schema/mod.rs +mod default; +mod ignore; + +use serde::{Deserialize, Serialize}; +use std::collections::HashMap; + +/// A `package.json` is a JSON file that exists in the root of a JavaScript/Node.js project. It holds metadata relevant to the project and it's used for managing the project's dependencies, scripts, version and a whole lot more. +/// +/// `package.json` schema from [official npm documentation](https://docs.npmjs.com/cli/v8/configuring-npm/package-json), see also [json-schemas repo](https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/package.json) and [json-schemas online](https://json.schemastore.org/package) +#[derive(Serialize, Deserialize, Debug, Default)] +#[serde(rename_all = "camelCase")] +pub struct PackageJson { + /// The [name](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#name) for the npm package + pub name: String, + /// The [version](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#version) for the npm package + pub version: String, + /// The [description](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#description-1) helps people discover your package, as it's listed in `npm search`. + #[serde(skip_serializing_if = "Option::is_none")] + pub description: Option, + /// The [keywords](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#keywords) helps people discover your package as it's listed in `npm search`. + #[serde(skip_serializing_if = "Option::is_none")] + pub keywords: Option>, + /// The url to the project [homepage](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#homepage). + #[serde(skip_serializing_if = "Option::is_none")] + pub homepage: Option, + /// The url to your project's issue tracker and / or the email address to which issues should be reported. + /// These are helpful for people who encounter issues with your package. + #[serde(skip_serializing_if = "Option::is_none")] + pub bugs: Option, + /// The [license](https://spdx.org/licenses/) of the package. + #[serde(skip_serializing_if = "Option::is_none")] + pub license: Option, + /// The [author](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#people-fields-author-contributors) of the package. + #[serde(skip_serializing_if = "Option::is_none")] + pub author: Option, + /// A list of [people](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#people-fields-author-contributors) who contributed to this package. + #[serde(skip_serializing_if = "Option::is_none")] + pub contributors: Option>, + /// A list of [people](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#people-fields-author-contributors) who maintains this package. + #[serde(skip_serializing_if = "Option::is_none")] + pub maintainers: Option>, + /// Used to inform about ways to help [fund](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#funding) development of the package. + #[serde(skip_serializing_if = "Option::is_none")] + pub funding: Option>, + /// The [files](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#files) field is an array of files to include in your project. If you name a folder in the array, then it will also include the files inside that folder. + #[serde(skip_serializing_if = "Option::is_none")] + pub files: Option>, + /// The [main](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#main) field is a module ID that is the primary entry point to your program. That is, if your package is named `foo`, and a user installs it, and then does `require("foo")`, then your main module's exports object will be returned. + /// + /// This should be a module relative to the root of your package folder. + /// + /// For most modules, it makes the most sense to have a main script and often not much else. + /// + /// If main is not set it defaults to `index.js` in the package's root folder. + #[serde(default = "default::main")] + pub main: String, + /// If your module is meant to be used client-side the [browser](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#browser) field should be used instead of the [main][PackageJson::main] field. This is helpful to hint users that it might rely on primitives that aren't available in Node.js modules. (e.g. window) + #[serde(skip_serializing_if = "Option::is_none")] + pub browser: Option, + /// A lot of packages have one or more executable files that they'd like to install into the PATH. npm makes this pretty easy (in fact, it uses this feature to install the "npm" executable.) + /// + /// To use this, supply a [bin](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#bin) field in your package.json which is a map of command name to local file name. When this package is installed globally, that file will be linked where global bins go so it is available to run by name. When this package is installed as a dependency in another package, the file will be linked where it will be available to that package either directly by npm exec or by name in other scripts when invoking them via npm run-script. + #[serde(skip_serializing_if = "Option::is_none")] + pub bin: Option, + /// Specify either a single file or an array of filenames to put in place for the man program to find. + /// + /// If only a single file is provided, then it's installed such that it is the result from `man `, regardless of its actual filename. + #[serde(skip_serializing_if = "Option::is_none")] + pub man: Option, + /// [The CommonJS Packages spec](http://wiki.commonjs.org/wiki/Packages/1.0) details a few ways that you can indicate the structure of your package using a directories object. If you look at npm's package.json, you'll see that it has directories for doc, lib, and man. + #[serde(skip_serializing_if = "Option::is_none")] + pub directories: Option, + /// Specify the place where your code lives. This is helpful for people who want to contribute. If the git repo is on GitHub, then the npm docs command will be able to find you. + #[serde(skip_serializing_if = "Option::is_none")] + pub repository: Option, + /// A dictionary containing script commands that are run at various times in the lifecycle of your package. The key is the lifecycle event, and the value is the command to run at that point. + #[serde(default = "default::scripts")] + #[serde(skip_serializing_if = "ignore::ignore_scripts")] + pub scripts: HashMap, + /// A [config](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#config) object can be used to set configuration parameters used in package scripts that persist across upgrades. + #[serde(skip_serializing_if = "Option::is_none")] + pub config: Option>, + /// [Dependencies](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#dependencies) are specified in a simple object that maps a package name to a version range. The version range is a string which has one or more space-separated descriptors. Dependencies can also be identified with a tarball or git URL. + /// + /// Please do not put test harnesses or transpilers or other "development" time tools in your dependencies object. See [devDependencies](PackageJson::dev_dependencies). + #[serde(skip_serializing_if = "Option::is_none")] + pub dependencies: Option, + /// If someone is planning on downloading and using your module in their program, then they probably don't want or need to download and build the external test or documentation framework that you use. + /// + /// In this case, it's best to map these additional items in a [devDependencies](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#devdependencies) object. + #[serde(skip_serializing_if = "Option::is_none")] + pub dev_dependencies: Option, + /// In some cases, you want to express the compatibility of your package with a host tool or library, while not necessarily doing a require of this host. This is usually referred to as a plugin. Notably, your module may be exposing a specific interface, expected and specified by the host documentation. + #[serde(skip_serializing_if = "Option::is_none")] + pub peer_dependencies: Option, + /// When a user installs your package, npm will emit warnings if packages specified in peerDependencies are not already installed. The [peerDependenciesMeta](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#peerdependenciesmeta) field serves to provide npm more information on how your [peer dependencies][PackageJson::peer_dependencies] are to be used. Specifically, it allows peer dependencies to be marked as optional. + #[serde(skip_serializing_if = "Option::is_none")] + pub peer_dependencies_meta: Option>>, + /// An array of package names that will be bundled when publishing the package. + #[serde(skip_serializing_if = "Option::is_none")] + pub bundled_dependencies: Option>, + /// If a dependency can be used, but you would like npm to proceed if it cannot be found or fails to install, then you may put it in the [optionalDependencies](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#optionaldependencies) object. + #[serde(skip_serializing_if = "Option::is_none")] + pub optional_dependencies: Option, + /// If you need to make specific changes to dependencies of your dependencies, for example replacing the version of a dependency with a known security issue, replacing an existing dependency with a fork, or making sure that the same version of a package is used everywhere, then you may add an override. + /// + /// [Overrides](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#overrides) provide a way to replace a package in your dependency tree with another version, or another package entirely. These changes can be scoped as specific or as vague as desired. + #[serde(skip_serializing_if = "Option::is_none")] + pub overrides: Option>, + /// Specify which [engines](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#engines) your module will run on. + #[serde(skip_serializing_if = "Option::is_none")] + pub engines: Option>, + /// Specify which [operating systems](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#os) your module will run on. + #[serde(skip_serializing_if = "Option::is_none")] + pub os: Option>, + /// Specify which [cpu](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#cpu) your module will run on. + #[serde(skip_serializing_if = "Option::is_none")] + pub cpu: Option>, + /// If set to true, then npm will refuse to publish it. + #[serde(default)] + pub private: bool, + /// This is a set of [config](https://docs.npmjs.com/cli/v8/using-npm/config) values that will be used at publish-time. It's + /// especially handy if you want to set the tag, registry or access, so that + /// you can ensure that a given package is not tagged with "latest", published + /// to the global public registry or that a scoped module is private by default. + #[serde(skip_serializing_if = "Option::is_none")] + pub publish_config: Option>, + /// The optional [workspace](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#workspaces)s + /// field is an array of file patterns that describes locations within the local + /// file system that the install client should look up to find each workspace + /// that needs to be symlinked to the top level node_modules folder. + #[serde(skip_serializing_if = "Option::is_none")] + pub workspaces: Option>, + /// When set to "module", the type field allows a package to specify all .js files within are ES modules. If the "type" field is omitted or set to "commonjs", all .js files are treated as CommonJS. + #[serde(default = "default::r#type")] + pub r#type: String, + /// Set the [types](https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html#including-declarations-in-your-npm-package) property to point to your bundled declaration file. This is useful for packages that have a large number of types, but only a few of which are used. + #[serde(skip_serializing_if = "Option::is_none")] + pub types: Option, + /// Note that the [typings](https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html#including-declarations-in-your-npm-package) field is synonymous with "types", and could be used as well. + #[serde(skip_serializing_if = "Option::is_none")] + pub typings: Option, + + /// Any unknown fields should be placed in `unknown` field. + #[serde(flatten)] + pub unknowns: HashMap, +} + +/// see [PackageJson::bugs](PackageJson::bugs) +#[derive(Serialize, Deserialize, Debug)] +pub enum PackageBugs { + Url(String), + Record(PackageBugsRecord), +} + +/// see [PackageJson::bugs](PackageJson::bugs) +#[derive(Serialize, Deserialize, Debug, Default)] +pub struct PackageBugsRecord { + pub url: String, + pub email: String, +} + +#[derive(Serialize, Deserialize, Debug)] +pub enum PackagePeople { + Literal(String), + Record(PackagePeopleRecord), +} + +#[derive(Serialize, Deserialize, Debug, Default)] +pub struct PackagePeopleRecord { + pub name: String, + pub email: Option, + pub url: Option, +} + +/// see [PackageJson::funding](PackageJson::funding) +#[derive(Serialize, Deserialize, Debug)] +pub enum PackageFunding { + Url(String), + Record(PackageFundingRecord), + Slice(Vec), +} + +/// see [PackageJson::funding](PackageJson::funding) +#[derive(Serialize, Deserialize, Debug, Default)] +pub struct PackageFundingRecord { + pub r#type: String, + pub url: String, +} + +/// see [PackageJson::bin](PackageJson::bin) +#[derive(Serialize, Deserialize, Debug)] +pub enum PackageBin { + Literal(String), + Record(HashMap), +} + +/// see [PackageJson::man](PackageJson::man) +#[derive(Serialize, Deserialize, Debug)] +pub enum PackageMan { + Literal(String), + Slice(Vec), +} + +/// see [PackageJson::directories](PackageJson::directories) +#[derive(Serialize, Deserialize, Debug, Default)] +pub struct PackageDirectories { + pub bin: Option, + pub man: Option, +} + +/// see [PackageJson::repository](PackageJson::repository) +#[derive(Serialize, Deserialize, Debug, Default)] +pub struct PackageRepository { + pub r#type: String, + pub url: String, +} + +pub type PackageDependencies = HashMap; + +#[test] +fn test_spec_fields() { + use self::default; + let package_json_raw = r#" + { + "name": "test", + "version": "1.0.0", + "description": "test", + "devDependencies": { + "typescript": "*" + } + } + "#; + + let json = serde_json::from_str::(package_json_raw).unwrap(); + // test actual values + assert_eq!(json.name, "test"); + assert_eq!(json.version, "1.0.0"); + assert_eq!(json.description, Some("test".to_owned())); + assert_eq!(json.license, None); + assert_eq!(json.dependencies, None); + assert_eq!( + json.dev_dependencies, + Some(HashMap::from([("typescript".to_owned(), "*".to_owned())])) + ); + assert_eq!(json.bundled_dependencies, None); + + // test default values + assert!(!json.private, "json.private should be false"); + assert_eq!(json.scripts, default::scripts()); + assert_eq!(json.main, default::main()); + assert_eq!(json.r#type, default::r#type()); +} + +#[test] +fn test_unknown_fields() { + let json = r#" + { + "name": "test", + "version": "1.0.0", + "description": "test", + "foo": "bar", + "baz": "qux" + }"#; + + let package_json = serde_json::from_str::(json).unwrap(); + assert_eq!(package_json.unknowns.len(), 2); + assert!(package_json.unknowns.get("foo").is_some()); + assert!(package_json.unknowns.get("baz").is_some()); + assert_eq!(package_json.unknowns.get("foo").unwrap(), &"bar".to_owned()); + assert_eq!(package_json.unknowns.get("baz").unwrap(), &"qux".to_owned()); +} diff --git a/src/data/packages/default.rs b/src/data/packages/default.rs new file mode 100644 index 0000000..cf10d68 --- /dev/null +++ b/src/data/packages/default.rs @@ -0,0 +1,17 @@ +use std::collections::HashMap; + +pub fn main() -> String { + String::from("index.js") +} + +/// see https://docs.npmjs.com/cli/v8/configuring-npm/package-json#default-values +pub fn scripts() -> HashMap { + HashMap::from([ + ("start".to_owned(), "node server.js".to_owned()), + ("install".to_owned(), "node-gyp rebuild".to_owned()), + ]) +} + +pub fn r#type() -> String { + String::from("commonjs") +} diff --git a/src/data/packages/ignore.rs b/src/data/packages/ignore.rs new file mode 100644 index 0000000..6a26e36 --- /dev/null +++ b/src/data/packages/ignore.rs @@ -0,0 +1,7 @@ +use std::collections::HashMap; + +pub fn ignore_scripts(data: &HashMap) -> bool { + let default_value = super::default::scripts(); + data.keys() + .all(|item| default_value.get(item) == data.get(item)) +} diff --git a/src/data/response.rs b/src/data/response.rs new file mode 100644 index 0000000..120ac34 --- /dev/null +++ b/src/data/response.rs @@ -0,0 +1,56 @@ +mod file; +use serde::{Deserialize, Serialize}; + +use self::file::IRawGalleryExtensionVersion; + +#[derive(Debug, Default, Serialize, Deserialize)] +#[serde(default)] +#[serde(rename_all = "camelCase")] +pub struct IRawGalleryQueryResult { + pub results: Vec, +} + +#[derive(Debug, Default, Serialize, Deserialize)] +#[serde(default)] +#[serde(rename_all = "camelCase")] +pub struct IRawGalleryExtensionStatistics { + pub statistic_name: String, + pub value: f64, +} + +#[derive(Debug, Default, Serialize, Deserialize)] +#[serde(default)] +#[serde(rename_all = "camelCase")] +pub struct IRawGalleryExtensionPublisher { + pub display_name: String, + pub publisher_id: String, + pub publisher_name: String, + pub domain: Option, + pub is_domain_verified: bool, +} + +#[derive(Debug, Default, Serialize, Deserialize)] +#[serde(default)] +#[serde(rename_all = "camelCase")] +pub struct IRawGalleryExtension { + pub extension_id: String, + pub extension_name: String, + pub display_name: String, + pub short_description: Option, + pub publisher: IRawGalleryExtensionPublisher, + pub versions: Vec, + pub statistics: Vec, + pub tags: Option, + pub release_date: String, + pub published_date: String, + pub last_updated: String, + pub categories: Option>, + pub flags: String, +} + +#[derive(Debug, Default, Serialize, Deserialize)] +#[serde(default)] +#[serde(rename_all = "camelCase")] +pub struct IRawGalleryExtensionsResult { + pub extensions: Vec, +} diff --git a/src/data/response/file.rs b/src/data/response/file.rs new file mode 100644 index 0000000..a72cc01 --- /dev/null +++ b/src/data/response/file.rs @@ -0,0 +1,70 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Default, Serialize, Deserialize)] +#[serde(default)] +#[serde(rename_all = "camelCase")] +pub struct IRawGalleryExtensionVersion { + pub version: String, + pub last_updated: String, + pub asset_uri: String, + pub fallback_asset_uri: String, + pub files: Vec, + pub properties: Vec, + pub target_platform: String, +} + +#[derive(Debug, Default, Serialize, Deserialize)] +#[serde(default)] +#[serde(rename_all = "camelCase")] +pub struct IRawGalleryExtensionProperty { + key: String, + value: String, +} + +#[derive(Debug, Default, Serialize, Deserialize)] +#[serde(default)] +#[serde(rename_all = "camelCase")] +pub struct IRawGalleryExtensionFile { + pub asset_type: String, + pub source: String, +} + +pub enum AssetType { + Icon, + Details, + Changelog, + Manifest, + Vsix, + License, + Repository, + Signature, +} + +impl ToString for AssetType { + #[rustfmt::skip] + fn to_string(&self) -> String { + match self { + Self::Icon=> "Microsoft.VisualStudio.Services.Icons.Default".into(), + Self::Details=> "Microsoft.VisualStudio.Services.Content.Details".into(), + Self::Changelog=> "Microsoft.VisualStudio.Services.Content.Changelog".into(), + Self::Manifest=> "Microsoft.VisualStudio.Code.Manifest".into(), + Self::Vsix=> "Microsoft.VisualStudio.Services.VSIXPackage".into(), + Self::License=> "Microsoft.VisualStudio.Services.Content.License".into(), + Self::Repository=> "Microsoft.VisualStudio.Services.Links.Source".into(), + Self::Signature=> "Microsoft.VisualStudio.Services.VsixSignature".into() + } + } +} + +impl IRawGalleryExtensionVersion { + pub fn get_file(&self, file_kind: AssetType) -> Option<&IRawGalleryExtensionFile> { + match self + .files + .iter() + .position(|item| item.asset_type == file_kind.to_string()) + { + Some(idx) => Some(&self.files[idx]), + None => None, + } + } +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..67edd10 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,21 @@ +#![allow(dead_code)] +#![allow(unused_variables)] + +pub(crate) mod data; +pub(crate) mod request; + +#[tokio::main] +async fn main() { + let obj: data::IRawGalleryQueryResult = + serde_json::from_str(include_str!("../vscode.json")).unwrap(); + let obj = &obj.results[0]; + obj.extensions + .iter() + .filter(|item| { + item.publisher.publisher_name == "ms-python" && item.extension_name == "python" + }) + .for_each(|item| { + println!("{item:?}"); + }); + println!("Hello, world!"); +} diff --git a/src/request.rs b/src/request.rs new file mode 100644 index 0000000..8394943 --- /dev/null +++ b/src/request.rs @@ -0,0 +1,26 @@ +mod enums; +mod flags; +mod request_body; + +pub use enums::*; +pub use flags::*; +pub use request_body::*; + +// pub fn create_request_body(flags: u32, page_number: u64, page_size: u64) -> String { +// let obj = RequestBody { +// filters: vec![IQueryState { +// criteria: vec![ICriterium { +// filter_type: FilterType::TARGET, +// value: "Microsoft.VisualStudio.Code".into(), +// }], +// page_number, +// page_size, +// sort_by: SortBy, +// sort_order: 0, +// }], +// asset_types: vec![], +// flags, +// }; +// +// serde_json::to_string(&obj).unwrap() +// } diff --git a/src/request/enums.rs b/src/request/enums.rs new file mode 100644 index 0000000..fa55a84 --- /dev/null +++ b/src/request/enums.rs @@ -0,0 +1,68 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Serialize, Deserialize)] +pub struct FilterType(u8); + +impl Default for FilterType { + fn default() -> Self { + Self::TAG + } +} + +impl FilterType { + pub const TAG: Self = Self(1); + pub const EXTENSION_ID: Self = Self(4); + pub const CATEGORY: Self = Self(5); + pub const EXTENSION_NAME: Self = Self(7); + pub const TARGET: Self = Self(8); + pub const FEATURED: Self = Self(9); + pub const SEARCH_TEXT: Self = Self(10); + pub const EXCLUDE_WITH_FLAGS: Self = Self(12); +} + +pub enum PropertyType { + Dependency, + ExtensionPack, + Engine, + PreRelease, + LocalizedLanguages, + WebExtension, + SponsorLink, +} + +impl ToString for PropertyType { + fn to_string(&self) -> String { + match self { + Self::Dependency => "Microsoft.VisualStudio.Code.ExtensionDependencies".into(), + Self::ExtensionPack => "Microsoft.VisualStudio.Code.ExtensionPack".into(), + Self::Engine => "Microsoft.VisualStudio.Code.Engine".into(), + Self::PreRelease => "Microsoft.VisualStudio.Code.PreRelease".into(), + Self::LocalizedLanguages => "Microsoft.VisualStudio.Code.LocalizedLanguages".into(), + Self::WebExtension => "Microsoft.VisualStudio.Code.WebExtension".into(), + Self::SponsorLink => "Microsoft.VisualStudio.Code.SponsorLink".into(), + } + } +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct SortOrder(u8); + +impl SortOrder { + pub const DEFAULT: Self = Self(0); + pub const ASCENDING: Self = Self(1); + pub const DESCENDING: Self = Self(2); +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct SortBy(u8); + +impl SortBy { + pub const NONE_OR_RELEVANCE: Self = Self(0); + pub const LAST_UPDATED_DATE: Self = Self(1); + pub const TITLE: Self = Self(2); + pub const PUBLISHER_NAME: Self = Self(3); + pub const INSTALL_COUNT: Self = Self(4); + pub const PUBLISHED_DATE: Self = Self(10); + pub const AVERAGE_RATING: Self = Self(6); + pub const WEIGHTED_RATING: Self = Self(12); +} diff --git a/src/request/flags.rs b/src/request/flags.rs new file mode 100644 index 0000000..81c1f78 --- /dev/null +++ b/src/request/flags.rs @@ -0,0 +1,98 @@ +use bitflags::bitflags; +use serde::{Deserialize, Serialize}; + +bitflags! { + #[repr(transparent)] + #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] + pub struct RequestFlags: u32 { + /// + /// None is used to retrieve only the basic extension details. + /// + const None = 0x0; + + /// + /// IncludeVersions will return version information for extensions returned + /// + const IncludeVersions = 0x1; + + /// + /// IncludeFiles will return information about which files were found + /// within the extension that were stored independent of the manifest. + /// When asking for files, versions will be included as well since files + /// are returned as a property of the versions. + /// These files can be retrieved using the path to the file without + /// requiring the entire manifest be downloaded. + /// + const include_files = 0x2; + + /// + ///Include the Categories and Tags that were added to the extension definition. + /// + const include_category_and_tags = 0x4; + + /// + ///Include the details about which accounts the extension has been shared + ///with if the extension is a private extension. + /// + const include_shared_accounts = 0x8; + + /// + ///Include properties associated with versions of the extension + /// + const include_version_properties = 0x10; + + /// + ///Excluding non-validated extensions will remove any extension versions that + ///either are in the process of being validated or have failed validation. + /// + const exclude_non_validated = 0x20; + + /// + ///Include the set of installation targets the extension has requested. + /// + const include_installation_targets = 0x40; + + /// + ///Include the base uri for assets of this extension + /// + const include_asset_uri = 0x80; + + /// + ///Include the statistics associated with this extension + /// + const include_statistics = 0x100; + + /// + ///When retrieving versions from a query, only include the latest + ///version of the extensions that matched. This is useful when the + ///caller doesn't need all the published versions. It will save a + ///significant size in the returned payload. + /// + const include_latest_version_only = 0x200; + + /// + ///This flag switches the asset uri to use GetAssetByName instead of CDN + ///When this is used, values of base asset uri and base asset uri fallback are switched + ///When this is used, source of asset files are pointed to Gallery service always even if CDN is available + /// + const unpublished = 0x1000; + + /// + ///Include the details if an extension is in conflict list or not + /// + const includeNameConflictInfo = 0x8000; + } +} + +impl Default for RequestFlags { + fn default() -> Self { + Self::IncludeVersions + | Self::include_files + | Self::include_category_and_tags + | Self::include_shared_accounts + | Self::include_version_properties + | Self::include_installation_targets + | Self::include_asset_uri + | Self::include_statistics + } +} diff --git a/src/request/request_body.rs b/src/request/request_body.rs new file mode 100644 index 0000000..032c0dc --- /dev/null +++ b/src/request/request_body.rs @@ -0,0 +1,53 @@ +use serde::{Deserialize, Serialize}; + +use super::*; + +#[derive(Debug, Default, Serialize, Deserialize)] +#[serde(default)] +#[serde(rename_all = "camelCase")] +pub struct ICriterium { + pub filter_type: FilterType, + pub value: String, +} + +#[derive(Debug, Serialize, Deserialize)] +#[serde(default)] +#[serde(rename_all = "camelCase")] +pub struct IQueryState { + pub page_number: u64, + pub page_size: u64, + pub sort_by: SortBy, + pub sort_order: SortOrder, + pub flags: RequestFlags, + pub criteria: Vec, + pub asset_types: Vec, + pub source: String, +} + +impl IQueryState { + pub const DEFAULT_PAGE_SIZE: u64 = 10; +} + +impl Default for IQueryState { + fn default() -> Self { + Self { + page_number: 1, + page_size: Self::DEFAULT_PAGE_SIZE, + sort_by: SortBy::NONE_OR_RELEVANCE, + sort_order: SortOrder::DEFAULT, + flags: RequestFlags::None, + criteria: Default::default(), + asset_types: Default::default(), + source: Default::default(), + } + } +} + +#[derive(Debug, Default, Serialize, Deserialize)] +#[serde(default)] +#[serde(rename_all = "camelCase")] +pub struct Query { + pub filters: Vec, + pub asset_types: Vec, + pub flags: u32, +}