Skip to main content

taskfast_client/
lib.rs

1// SPDX-License-Identifier: MIT
2//! TaskFast typed HTTP client.
3//!
4//! The `api` module is generated from `spec/openapi.yaml` at build time by
5//! `build.rs`. The rewritten spec (error-alias folding) is produced in-memory
6//! via `xtask::normalize_spec` so the on-disk spec stays authoritative.
7//!
8//! Use [`api::Client`] to issue requests; cross-cutting concerns
9//! ([`errors::Error`], [`retry::with_backoff`]) live in sibling modules and
10//! will be composed over the generated client in a follow-up.
11
12pub mod client;
13pub mod corr;
14pub mod errors;
15pub mod retry;
16
17pub use client::{
18    map_api_error, put_presigned_upload, ArtifactUpload, NetworkConfigEntry, NetworkConfigResponse,
19    TaskFastClient, UserProfile,
20};
21// `record_corr` is referenced by the generated client as `crate::record_corr`
22// (wired as progenitor's post-hook in build.rs), so it must live at the root.
23pub use corr::{record_corr, record_corr_response, take_last_corr};
24pub use errors::{Error, Result};
25pub use retry::{with_backoff, RetryPolicy};
26
27/// Re-exported so downstream crates can call the generated client's
28/// `baseurl()` / `client()` accessors — progenitor 0.11+ moved them off the
29/// inherent impl into this trait, which must be in scope at the call site.
30pub use progenitor_client::ClientInfo;
31
32/// Convert an `i64` page limit (as parsed from the CLI) into the
33/// `Option<NonZeroU64>` the generated client now requires: progenitor 0.14 /
34/// typify encodes the spec's `minimum: 1` in the type. Non-positive limits
35/// map to `None`, letting the server apply its default page size.
36pub fn page_limit(n: i64) -> Option<std::num::NonZeroU64> {
37    u64::try_from(n).ok().and_then(std::num::NonZeroU64::new)
38}
39
40#[cfg(test)]
41mod tests {
42    /// typify matches schema→type conversions by exact `SchemaObject`
43    /// equality, so a spec date that grows an extra constraint silently
44    /// reverts to chrono; this pins the gh#235 migration.
45    #[test]
46    fn generated_client_maps_dates_to_jiff() {
47        let codegen = std::fs::read_to_string(env!("TASKFAST_CODEGEN_PATH")).unwrap();
48        assert!(
49            !codegen.contains("chrono::"),
50            "generated client drifted back to chrono (gh#235)"
51        );
52        assert!(codegen.contains("::jiff::Timestamp"));
53        assert!(codegen.contains("::jiff::civil::Date"));
54    }
55}
56
57/// Generated typed client + DTOs for the TaskFast OpenAPI spec.
58///
59/// Produced by `progenitor` from `spec/openapi.yaml` at build time; see
60/// `build.rs` and `xtask::normalize_spec`. Do not edit by hand — regenerate
61/// by changing the spec.
62#[allow(
63    clippy::all,
64    clippy::pedantic,
65    dead_code,
66    irrefutable_let_patterns,
67    missing_docs,
68    non_camel_case_types,
69    non_snake_case,
70    renamed_and_removed_lints,
71    unknown_lints,
72    rustdoc::broken_intra_doc_links,
73    rustdoc::invalid_html_tags
74)]
75pub mod api {
76    include!(concat!(env!("OUT_DIR"), "/codegen.rs"));
77}