diff --git a/.github/workflows/rust_on_release.yml b/.github/workflows/rust_on_release.yml new file mode 100644 index 0000000000..5594cc08bb --- /dev/null +++ b/.github/workflows/rust_on_release.yml @@ -0,0 +1,19 @@ +name: Publish rust-client to crates.io on release +on: + push: + tags: + - "v*" + workflow_dispatch: + +jobs: + build_rust_and_publish_to_crates_io: + runs-on: ubicloud-standard-8 + steps: + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v20 + with: + extra_nix_config: | + experimental-features = nix-command flakes + - run: cd rust-client && nix develop ../ --command ./dev.nu --check --publish + env: + CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }} diff --git a/rust-client/.gitignore b/rust-client/.gitignore new file mode 100644 index 0000000000..4924b1576c --- /dev/null +++ b/rust-client/.gitignore @@ -0,0 +1,3 @@ +windmill-api/ +windmill_api/ +api/ diff --git a/rust-client/Cargo.lock b/rust-client/Cargo.lock new file mode 100644 index 0000000000..03d1d4594a --- /dev/null +++ b/rust-client/Cargo.lock @@ -0,0 +1,1821 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "addr2line" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" + +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anyhow" +version = "1.0.98" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487" + +[[package]] +name = "autocfg" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" + +[[package]] +name = "backtrace" +version = "0.3.75" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6806a6321ec58106fea15becdad98371e28d92ccbc7c8f1b3b6dd724fe8f1002" +dependencies = [ + "addr2line", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", + "windows-targets", +] + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" + +[[package]] +name = "bumpalo" +version = "3.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf" + +[[package]] +name = "bytes" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" + +[[package]] +name = "cc" +version = "1.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0fc897dc1e865cc67c0e05a836d9d3f1df3cbe442aa4a9473b18e12624a4951" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + +[[package]] +name = "chrono" +version = "0.4.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c469d952047f47f91b68d1cba3f10d63c11d73e4636f24f08daf0278abf01c4d" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "num-traits", + "serde", + "windows-link", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "darling" +version = "0.20.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc7f46116c46ff9ab3eb1597a45688b6715c6e628b5c133e288e709a29bcb4ee" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d00b9596d185e565c2207a0b01f8bd1a135483d02d9b7b0a54b11da8d53412e" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.20.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead" +dependencies = [ + "darling_core", + "quote", + "syn", +] + +[[package]] +name = "deranged" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c9e6a11ca8224451684bc0d7d5a7adbf8f2fd6887261a1cfc3c0432f9d4068e" +dependencies = [ + "powerfmt", + "serde", +] + +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[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.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" + +[[package]] +name = "futures-executor" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" + +[[package]] +name = "futures-macro" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" + +[[package]] +name = "futures-task" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" + +[[package]] +name = "futures-util" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "getrandom" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi 0.11.0+wasi-snapshot-preview1", + "wasm-bindgen", +] + +[[package]] +name = "getrandom" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "r-efi", + "wasi 0.14.2+wasi-0.2.4", + "wasm-bindgen", +] + +[[package]] +name = "gimli" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "hashbrown" +version = "0.15.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84b26c544d002229e640969970a2e74021aadf6e2f96372b9c58eff97de08eb3" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "http" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4a85d31aea989eead29a3aaf9e1115a180df8282431156e533de47660892565" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "hyper" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc2b571658e38e0c01b1fdca3bbbe93c00d3d71693ff2770043f8c29bc7d6f80" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03a01595e11bdcec50946522c32dde3fc6914743000a68b93000965f2f02406d" +dependencies = [ + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", + "webpki-roots", +] + +[[package]] +name = "hyper-util" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1c293b6b3d21eca78250dc7dbebd6b9210ec5530e038cbfe0661b5c47ab06e8" +dependencies = [ + "base64", + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "http", + "http-body", + "hyper", + "ipnet", + "libc", + "percent-encoding", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c919e5debc312ad217002b8048a17b7d83f80703865bbfcfebb0458b0b27d8" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "icu_collections" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "200072f5d0e3614556f94a9930d5dc3e0662a652823904c3a75dc3b0af7fee47" +dependencies = [ + "displaydoc", + "potential_utf", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0cde2700ccaed3872079a65fb1a78f6c0a36c91570f28755dda67bc8f7d9f00a" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "436880e8e18df4d7bbc06d58432329d6458cc84531f7ac5f024e93deadb37979" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00210d6893afc98edb752b664b8890f0ef174c8adbb8d0be9710fa66fbbf72d3" + +[[package]] +name = "icu_properties" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "016c619c1eeb94efb86809b015c58f479963de65bdb6253345c1a1276f22e32b" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "potential_utf", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "298459143998310acd25ffe6810ed544932242d3f07083eee1084d83a71bd632" + +[[package]] +name = "icu_provider" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03c80da27b5f4187909049ee2d72f276f0d9f99a42c306bd0131ecfe04d8e5af" +dependencies = [ + "displaydoc", + "icu_locale_core", + "stable_deref_trait", + "tinystr", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "idna" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[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", + "serde", +] + +[[package]] +name = "indexmap" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e" +dependencies = [ + "equivalent", + "hashbrown 0.15.3", + "serde", +] + +[[package]] +name = "ipnet" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" + +[[package]] +name = "iri-string" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbc5ebe9c3a1a7a5127f920a418f7585e9e758e911d0466ed004f393b0e380b2" +dependencies = [ + "memchr", + "serde", +] + +[[package]] +name = "itoa" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" + +[[package]] +name = "js-sys" +version = "0.3.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.172" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" + +[[package]] +name = "litemap" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "241eaef5fd12c88705a01fc1066c48c4b36e0dd4377dcdc7ec3942cea7a69956" + +[[package]] +name = "log" +version = "0.4.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" + +[[package]] +name = "lru-slab" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mime_guess" +version = "2.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e" +dependencies = [ + "mime", + "unicase", +] + +[[package]] +name = "miniz_oxide" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3be647b768db090acb35d5ec5db2b0e1f1de11133ca123b9eacf5137868f892a" +dependencies = [ + "adler2", +] + +[[package]] +name = "mio" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78bed444cc8a2160f01cbcf811ef18cac863ad68ae8ca62092e8db51d51c761c" +dependencies = [ + "libc", + "wasi 0.11.0+wasi-snapshot-preview1", + "windows-sys 0.59.0", +] + +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "object" +version = "0.36.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "pin-project-lite" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "potential_utf" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5a7c30837279ca13e7c867e9e40053bc68740f988cb07f7ca6df43cc734b585" +dependencies = [ + "zerovec", +] + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro2" +version = "1.0.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quinn" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "626214629cda6781b6dc1d316ba307189c85ba657213ce642d9c77670f8202c8" +dependencies = [ + "bytes", + "cfg_aliases", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-proto" +version = "0.11.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49df843a9161c85bb8aae55f101bc0bac8bcafd637a620d9122fd7e0b2f7422e" +dependencies = [ + "bytes", + "getrandom 0.3.3", + "lru-slab", + "rand", + "ring", + "rustc-hash", + "rustls", + "rustls-pki-types", + "slab", + "thiserror", + "tinyvec", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-udp" +version = "0.5.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee4e529991f949c5e25755532370b8af5d114acae52326361d68d47af64aa842" +dependencies = [ + "cfg_aliases", + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + +[[package]] +name = "quote" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "5.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5" + +[[package]] +name = "rand" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fbfd9d094a40bf3ae768db9361049ace4c0e04a4fd6b359518bd7b73a73dd97" +dependencies = [ + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" +dependencies = [ + "getrandom 0.3.3", +] + +[[package]] +name = "reqwest" +version = "0.12.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2f8e5513d63f2e5b386eb5106dc67eaf3f84e95258e210489136b8b92ad6119" +dependencies = [ + "base64", + "bytes", + "futures-core", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "mime_guess", + "once_cell", + "percent-encoding", + "pin-project-lite", + "quinn", + "rustls", + "rustls-pki-types", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tokio-rustls", + "tower", + "tower-http", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "webpki-roots", +] + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.16", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustc-hash" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" + +[[package]] +name = "rustls" +version = "0.23.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "730944ca083c1c233a75c09f199e973ca499344a2b7ba9e755c457e86fb4a321" +dependencies = [ + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pki-types" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "229a4a4c221013e7e1f1a043678c5cc39fe5171437c88fb47151a21e6f5b5c79" +dependencies = [ + "web-time", + "zeroize", +] + +[[package]] +name = "rustls-webpki" +version = "0.103.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4a72fe2bcf7a6ac6fd7d0b9e5cb68aeb7d4c0a0271730218b3e92d43b4eb435" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "rustversion" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a0d197bd2c9dc6e53b84da9556a69ba4cdfab8619eb41a8bd1cc2027a0f6b1d" + +[[package]] +name = "ryu" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" + +[[package]] +name = "serde" +version = "1.0.219" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.219" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.140" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_repr" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "175ee3e80ae9982737ca543e96133087cbd9a485eecc3bc4de9c1a37b47ea59c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_with" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6b6f7f2fcb69f747921f79f3926bd1e203fce4fef62c268dd3abfb6d86029aa" +dependencies = [ + "base64", + "chrono", + "hex", + "indexmap 1.9.3", + "indexmap 2.9.0", + "serde", + "serde_derive", + "serde_json", + "serde_with_macros", + "time", +] + +[[package]] +name = "serde_with_macros" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d00caa5193a3c8362ac2b73be6b9e768aa5a4b2f721d8f4b339600c3cb51f8e" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_yaml" +version = "0.9.34+deprecated" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" +dependencies = [ + "indexmap 2.9.0", + "itoa", + "ryu", + "serde", + "unsafe-libyaml", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[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.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8917285742e9f3e1683f0a9c4e6b57960b7314d0b08d30d1ecd426713ee2eee9" + +[[package]] +name = "socket2" +version = "0.5.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e22376abed350d73dd1cd119b57ffccad95b4e585a7cda43e286245ce23c0678" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.101" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" +dependencies = [ + "futures-core", +] + +[[package]] +name = "synstructure" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thiserror" +version = "2.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "time" +version = "0.3.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7619e19bc266e0f9c5e6686659d394bc57973859340060a69221e57dbc0c40" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9e9a38711f559d9e3ce1cdb06dd7c5b8ea546bc90052da6d06bb76da74bb07c" + +[[package]] +name = "time-macros" +version = "0.2.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3526739392ec93fd8b359c8e98514cb3e8e021beb4e5f597b00a0221f8ed8a49" +dependencies = [ + "num-conv", + "time-core", +] + +[[package]] +name = "tinystr" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d4f6d1145dcb577acf783d4e601bc1d76a13337bb54e6233add580b07344c8b" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tinyvec" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09b3661f17e86524eccd4371ab0429194e0d7c008abb45f7a7495b1719463c71" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.45.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75ef51a33ef1da925cea3e4eb122833cb377c61439ca401b770f54902b806779" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "pin-project-lite", + "socket2", + "tokio-macros", + "windows-sys 0.52.0", +] + +[[package]] +name = "tokio-macros" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e727b36a1a0e8b74c376ac2211e40c2c8af09fb4013c60d910495810f008e9b" +dependencies = [ + "rustls", + "tokio", +] + +[[package]] +name = "tower" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d039ad9159c98b70ecfd540b2573b97f7f52c3e8d9f8ad57a24b916a536975f9" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-http" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adc82fd73de2a9722ac5da747f12383d2bfdb93591ee6c58486e0097890f05f2" +dependencies = [ + "bitflags", + "bytes", + "futures-util", + "http", + "http-body", + "iri-string", + "pin-project-lite", + "tower", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c" +dependencies = [ + "once_cell", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicase" +version = "2.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75b844d17643ee918803943289730bec8aac480150456169e647ed0b576ba539" + +[[package]] +name = "unicode-ident" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" + +[[package]] +name = "unsafe-libyaml" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32f8b686cadd1473f4bd0117a5d28d36b1ade384ea9b5069a1c40aefed7fda60" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] +name = "uuid" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3cf4199d1e5d15ddd86a694e4d0dffa9c323ce759fea589f00fef9d81cc1931d" +dependencies = [ + "getrandom 0.3.3", + "js-sys", + "serde", + "wasm-bindgen", +] + +[[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 = "wasi" +version = "0.14.2+wasi-0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3" +dependencies = [ + "wit-bindgen-rt", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" +dependencies = [ + "bumpalo", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "555d470ec0bc3bb57890405e5d4322cc9ea83cebb085523ced7be4144dac1e61" +dependencies = [ + "cfg-if", + "js-sys", + "once_cell", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "web-sys" +version = "0.3.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33b6dd2ef9186f1f2072e409e99cd22a975331a6b3591b12c764e0e55c60d5d2" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki-roots" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2853738d1cc4f2da3a225c18ec6c3721abb31961096e9dbf5ab35fa88b19cfdb" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "windmill-api" +version = "1.496.3" +dependencies = [ + "reqwest", + "serde", + "serde_json", + "serde_repr", + "serde_with", + "url", + "uuid", +] + +[[package]] +name = "windows-core" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.59.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-link" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76840935b766e1b0a05c0066835fb9ec80071d4c09a16f6bd5f7e655e3c14c38" + +[[package]] +name = "windows-result" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "wit-bindgen-rt" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1" +dependencies = [ + "bitflags", +] + +[[package]] +name = "wmill" +version = "1.496.3" +dependencies = [ + "anyhow", + "futures", + "once_cell", + "serde", + "serde_json", + "serde_yaml", + "thiserror", + "tokio", + "uuid", + "windmill-api", +] + +[[package]] +name = "writeable" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea2f10b9bb0928dfb1b42b65e1f9e36f7f54dbdf08457afefb38afcdec4fa2bb" + +[[package]] +name = "yoke" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f41bb01b8226ef4bfd589436a297c53d118f65921786300e427be8d487695cc" +dependencies = [ + "serde", + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38da3c9736e16c5d3c8c597a9aaa5d1fa565d0532ae05e27c24aa62fb32c0ab6" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zerocopy" +version = "0.8.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1702d9583232ddb9174e01bb7c15a2ab8fb1bc6f227aa1233858c351a3ba0cb" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28a6e20d751156648aa063f3800b706ee209a32c0b4d9f24be3d980b01be55ef" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zerofrom" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" + +[[package]] +name = "zerotrie" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36f0bbd478583f79edad978b407914f61b2972f5af6fa089686016be8f9af595" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a05eb080e015ba39cc9e23bbe5e7fb04d5fb040350f99f34e338d5fdd294428" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b96237efa0c878c64bd89c436f661be4e46b2f3eff1ebb976f7ef2321d2f58f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/rust-client/Cargo.toml b/rust-client/Cargo.toml new file mode 100644 index 0000000000..5b49ab15fd --- /dev/null +++ b/rust-client/Cargo.toml @@ -0,0 +1,47 @@ +[package] +name = "wmill" +version = """ +1.496.3 +""" +edition = "2024" +description = "A client library for accessing Windmill server wrapping the Windmill client API" +license = "Apache-2.0" +homepage = "https://windmill.dev" + +[workspace] +resolver = "3" +members = ["windmill_api"] + +[dependencies] +serde_yaml = "0.9" +serde_json = "1.0" +serde = "1.0" +thiserror = "2" +anyhow = "1.0" +uuid = "1" + +[dependencies.windmill-api] +path = "./windmill_api" +version = "1.496.3" + +[dependencies.futures] +version = "0.3" + +[dependencies.tokio] +version = "1" +default-features = false + +[dependencies.once_cell] +version = "1.18" + +[dev-dependencies.tokio] +version = "1" +default-features = false +features = [ + "rt", + "macros", +] + +[features] +default = [] +async = [] diff --git a/rust-client/README.md b/rust-client/README.md new file mode 100644 index 0000000000..4fbf85010f --- /dev/null +++ b/rust-client/README.md @@ -0,0 +1,195 @@ +# Windmill Rust SDK + +A Rust client library for interacting with [Windmill](https://www.windmill.dev/) API, providing type-safe abstractions for variables, resources, scripts, jobs, and state management. + +## Installation + +Add this to your ```Cargo.toml```: + +```toml +[dependencies] +wmill = "0.1.0" +``` + +For async support (recommended): + +```toml +[dependencies] +wmill = { version = "0.1.0", features = ["async"] } +``` + +## Usage + +### Initialize Client + +```ignore +use wmill::Windmill; + +#[tokio::main] +async fn main() -> Result<(), Box> { + // Read config from env vars + let wm = Windmill::default()?; + + // Or override specific values + let wm = Windmill::new( + Some("custom_token".to_string()), + Some("my_workspace".to_string()), + Some("http://localhost:8000".to_string()) + )?; + + Ok(()) +} +``` + +### Variables + +```ignore +// Get variable (auto-parsed) +let db_config: serde_json::Value = wm.get_variable("u/admin/db_config").await?; + +// Get raw variable +let raw_text = wm.get_variable_raw("u/user/text_note").await?; + +// Set variable +wm.set_variable("new_value".to_string(), "u/user/my_var", false).await?; +``` + +### Resources + +```ignore +// Get resource (typed) +#[derive(serde::Deserialize)] +struct DbConfig { host: String, port: u16 } + +let config: DbConfig = wm.get_resource("u/admin/db").await?; + +// Get raw resource +let raw_json = wm.get_resource_any("u/admin/db").await?; + +// Set resource +wm.set_resource( + Some(serde_json::json!({"host": "localhost", "port": 5432})), + "u/admin/db", + "postgresql" +).await?; +``` + +### Scripts + +```ignore +// Run script async +let job_id = wm.run_script_async( + "u/user/my_script", + false, + serde_json::json!({"param": "value"}), + Some(10) // Schedule in 10 seconds +).await?; + +// Run script sync +let result = wm.run_script_sync( + "u/user/my_script", + false, + serde_json::json!({"param": "value"}), + Some(10), + Some(30), // 30s timeout + true, // Verbose + true // Assert result not None +).await?; +``` + +### Jobs + +```ignore +// Wait for job completion +let result = wm.wait_job(&job_id, Some(60), true, true).await?; + +// Get job status +let status = wm.get_job_status(&job_id).await?; // Running/Waiting/Completed + +// Get result directly +let result = wm.get_result(&job_id).await?; +``` + +### State Management + +```ignore +// Get typed state +#[derive(serde::Deserialize)] +struct ScriptState { counter: i32 } + +let state: ScriptState = wm.get_state().await?; + +// Get raw state +let raw_state = wm.get_state_any().await?; + +// Update state +wm.set_state(Some(serde_json::json!({"counter": 42}))).await?; +``` + +### Progress Tracking + +```ignore +// Set job progress +wm.set_progress(75, None).await?; // Uses current job ID from env + +// Get job progress +let progress = wm.get_progress(Some(job_id.to_string())).await?; +``` + +### Custom API Calls + +The SDK provides direct access to underlying API endpoints through the ```call_api``` method, which works in both async and sync contexts: + +```ignore +// Async usage +#[tokio::main] +async fn main() -> Result<(), Box> { + let wm = Windmill::default()?; + + // Make direct API call to get user + let user = wm.call_api(wmill::apis::admin_api::get_user( + &wm.client_config, + &wm.workspace, + "Alice" + )).await; + + println!("User details: {:?}", user); + Ok(()) +} + +// Sync usage +fn main() { + let wm = Windmill::default().unwrap(); + + // Make direct API call to get user + let user = wm.call_api(wmill::apis::admin_api::get_user( + &wm.client_config, + &wm.workspace, + "Bob" + )); + + println!("User details: {:?}", user); +} +``` + +This advanced feature allows access to any Windmill API endpoint, even those not covered by the SDK's convenience methods. Use this when: +- Need to access newer/undocumented API endpoints +- Require fine-grained control over API requests +- Existing abstractions don't meet specific needs + +## Environment Variables + +The SDK uses these environment variables: + +| Variable | Required | Description | +|---------|----------|-------------| +| ```WM_TOKEN``` | ✅ | Authentication token | +| ```WM_WORKSPACE``` | ✅ | Workspace name | +| ```BASE_INTERNAL_URL``` | ✅ | API base URL (without ```/api```) | +| ```WM_JOB_ID``` | Optional | Current job ID for progress tracking | +| ```WM_STATE_PATH_NEW``` | Optional | State path override | + +## Contributions + +Contributions are welcome! Please open an issue or submit a PR. + diff --git a/rust-client/dev.nu b/rust-client/dev.nu new file mode 100755 index 0000000000..010b84aa39 --- /dev/null +++ b/rust-client/dev.nu @@ -0,0 +1,81 @@ +#! /usr/bin/env nu + +let version = open ../version.txt; + +def main [ --publish(-p) --check(-c) --test(-t) ] { + mkdir api/a/ + + open ../backend/windmill-api/openapi.yaml + # openapi-generator confused with these two, so we just drop them + | reject paths."/w/{workspace}/apps/create_raw" + | reject paths."/w/{workspace}/apps/update_raw/{path}" + | save -f api/openapi.yaml; + + openapi-generator-cli generate -i api/openapi.yaml -g rust -o ./windmill_api --strict-spec true --additional-properties=packageName="windmill-api" + + # Patch Cargo.toml + open Cargo.toml + | update package.version $version + | save -f Cargo.toml + + # Patch windmill_api/Cargo.toml + open windmill_api/Cargo.toml + # Use rustls - otherwise compilation will fail due to missing libssl + | update dependencies.reqwest.features [json, multipart, rustls-tls] + | insert dependencies.reqwest.default-features false + | update package.license "Apache-2.0" + | insert package.homepage "https://windmill.dev" + | save -f windmill_api/Cargo.toml + + # Recursively replace serde_json::from_str with our patched version + ls ./windmill_api/src/**/*.rs + | each { |file| + let path = $file.name + open $path + | str replace --all "serde_json::from_str" "crate::from_str_patched/* Externally injected from /build.nu */" + | save -f $path + } + + # Inject patched from_str + echo ` +// NOTE: Injected by rust-client/dev.nu +pub fn from_str_patched<'a, T>(s: &'a str) -> Result +where + T: serde::de::DeserializeOwned + 'static, +{ + if std::any::TypeId::of::() == std::any::TypeId::of::() + || std::any::TypeId::of::() == std::any::TypeId::of::() { + // unsafe { std::mem::transmute::<&str, T>(s) } + // Quote string + let a = format!("\"{}\"", s.replace('"', r#"\""#)); + serde_json::from_str(&a) + } else { + serde_json::from_str(s) + } +} + ` | save --append ./windmill_api/src/lib.rs + + if $check { + print "Checking..." + cargo check --no-default-features + cargo check --features "async" + } + + if $test { + print "Testing..." + cargo test --features async simple + cargo test --no-default-features + } + + if $publish { + print "Publishing..." + + print Publishing windmill-api + cd windmill_api + cargo publish --token $env.CRATES_IO_TOKEN --allow-dirty + + print Publishing wmill + cd ../ + cargo publish --token $env.CRATES_IO_TOKEN --allow-dirty + } +} diff --git a/rust-client/src/client.rs b/rust-client/src/client.rs new file mode 100644 index 0000000000..66dea99fbb --- /dev/null +++ b/rust-client/src/client.rs @@ -0,0 +1,1047 @@ +#[cfg(feature = "async")] +use futures::FutureExt; +use windmill_api::{ + apis::{ + configuration::Configuration, + job_api, + resource_api::{self, get_resource_value_interpolated}, + variable_api, + }, + models::{EditResource, GetCompletedJobResultMaybe200Response}, +}; + +use serde::Deserialize; +use serde_json::{Value, json}; +use std::{ + env::{self, var}, + fmt::Debug, + time::{Duration, Instant}, +}; + +use crate::{maybe_future::maybe_future::MaybeFuture, ret}; + +#[derive(Debug, Clone)] +pub struct Windmill { + pub workspace: String, + pub token: String, + pub base_internal_url: String, + pub client_config: Configuration, +} + +impl Windmill { + /// Creates a new `Windmill` instance with default configuration. + /// + /// Reads configuration from environment variables: + /// - `WM_TOKEN` for authentication token + /// - `WM_WORKSPACE` for workspace name + /// - `BASE_INTERNAL_URL` for API base URL (appends `/api` automatically) + /// + /// # Errors + /// Returns `SdkError` if: + /// - Required environment variables are missing + /// - Environment variables cannot be read + pub fn default() -> Result { + Windmill::new(None, None, None) + } + + /// Creates a new `Windmill` instance with optional overrides. + /// + /// Falls back to environment variables for any `None` parameters: + /// - `WM_TOKEN` if `token` is `None` + /// - `WM_WORKSPACE` if `workspace` is `None` + /// - `BASE_INTERNAL_URL` + "/api" if `base_internal_url` is `None` + /// + /// # Parameters + /// - `token`: Optional bearer token override + /// - `workspace`: Optional workspace name override + /// - `base_internal_url`: Optional base URL override (without `/api` suffix) + /// + /// # Errors + /// Returns `SdkError` if: + /// - Required environment variables are missing when needed + /// - Environment variables cannot be read + pub fn new( + token: Option, + workspace: Option, + base_internal_url: Option, + ) -> Result { + use env::var; + let (token, base_internal_url, workspace) = ( + token.or(var("WM_TOKEN").ok()).ok_or(SdkError::BadValue( + "WM_TOKEN is not set nor was provided in constructor".to_owned(), + ))?, + base_internal_url + .or(var("BASE_INTERNAL_URL").ok()) + .ok_or(SdkError::BadValue( + "BASE_INTERNAL_URL is not set nor was provided in constructor".to_owned(), + ))? + + "/api", + workspace + .or(var("WM_WORKSPACE").ok()) + .ok_or(SdkError::BadValue( + "WM_WORKSPACE is not set nor was provided in constructor".to_owned(), + ))?, + ); + + Ok(Windmill { + client_config: Configuration { + // TODO: client: reqwest::blocking::Client::new(), // Use blocking client? + base_path: base_internal_url.clone(), + bearer_access_token: Some(token.clone()), + ..Default::default() + }, + workspace, + token, + base_internal_url, + }) + } + + /// Retrieves a variable from Windmill, automatically parsing it as JSON/YAML. + /// + /// This is the convenience version that attempts to parse the variable value as: + /// 1. JSON (primary attempt) + /// 2. YAML (fallback if JSON parsing fails) + /// 3. Raw string (final fallback if both parsings fail) + /// + /// For better performance when you know the format or don't need parsing, + /// use [`Self::get_variable_raw`] instead. + /// + /// # Arguments + /// * `path` - Variable path (e.g., "u/user/variable_name") + /// + /// # Example + /// ```no_run + /// + /// use wmill::Windmill; + /// use serde_json::json; + /// + /// let wm = Windmill::default()?; + /// + /// // For a variable containing JSON: {"key": "value"} + /// let json_var = wm.get_variable("u/admin/config")?; + /// + /// // For a variable containing plain text + /// let text_var = wm.get_variable("u/user/plaintext_note")?; + /// + /// # Ok::<(), wmill::SdkError>(()) + /// ``` + /// + /// See also: [`Self::get_variable_raw`] for the unparsed version + pub fn get_variable<'a>(&'a self, path: &'a str) -> MaybeFuture<'a, Result> { + ret!(self.get_variable_inner(path)); + } + + async fn get_variable_inner<'a>(&'a self, path: &'a str) -> Result { + let raw = self.get_variable_raw_inner(path).await?; + Ok(serde_json::from_str(&raw) + .or(serde_yaml::from_str(&raw)) + .unwrap_or(json!(raw))) + } + + /// This is the **faster version** when: + /// - You know the variable contains plain text + /// - You want to handle parsing yourself + /// - You need maximum performance + /// + /// Performance benefit comes from avoiding: + /// 1. JSON parsing attempt + /// 2. YAML parsing fallback + /// + /// # Arguments + /// * `path` - Variable path (e.g., "u/user/variable_name") + /// + /// # Example + /// ```no_run + /// use wmill::Windmill; + /// use serde_json::{json, Value}; + /// + /// let wm = Windmill::default()?; + /// + /// // When you need the raw content + /// let raw_content = wm.get_variable_raw("u/user/custom_format")?; + /// + /// // When you know it's JSON and want to parse it differently + /// let json_value: Value = serde_json::from_str( + /// &wm.get_variable_raw("u/admin/config")? + /// )?; + /// + /// # Ok::<(), wmill::SdkError>(()) + /// ``` + /// + /// See also: [`Self::get_variable`] for the auto-parsed version + pub fn get_variable_raw<'a>( + &'a self, + path: &'a str, + ) -> MaybeFuture<'a, Result> { + ret!(self.get_variable_raw_inner(path)); + } + + async fn get_variable_raw_inner<'a>(&'a self, path: &'a str) -> Result { + let v = + variable_api::get_variable_value(&self.client_config, &self.workspace, path).await?; + + v.get(1..v.len() - 1) + .ok_or(SdkError::InternalError( + "returned value is incorrect".into(), + )) + .map(|s| s.to_owned()) + } + + /// Creates or updates a variable in the workspace. + /// + /// This function provides atomic variable management that: + /// - Creates a new variable if it doesn't exist + /// - Updates an existing variable if found + /// - Handles both regular and secret variables + /// + /// # Parameters + /// - `value`: The variable value to set + /// - `path`: The variable path/identifier + /// - `is_secret`: Whether to store as a secret (encrypted) variable + /// + /// # Errors + /// Returns `SdkError` if: + /// - Variable fetch fails for reasons other than "not found" + /// - Variable creation fails + /// - Variable update fails + /// - Underlying API calls fail + /// + /// # Notes + /// - For new variables, defaults to empty description + /// - Updates only modify the value (preserving other metadata) + /// - Secret status can only be set during creation + pub fn set_variable<'a>( + &'a self, + value: String, + path: &'a str, + is_secret: bool, + ) -> MaybeFuture<'a, Result<(), SdkError>> { + ret!(self.set_variable_inner(value, path, is_secret)); + } + + async fn set_variable_inner<'a>( + &'a self, + value: String, + path: &'a str, + is_secret: bool, + ) -> Result<(), SdkError> { + let res = + variable_api::get_variable(&self.client_config, &self.workspace, path, None, None) + .await; + + if res.is_err() { + variable_api::create_variable( + &self.client_config, + &self.workspace, + windmill_api::models::CreateVariable { + path: path.to_owned(), + value, + is_secret, + description: "".to_owned(), + account: None, + is_oauth: None, + expires_at: None, + }, + None, + ) + .await?; + } else { + variable_api::update_variable( + &self.client_config, + &self.workspace, + path, + windmill_api::models::EditVariable { + path: None, + value: Some(value), + is_secret: None, + description: None, + }, + None, + ) + .await?; + } + Ok(()) + } + + /// Fetches and deserializes a resource into a concrete type. + /// + /// This is the recommended way to access resources when you know the expected type. + /// For raw JSON access or dynamic typing, use [`Self::get_resource_any`] instead. + /// + /// # Type Parameters + /// * `T` - Any type implementing `DeserializeOwned` (most structs with `#[derive(Deserialize)]`) + /// + /// # Arguments + /// * `path` - The resource path (e.g., "u/user/resource_name") + /// + /// # Example + /// ```no_run + /// use wmill::Windmill; + /// use serde_json::{json, Value}; + /// use serde::Deserialize; + /// + /// #[derive(Deserialize)] + /// struct DbConfig { + /// url: String, + /// pool_size: Option, + /// } + /// + /// let wm = Windmill::default()?; + /// + /// // Directly deserialize to your type + /// let config: DbConfig = wm.get_resource("u/admin/db_connection")?; + /// # Ok::<(), wmill::SdkError>(()) + /// ``` + /// + /// See also: [`Self::get_resource_any`] for untyped version + pub fn get_resource<'a, T: serde::de::DeserializeOwned>( + &'a self, + path: &'a str, + ) -> MaybeFuture<'a, Result> { + ret!(self.get_resource_inner(path)); + } + + async fn get_resource_inner<'a, T: serde::de::DeserializeOwned>( + &'a self, + path: &'a str, + ) -> Result { + Ok(serde_json::from_value( + self.get_resource_any_inner(path).await?, + )?) + } + + /// Fetches a raw JSON [`Value`] from Windmill by path. + /// + /// Use this when you need the raw JSON structure or don't have a concrete type to deserialize into. + /// For typed deserialization, prefer [`Self::get_resource`] instead. + /// + /// # Arguments + /// * `path` - The resource path (e.g., "u/user/resource_name") + /// + /// # Example + /// ```no_run + /// use wmill::Windmill; + /// + /// let wm = Windmill::default()?; + /// + /// // When you need to inspect the raw structure first + /// let json = wm.get_resource_any("u/admin/db_connection")?; + /// + /// println!("Url is: {}", json["url"]); + /// + /// # Ok::<(), wmill::SdkError>(()) + /// ``` + /// + /// See also: [`Self::get_resource`] for typed version + pub fn get_resource_any<'a>( + &'a self, + path: &'a str, + ) -> MaybeFuture<'a, Result> { + ret!(self.get_resource_any_inner(path)); + } + + async fn get_resource_any_inner<'a>(&'a self, path: &'a str) -> Result { + Ok( + get_resource_value_interpolated(&self.client_config, &self.workspace, path, None) + .await?, + ) + } + + /// Creates or updates a resource in Windmill. + /// + /// This function sets a resource's value at the specified path, creating it if it doesn't exist + /// or updating it if it does. The resource will be of the specified type. + /// + /// # Arguments + /// * `value` - The value to set for the resource. Use `None` to create an empty resource. + /// * `path` - The ownership path of the resource (e.g., "u/user/resource_name"). + /// Defines permissions based on Windmill's path prefix system. + /// * `resource_type` - The type of resource to create (e.g., "postgresql", "smtp"). + /// Must be a pre-existing resource type. + /// + /// # Examples + /// ```no_run + /// use wmill::Windmill; + /// + /// # fn main() -> anyhow::Result<()> { + /// let wm = Windmill::default()?; + /// wm.set_resource( + /// Some(serde_json::json!({"host": "localhost", "port": 5432})), + /// "u/admin/database", + /// "postgresql" + /// )?; + /// # Ok(()) + /// # } + /// ``` + pub fn set_resource<'a>( + &'a self, + value: Option, + path: &'a str, + resource_type: &'a str, + ) -> MaybeFuture<'a, Result<(), SdkError>> { + ret!(self.set_resource_inner(value, path, resource_type)); + } + + async fn set_resource_inner<'a>( + &'a self, + value: Option, + path: &'a str, + resource_type: &'a str, + ) -> Result<(), SdkError> { + // if resource_api::get_resource(&self.client_config, &self.workspace, path) + // .await + // .is_err() + if !resource_api::exists_resource(&self.client_config, &self.workspace, path).await? { + resource_api::create_resource( + &self.client_config, + &self.workspace, + windmill_api::models::CreateResource { + path: path.to_owned(), + value, + description: None, + resource_type: resource_type.to_owned(), + // resource_type: "any".to_owned(), + }, + // Some(true), + None, + ) + .await?; + } else { + resource_api::update_resource( + &self.client_config, + &self.workspace, + path, + EditResource { + path: None, + description: None, + value: Some(value), + }, + ) + .await?; + } + Ok(()) + } + + /// Retrieves and deserializes the current typed state value for a script's execution context. + /// + /// This is the typed version of [`Self::get_state_any`], automatically deserializing the state + /// into the specified type `T` that implements [`serde::de::DeserializeOwned`]. + /// + /// # Type Parameter + /// * `T` - The type to deserialize into (must implement `serde::de::DeserializeOwned`) + /// + /// # Examples + /// ```no_run + /// use wmill::Windmill; + /// use serde_json::{json, Value}; + /// use serde::Deserialize; + /// + /// #[derive(Deserialize)] + /// struct ScriptState { + /// counter: i32, + /// last_run: String, + /// } + /// + /// let wm = Windmill::default()?; + /// + /// // Get typed state + /// let state: ScriptState = wm.get_state()?; + /// + /// println!("Counter: {}, Last run: {}", state.counter, state.last_run); + /// + /// # Ok::<(), wmill::SdkError>(()) + /// ``` + /// + /// # Behavior Details + /// - Uses same state path resolution as [`Self::get_state_any`] (`WM_STATE_PATH_NEW` → `WM_STATE_PATH` fallback) + /// - Performs runtime type checking during deserialization + /// + /// # When to Use vs [`Self::get_state_any`] + /// | Use Case | `get_state` | `get_state_any` | + /// |------------------------|-------------------------|------------------------| + /// | Known state structure | ✅ Preferred | ⚠️ Requires manual parsing | + /// | Dynamic state | ❌ Won't compile | ✅ Works | + /// | Type safety | ✅ Compile-time checks | ❌ Runtime checks only | + /// + /// # Notes + /// - For complex types, derive `Deserialize` using Serde attributes + /// - Prefer this over [`Self::get_state_any`] when state schema is stable + /// - State modifications should use corresponding [`Self::set_state`] with matching type + /// + /// # See Also + /// - [`Self::get_state_any`] - Untyped state access + /// - [`Self::set_state`] - For updating typed states + /// - [Windmill State Management](https://www.windmill.dev/docs/core_concepts/persistent_storage/within_windmill#states) + pub fn get_state<'a, T: serde::de::DeserializeOwned>( + &'a self, + ) -> MaybeFuture<'a, Result> { + ret!(self.get_resource_inner(&get_state_path()?)); + } + + /// Retrieves the current state value for a script's execution context. + /// + /// States persist data between runs of the same script by the same trigger (schedule or user). + /// This is the untyped version that returns a generic [`Value`]. + /// + /// # Examples + /// ```no_run + /// use wmill::Windmill; + /// use serde_json::Value; + /// use serde::Deserialize; + /// + /// let wm = Windmill::default()?; + /// + /// // Get state (returns serde_json::Value) + /// let state: Value = wm.get_state_any()?; + /// + /// // Use with default if empty + /// let counter = state.as_i64().unwrap_or(0); + /// # Ok::<(), wmill::SdkError>(()) + /// ``` + /// + /// # Behavior Details + /// - Automatically uses the script's state path from `WM_STATE_PATH_NEW` (falls back to `WM_STATE_PATH`) + /// - Returns the full state object stored as a Windmill resource + /// - State resources are hidden from Workspace view but visible under Resources → States + /// + /// # Typical Use Cases + /// 1. Maintaining counters between runs + /// 2. Storing last execution timestamps + /// 3. Keeping reference data (like previous API responses) + /// + /// # Notes + /// - For typed state access, use `get_state` instead + /// - States are isolated per script and trigger combination + /// - Maximum state size: 5MB (compressed) + /// + /// # See Also + /// - [`Self::set_state`] - For updating the state + /// - [Windmill State Management](https://www.windmill.dev/docs/core_concepts/persistent_storage/within_windmill#states) + pub fn get_state_any<'a>(&'a self) -> MaybeFuture<'a, Result> { + ret!(self.get_resource_any_inner(&get_state_path()?)); + } + + /// Updates or clears the script's persistent state. + /// + /// # Arguments + /// * `value` - New state value (`Some(Value)`) or `None` to clear state + /// + /// # Examples + /// ```no_run + /// use wmill::Windmill; + /// use serde_json::json; + /// + /// # async fn example() -> anyhow::Result<()> { + /// let wm = Windmill::default()?; + /// + /// // Set state + /// wm.set_state(Some(json!({"count": 42})))?; + /// + /// // Clear state + /// wm.set_state(None)?; + /// # Ok(()) + /// # } + /// ``` + /// + /// See also: [`Self::get_state`], [`Self::get_state_any`] + pub fn set_state<'a>(&'a self, value: Option) -> MaybeFuture<'a, Result<(), SdkError>> { + ret!(self.set_resource_inner(value, &get_state_path()?, "state")); + } + + /// Executes a script synchronously and waits for its completion. + /// + /// This is a blocking version of `run_script_async` that handles the entire script execution + /// lifecycle including job scheduling and result waiting. + /// + /// # Parameters + /// - `ident`: Script identifier (either path or hash) + /// - `ident_is_hash`: Whether the identifier is a hash (true) or path (false) + /// - `args`: JSON arguments to pass to the script + /// - `scheduled_in_secs`: Optional delay before execution (in seconds) + /// - `timeout_secs`: Maximum time to wait for job completion (in seconds) + /// - `verbose`: Whether to print execution details + /// - `assert_result_is_not_none`: Whether to fail if the result is None + /// + /// # Errors + /// Returns `SdkError` if: + /// - Script fails to start + /// - Job times out + /// - Result assertion fails + /// - Underlying API calls fail + pub fn run_script_sync<'a>( + &'a self, + ident: &'a str, + ident_is_hash: bool, + args: Value, + scheduled_in_secs: Option, + timeout_secs: Option, + verbose: bool, + assert_result_is_not_none: bool, + ) -> MaybeFuture<'a, Result> { + if verbose { + println!("running `{ident}` synchronously with {:?}", &args); + } + + ret!(async move { + let job_id = self + .run_script_async_inner(ident, ident_is_hash, args, scheduled_in_secs) + .await?; + self.wait_job_inner( + &job_id.to_string(), + timeout_secs, + verbose, + assert_result_is_not_none, + ) + .await + }); + } + + /// Asynchronously executes a script in Windmill and returns its job UUID. + /// + /// This function runs a script either by path or by hash, with optional: + /// - Parent job inheritance (when run within a flow) + /// - Scheduled execution delay + /// - Argument passing + /// + /// # Arguments + /// * `ident` - Script identifier (path or hash depending on `ident_is_hash`) + /// * `ident_is_hash` - If true, `ident` is treated as a script hash; if false, as a path + /// * `args` - JSON arguments to pass to the script (must be an object if using path) + /// * `scheduled_in_secs` - Optional delay (in seconds) before execution + /// + /// # Examples + /// ```no_run + /// use wmill::Windmill; + /// use serde_json::json; + /// + /// let wm = Windmill::default()?; + /// let job_id = wm.run_script_async( + /// "u/user/script_path", + /// false, + /// json!({"param1": "value1"}), + /// Some(10) // Run after 10 seconds + /// )?; + /// + /// # Ok::<(), wmill::SdkError>(()) + /// ``` + /// + /// # Behavior Details + /// - **Automatic Job Inheritance**: + /// - Detects `WM_JOB_ID` env var → sets as `parent_job` + /// - Detects `WM_ROOT_FLOW_JOB_ID` env var → sets as `root_job` + /// - **Scheduled Execution**: + /// - When `scheduled_in_secs` is provided, sets `scheduled_in_secs` in args + /// - **Argument Handling**: + /// - For path-based execution (`ident_is_hash=false`), args must be a JSON object + /// - For hash-based execution, args can be any valid JSON value + /// + /// # Errors + /// - [`SdkError::BadValue`] if path-based execution receives non-object arguments + /// - API errors from Windmill's backend + pub fn run_script_async<'a>( + &'a self, + ident: &'a str, + ident_is_hash: bool, + args: Value, + scheduled_in_secs: Option, + ) -> MaybeFuture<'a, Result> { + ret!(self.run_script_async_inner(ident, ident_is_hash, args, scheduled_in_secs)); + } + + async fn run_script_async_inner<'a>( + &'a self, + ident: &'a str, + ident_is_hash: bool, + mut args: Value, + scheduled_in_secs: Option, + ) -> Result { + if let Ok(parent_job) = var("WM_JOB_ID") { + args["parent_job"] = json!(parent_job); + } + + if let Ok(root_job) = var("WM_ROOT_FLOW_JOB_ID") { + args["root_job"] = json!(root_job); + } + + if let Some(scheduled_in_secs) = scheduled_in_secs { + args["scheduled_in_secs"] = json!(scheduled_in_secs); + } + + let uuid = if ident_is_hash { + job_api::run_script_by_hash( + &self.client_config, + &self.workspace, + ident, + args, + None, + None, + None, + None, + None, + None, + None, + None, + None, + ) + .await? + } else { + job_api::run_script_by_path( + &self.client_config, + &self.workspace, + ident, + args.as_object() + .ok_or(SdkError::BadValue(format!( + "Args should be Object, but it is: {}", + args + )))? + .clone() + .into_iter() + .collect(), + None, + None, + None, + None, + None, + None, + None, + None, + ) + .await? + }; + Ok(uuid) + } + + /// Waits for a job to complete and returns its result. + /// + /// This function provides both synchronous and asynchronous interfaces for waiting + /// on job completion, with timeout handling and result validation. + /// + /// # Parameters + /// - `job_id`: The ID of the job to wait for + /// - `timeout_secs`: Maximum time to wait (in seconds) before cancelling the job + /// - `verbose`: Whether to print progress information + /// - `assert_result_is_not_none`: Whether to fail if the job returns no result + /// + /// # Errors + /// Returns `SdkError` if: + /// - Job fails or times out + /// - Result assertion fails when `assert_result_is_not_none` is true + /// - Underlying API calls fail + /// + /// # Behavior + /// 1. Polls job status at 500ms intervals + /// 2. Cancels job if timeout is reached + /// 3. Validates success status and optional result presence + /// 4. Returns either the result or appropriate error + pub fn wait_job<'a>( + &'a self, + job_id: &'a str, + timeout_secs: Option, + verbose: bool, + assert_result_is_not_none: bool, + ) -> MaybeFuture<'a, Result> { + ret!(self.wait_job_inner(job_id, timeout_secs, verbose, assert_result_is_not_none)); + } + + async fn wait_job_inner<'a>( + &'a self, + job_id: &'a str, + timeout_secs: Option, + verbose: bool, + assert_result_is_not_none: bool, + ) -> Result { + let start = Instant::now(); + loop { + if let Some(timeout) = timeout_secs { + if start.elapsed().as_secs() > timeout { + println!("WARN: reached timeout for {job_id}. Cancelling the job."); + job_api::cancel_queued_job( + &self.client_config, + &self.workspace, + job_id, + windmill_api::models::CancelQueuedJobRequest { + reason: Some("reached timeout".into()), + }, + ) + .await?; + } + } + let GetCompletedJobResultMaybe200Response { + completed, + result, + success, + started, + } = job_api::get_completed_job_result_maybe( + &self.client_config, + &self.workspace, + job_id, + Some(true), + ) + .await?; + + if matches!(started, Some(false)) && verbose { + println!("INFO: job {job_id} has not started yet"); + } + + if completed { + if matches!(success, Some(true)) { + if result.is_none() && assert_result_is_not_none { + return Err(SdkError::ExecutionError("Result was None".into())); + } + return Ok(result.unwrap_or_default()); + } else { + return Err(SdkError::ExecutionError(format!( + "Job {job_id} was not successful: {:?}", + result + ))); + } + } + if verbose { + println!("INFO: sleeping 0.5 seconds for {job_id}"); + } + tokio::time::sleep(Duration::from_millis(500)).await; + } + } + + /// Retrieves the current status of a Windmill job by its UUID. + /// + /// This function queries the Windmill backend to determine whether a job is: + /// - Waiting to be executed + /// - Currently running + /// - Already completed + /// + /// # Arguments + /// * `job_id` - The UUID of the job to check (format: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx") + /// + /// # Job Lifecycle States + /// - **Waiting**: Job is queued but hasn't started execution + /// - **Running**: Job is currently being executed + /// - **Completed**: Job has finished (successfully or with errors) + pub fn get_job_status<'a>( + &'a self, + job_id: &'a str, + ) -> MaybeFuture<'a, Result> { + ret!(self.get_job_status_inner(job_id)); + } + + async fn get_job_status_inner<'a>(&'a self, job_id: &'a str) -> Result { + let job = + job_api::get_job(&self.client_config, &self.workspace, job_id, Some(true)).await?; + + Ok(match job { + windmill_api::models::Job::JobOneOf(..) => JobStatus::Completed, + windmill_api::models::Job::JobOneOf1(job_one_of1) => { + if job_one_of1.running { + JobStatus::Running + } else { + JobStatus::Waiting + } + } + }) + } + + /// Retrieves the result of a completed job. + /// + /// This provides both synchronous and asynchronous interfaces for fetching + /// the final result of a successfully completed job. + /// + /// # Parameters + /// - `job_id`: The ID of the completed job to fetch results for + /// + /// # Errors + /// Returns `SdkError` if: + /// - Job is not found + /// - Job failed to complete successfully + /// - Underlying API calls fail + /// - Result cannot be parsed + /// + /// # Notes + /// - Only works for jobs that have already completed + /// - For pending/running jobs, use `wait_job` instead + /// - Does not handle timeouts or polling - assumes job is already complete + pub fn get_result<'a>(&'a self, job_id: &'a str) -> MaybeFuture<'a, Result> { + ret!(self.get_result_inner(job_id)); + } + + async fn get_result_inner<'a>(&'a self, job_id: &'a str) -> Result { + Ok(job_api::get_completed_job_result( + &self.client_config, + &self.workspace, + job_id, + None, + None, + None, + None, + ) + .await?) + } + + /// Updates the progress percentage of a running Windmill job. + /// + /// This function allows scripts to report their execution progress (0-100%) back to the Windmill UI. + /// Progress updates are visible in both the jobs dashboard and flow visualizations. + /// + /// # Arguments + /// * `value` - Progress percentage (0-100) + /// * `job_id` - Optional job UUID. If None, uses current job's ID from `WM_JOB_ID` environment variable + /// + /// # Examples + /// ```no_run + /// use wmill::Windmill; + /// # fn main () -> anyhow::Result<()>{ + /// let wm = Windmill::default()?; + /// + /// // Report progress for current job + /// wm.set_progress(25, None)?; + /// # Ok(()) + /// # } + /// + /// ``` + /// + /// # Behavior Details + /// - Automatically handles flow context by detecting parent job ID + /// - Progress updates are reflected in real-time in the Windmill UI + /// - Typical usage pattern: + /// ```ignore + /// for (i, item) in items.iter().enumerate() { + /// process(item); + /// let progress = ((i + 1) * 100 / items.len()) as i32; + /// wmill.set_progress(progress, None).await?; + /// } + /// ``` + /// + /// # Notes + /// - Only affects jobs that are currently running + /// - Progress values outside 0-99 range are clamped by the server + /// - Progress cannot decrease + /// - For flows, updates the progress of both the step and parent flow + /// + /// # See Also + /// - [Flow Progress Tracking](https://www.windmill.dev/docs/advanced/explicit_progress) + /// - [`Self::get_progress`] - For reading job progress + pub fn set_progress<'a>( + &'a self, + value: u32, + job_id: Option, + ) -> MaybeFuture<'a, Result<(), SdkError>> { + let f = async move { + let job_id = job_id.unwrap_or(var("WM_JOB_ID")?); + let job = + job_api::get_job(&self.client_config, &self.workspace, &job_id, Some(true)).await?; + + let flow_id = match job { + windmill_api::models::Job::JobOneOf(job) => job.parent_job, + windmill_api::models::Job::JobOneOf1(job) => job.parent_job, + }; + + windmill_api::apis::metrics_api::set_job_progress( + &self.client_config, + &self.workspace, + &job_id, + windmill_api::models::SetJobProgressRequest { + percent: Some(value as i32), + flow_job_id: flow_id, + }, + ) + .await?; + Ok(()) + }; + ret!(f); + } + + /// Retrieves the current progress percentage of a Windmill job. + /// + /// This function queries the Windmill backend to get the execution progress (0-100%) + /// of either a specific job or the current job context. + /// + /// # Arguments + /// * `job_id` - Optional job UUID. If `None`, uses current job's ID from `WM_JOB_ID` env var + /// + /// # See Also + /// - [Flow Progress Tracking](https://www.windmill.dev/docs/advanced/explicit_progress) + /// - [`Self::set_progress`] - For updating job progress + pub fn get_progress<'a>( + &'a self, + job_id: Option, + ) -> MaybeFuture<'a, Result> { + let f = async move { + let job_id = job_id.unwrap_or(var("WM_JOB_ID")?); + Ok(windmill_api::apis::metrics_api::get_job_progress( + &self.client_config, + &self.workspace, + &job_id, + ) + .await + .map(|v| v as u32)?) + }; + ret!(f); + } + + /// Executes an API call in either asynchronous or synchronous mode based on compilation context. + /// + /// This function serves as a bridge between async and sync code, automatically adapting its behavior: + /// - With `async` feature: Returns a boxed future for later await + /// - Without `async` feature: Blocks immediately using the global runtime + /// + /// # Examples + /// + /// ## Async usage (with `async` feature) + /// ```ignore + /// use wmill::Windmill; + /// # #[tokio::main] + /// # async fn main() -> anyhow::Result<()>{ + /// let wm = Windmill::default()?; + /// let user = wm.call_api(wmill::apis::admin_api::get_user(&wm.client_config, &wm.workspace, "Bob"))?; + /// println!("User details: {:?}", user); + /// # Ok(()) + /// # } + /// ``` + /// + /// ## Sync usage (without `async` feature) + /// ```ignore + /// use wmill::Windmill; + /// let wm = Windmill::new(Some("".into()), Some("admins".into()), Some("http://localhost:5000/api".into()))?; + /// let user = wm.call_api(wmill::apis::admin_api::get_user(&wm.client_config, &wm.workspace, "Bob")); + /// println!("User details: {:?}", user); + /// # Ok::<(), wmill::SdkError>(()) + /// ``` + pub fn call_api<'a, T>( + &'a self, + callback: impl Future + std::marker::Send + 'a, + ) -> MaybeFuture<'a, T> { + ret!(callback); + } + + // pub fn get_version() {} +} + +pub enum JobStatus { + Running, + Waiting, + Completed, +} + +fn get_state_path() -> Result { + Ok(var("WM_STATE_PATH_NEW").unwrap_or(var("WM_STATE_PATH")?)) +} + +#[derive(thiserror::Error, Debug)] +pub enum SdkError { + #[error("Error: {0}")] + Serde(#[from] serde_json::Error), + #[error("Having troubles reading Env Variable: {0}")] + VarError(#[from] std::env::VarError), + #[error("Api error: {0}")] + ApiError(String), + #[error("Internal Error: {0}")] + InternalError(String), + #[error("Specified value is incorrect: {0}")] + BadValue(String), + #[error("{0}")] + ExecutionError(String), +} +impl Deserialize<'a>> From> for SdkError { + fn from(value: windmill_api::apis::Error) -> Self { + Self::ApiError(value.to_string()) + } +} diff --git a/rust-client/src/lib.rs b/rust-client/src/lib.rs new file mode 100644 index 0000000000..32dbb548de --- /dev/null +++ b/rust-client/src/lib.rs @@ -0,0 +1,8 @@ +#![doc = include_str!("../README.md")] +mod client; +mod maybe_future; +#[cfg(test)] +mod tests; + +pub use client::{SdkError, Windmill}; +pub use windmill_api::apis; diff --git a/rust-client/src/maybe_future.rs b/rust-client/src/maybe_future.rs new file mode 100644 index 0000000000..ed9f3f086a --- /dev/null +++ b/rust-client/src/maybe_future.rs @@ -0,0 +1,48 @@ +// #[cfg(feature = "async")] +// use futures::future::BoxFuture; + +/// A conditional type that represents either: +/// - A boxed future (async mode) +/// - A direct value (sync mode) +pub mod maybe_future { + #[cfg(feature = "async")] + pub type MaybeFuture<'a, T> = futures::future::BoxFuture<'a, T>; + #[cfg(not(feature = "async"))] + pub type MaybeFuture<'a, T> = T; +} + +/// Bridges between async and sync execution contexts +/// +/// Behavior depends on compilation: +/// - With `async` feature: Returns a boxed future +/// - Without `async` feature: Blocks on the global runtime +#[macro_export] +macro_rules! ret { + ($ex:expr) => { + #[cfg(feature = "async")] + return async move { $ex.await }.boxed(); + + #[cfg(not(feature = "async"))] + return crate::maybe_future::RUNTIME.block_on($ex); + }; +} + +/// The global Tokio runtime instance used in sync mode +/// +/// Initialized lazily with: +/// - I/O capabilities +/// - Time utilities +/// - Current-thread executor +/// +/// # Panics +/// +/// If Tokio fails to initialize the runtime +#[cfg(not(feature = "async"))] +pub(crate) static RUNTIME: once_cell::sync::Lazy = + once_cell::sync::Lazy::new(|| { + tokio::runtime::Builder::new_current_thread() + .enable_io() + .enable_time() + .build() + .unwrap() + }); diff --git a/rust-client/src/tests.rs b/rust-client/src/tests.rs new file mode 100644 index 0000000000..7e3ef4cd77 --- /dev/null +++ b/rust-client/src/tests.rs @@ -0,0 +1,345 @@ +use serde::Deserialize; +use serde_json::json; +use uuid::Uuid; + +use super::*; + +fn wm() -> Windmill { + Windmill::new( + // Some("".into()), + None, + Some("admins".into()), + // Some("storage".into()), + Some("http://localhost:8000".into()), + ) + .unwrap() +} + +#[cfg(not(feature = "async"))] +#[test] +fn create() { + wm(); +} + +#[cfg(not(feature = "async"))] +#[test] +fn resources() { + #[derive(Deserialize, Debug, PartialEq, PartialOrd)] + struct MatrixResource { + token: String, + #[allow(non_snake_case)] + baseUrl: String, + } + let wm = wm(); + let path = format!("f/tests/delete_me_{}", Uuid::new_v4()); + + { + wm.set_resource( + Some(json!({ + "token": "token", + "baseUrl": "url" + })), + &path, + "matrix", + ) + .unwrap(); + + let matrix: MatrixResource = wm.get_resource(&path).unwrap(); + + assert_eq!( + MatrixResource { + token: "token".into(), + baseUrl: "url".into() + }, + matrix + ); + } +} + +#[cfg(not(feature = "async"))] +#[test] +fn variables() { + let wm = wm(); + let path = format!("f/tests/delete_me_{}", Uuid::new_v4()); + + { + // Create new + wm.set_variable( + ":0".into(), + &path, + // TODO: Test with true + false, + ) + .unwrap(); + + // Read + let out_val = wm.get_variable_raw(&path).unwrap(); + assert_eq!(":0", &out_val); + } + { + // Update + let in_val = json!({ + "a": true, + "b": "c" + }); + + wm.set_variable( + // Serialize as JSON + serde_yaml::to_string(&in_val).unwrap(), + &path, + false, + ) + .unwrap(); + + // Read Updated + let out_val = wm.get_variable(&path).unwrap(); + + assert_eq!(in_val, out_val); + } +} + +#[cfg(not(feature = "async"))] +#[test] +fn create_and_run() { + let wm = wm(); + + let path = format!("f/tests/delete_me_{}", Uuid::new_v4()); + let resp = wm + .call_api(apis::script_api::create_script( + &wm.client_config, + &wm.workspace, + windmill_api::models::NewScript { + path: path.clone(), + parent_hash: None, + summary: "auto-generated script from rust sdk | testing".into(), + description: "auto-generated script from rust sdk | testing".into(), + content: r#"fn main() -> Result { Ok("Hello World!".to_owned()) }"# + .into(), + schema: None, + is_template: None, + lock: None, + language: windmill_api::models::ScriptLang::Rust, + kind: Some(windmill_api::models::new_script::Kind::Script), + tag: Some("rust".into()), + draft_only: None, + envs: None, + concurrent_limit: None, + concurrency_time_window_s: None, + cache_ttl: None, + dedicated_worker: None, + ws_error_handler_muted: None, + priority: None, + restart_unless_cancelled: None, + timeout: None, + delete_after_use: None, + deployment_message: None, + concurrency_key: None, + visible_to_runner_only: None, + no_main_func: None, + codebase: None, + has_preprocessor: None, + on_behalf_of_email: None, + }, + )) + .unwrap(); + + assert_eq!( + json!("Hello World!"), + wm.run_script_sync( + // + &resp, + true, + json!(null), + None, + None, + true, + false, + ) + .unwrap() + ); +} +#[cfg(not(feature = "async"))] +#[test] +fn test_within() { + let wm = wm(); + + let path = format!("f/tests/delete_me_{}", Uuid::new_v4()); + let resp = wm + .call_api(apis::script_api::create_script( + &wm.client_config, + &wm.workspace, + windmill_api::models::NewScript { + path: path.clone(), + parent_hash: None, + summary: "auto-generated script from rust sdk | testing".into(), + description: "auto-generated script from rust sdk | testing".into(), + content: r#"//! Add dependencies in the following partial Cargo.toml manifest +//! +//! ```cargo +//! [dependencies] +//! anyhow = "1.0.86" +//! rand = "0.7.2" +//! wmill = { path = "" } +//! ``` +//! +//! Note that serde is used by default with the `derive` feature. +//! You can still reimport it if you need additional features. + +use anyhow::anyhow; +use rand::seq::SliceRandom; +use wmill::Windmill; +use serde::Serialize; + +fn main() -> anyhow::Result { + let wm = Windmill::default()?; + + // Resources + let inp = serde_json::json!({ + "token": "token", + "baseUrl": "url" + }); + + wm.set_resource(Some(inp.clone()), "f/tests/delete_me_test_matrix", "matrix")?; + let out = wm.get_resource_any("f/tests/delete_me_test_matrix")?; + assert_eq!(inp, out); + + // States + let inp = serde_json::json!({ "foo": 2 }); + wm.set_state(Some(inp.clone()))?; + let out = wm.get_state_any()?; + assert_eq!(inp, out); + + // Variables + let inp = "Foo".to_owned(); + wm.set_variable(inp.clone(), "f/tests/my_test_var", false)?; + let out = wm.get_variable_raw("f/tests/my_test_var")?; + assert_eq!(inp, out); + + Ok(0) +} + "# + .replace( + "", + std::env::current_dir() + .expect("Failed to get current directory") + .to_str() + .expect("Failed to parse current directory"), + ) + .into(), + schema: None, + is_template: None, + lock: None, + language: windmill_api::models::ScriptLang::Rust, + kind: Some(windmill_api::models::new_script::Kind::Script), + tag: Some("rust".into()), + draft_only: None, + envs: None, + concurrent_limit: None, + concurrency_time_window_s: None, + cache_ttl: None, + dedicated_worker: None, + ws_error_handler_muted: None, + priority: None, + restart_unless_cancelled: None, + timeout: None, + delete_after_use: None, + deployment_message: None, + concurrency_key: None, + visible_to_runner_only: None, + no_main_func: None, + codebase: None, + has_preprocessor: None, + on_behalf_of_email: None, + }, + )) + .unwrap(); + + assert_eq!( + json!(0), + wm.run_script_sync( + // + &resp, + true, + json!(null), + None, + None, + true, + false, + ) + .unwrap() + ); +} + +// ASYNC TESTS +#[cfg(feature = "async")] +#[tokio::test] +async fn simple() { + let wm = wm(); + let path = format!("f/tests/delete_me_{}", Uuid::new_v4()); + + // Create new + wm.set_variable( + ":0".into(), + &path, + // TODO: Test with true + false, + ) + .await + .unwrap(); + + let resp = wm + .call_api(apis::script_api::create_script( + &wm.client_config, + &wm.workspace, + windmill_api::models::NewScript { + path: path.clone(), + parent_hash: None, + summary: "auto-generated script from rust sdk | testing".into(), + description: "auto-generated script from rust sdk | testing".into(), + content: r#"fn main() -> Result { Ok("Hello World!".to_owned()) }"# + .into(), + schema: None, + is_template: None, + lock: None, + language: windmill_api::models::ScriptLang::Rust, + kind: Some(windmill_api::models::new_script::Kind::Script), + tag: Some("rust".into()), + draft_only: None, + envs: None, + concurrent_limit: None, + concurrency_time_window_s: None, + cache_ttl: None, + dedicated_worker: None, + ws_error_handler_muted: None, + priority: None, + restart_unless_cancelled: None, + timeout: None, + delete_after_use: None, + deployment_message: None, + concurrency_key: None, + visible_to_runner_only: None, + no_main_func: None, + codebase: None, + has_preprocessor: None, + on_behalf_of_email: None, + }, + )) + .await + .unwrap(); + + assert_eq!( + json!("Hello World!"), + wm.run_script_sync( + // + &resp, + true, + json!(null), + None, + None, + true, + false, + ) + .await + .unwrap() + ); +}