cdp-driver 0.5.0

Chrome DevTools Protocol (CDP) client for Rust: every command, event and type generated from the schema, with sessions, for browser automation and AI agents
Documentation
// @generated by `just generate-methods` from protocol/*.json.
// Do not edit by hand; edit xtask/ and regenerate.

//! The `CacheStorage` domain.
//!
//! Types, command parameters and event payloads for the `CacheStorage`
//! domain. The method-name constants for the same domain are in
//! [`crate::methods`].
//!
//! This domain is experimental and may change without notice.

use serde::{Deserialize, Serialize};

/// Unique identifier of the Cache object.
pub type CacheId = String;

/// type of HTTP response cached
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum CachedResponseType {
    /// `basic`
    #[serde(rename = "basic")]
    Basic,
    /// `cors`
    #[serde(rename = "cors")]
    Cors,
    /// `default`
    #[serde(rename = "default")]
    Default,
    /// `error`
    #[serde(rename = "error")]
    Error,
    /// `opaqueResponse`
    #[serde(rename = "opaqueResponse")]
    OpaqueResponse,
    /// `opaqueRedirect`
    #[serde(rename = "opaqueRedirect")]
    OpaqueRedirect,
    /// A value this vendored schema does not list. Chrome adds values ahead of
    /// the published protocol, so an unrecognised one is kept as it arrived
    /// rather than failing the payload it came in.
    #[serde(untagged)]
    Unrecognized(String),
}

/// Data entry.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct DataEntry {
    /// Request URL.
    #[serde(rename = "requestURL")]
    pub request_url: String,
    /// Request method.
    #[serde(rename = "requestMethod")]
    pub request_method: String,
    /// Request headers
    #[serde(rename = "requestHeaders")]
    pub request_headers: Vec<Header>,
    /// Number of seconds since epoch.
    #[serde(rename = "responseTime")]
    pub response_time: f64,
    /// HTTP response status code.
    #[serde(rename = "responseStatus")]
    pub response_status: i64,
    /// HTTP response status text.
    #[serde(rename = "responseStatusText")]
    pub response_status_text: String,
    /// HTTP response type
    #[serde(rename = "responseType")]
    pub response_type: CachedResponseType,
    /// Response headers
    #[serde(rename = "responseHeaders")]
    pub response_headers: Vec<Header>,
}

/// Cache identifier.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct Cache {
    /// An opaque unique id of the cache.
    #[serde(rename = "cacheId")]
    pub cache_id: CacheId,
    /// Security origin of the cache.
    #[serde(rename = "securityOrigin")]
    pub security_origin: String,
    /// Storage key of the cache.
    #[serde(rename = "storageKey")]
    pub storage_key: String,
    /// Storage bucket of the cache.
    #[serde(
        rename = "storageBucket",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub storage_bucket: Option<crate::protocol::storage::StorageBucket>,
    /// The name of the cache.
    #[serde(rename = "cacheName")]
    pub cache_name: String,
}

#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct Header {
    pub name: String,
    pub value: String,
}

/// Cached response
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct CachedResponse {
    /// Entry content, base64-encoded. (Encoded as a base64 string when passed
    /// over JSON)
    pub body: String,
}

/// Deletes a cache.
///
/// Parameters of `CacheStorage.deleteCache`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct DeleteCacheParams {
    /// Id of cache for deletion.
    #[serde(rename = "cacheId")]
    pub cache_id: CacheId,
}

impl crate::typed::Command for DeleteCacheParams {
    const METHOD: &'static str = "CacheStorage.deleteCache";
    type Returns = crate::typed::NoReturns;
}

/// Deletes a cache entry.
///
/// Parameters of `CacheStorage.deleteEntry`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct DeleteEntryParams {
    /// Id of cache where the entry will be deleted.
    #[serde(rename = "cacheId")]
    pub cache_id: CacheId,
    /// URL spec of the request.
    pub request: String,
}

impl crate::typed::Command for DeleteEntryParams {
    const METHOD: &'static str = "CacheStorage.deleteEntry";
    type Returns = crate::typed::NoReturns;
}

/// Requests cache names.
///
/// Parameters of `CacheStorage.requestCacheNames`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct RequestCacheNamesParams {
    /// At least and at most one of securityOrigin, storageKey, storageBucket must
    /// be specified. Security origin.
    #[serde(
        rename = "securityOrigin",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub security_origin: Option<String>,
    /// Storage key.
    #[serde(
        rename = "storageKey",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub storage_key: Option<String>,
    /// Storage bucket. If not specified, it uses the default bucket.
    #[serde(
        rename = "storageBucket",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub storage_bucket: Option<crate::protocol::storage::StorageBucket>,
}

/// What `CacheStorage.requestCacheNames` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct RequestCacheNamesReturns {
    /// Caches for the security origin.
    pub caches: Vec<Cache>,
}

impl crate::typed::Command for RequestCacheNamesParams {
    const METHOD: &'static str = "CacheStorage.requestCacheNames";
    type Returns = RequestCacheNamesReturns;
}

/// Fetches cache entry.
///
/// Parameters of `CacheStorage.requestCachedResponse`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct RequestCachedResponseParams {
    /// Id of cache that contains the entry.
    #[serde(rename = "cacheId")]
    pub cache_id: CacheId,
    /// URL spec of the request.
    #[serde(rename = "requestURL")]
    pub request_url: String,
    /// headers of the request.
    #[serde(rename = "requestHeaders")]
    pub request_headers: Vec<Header>,
}

/// What `CacheStorage.requestCachedResponse` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct RequestCachedResponseReturns {
    /// Response read from the cache.
    pub response: CachedResponse,
}

impl crate::typed::Command for RequestCachedResponseParams {
    const METHOD: &'static str = "CacheStorage.requestCachedResponse";
    type Returns = RequestCachedResponseReturns;
}

/// Requests data from cache.
///
/// Parameters of `CacheStorage.requestEntries`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct RequestEntriesParams {
    /// ID of cache to get entries from.
    #[serde(rename = "cacheId")]
    pub cache_id: CacheId,
    /// Number of records to skip.
    #[serde(rename = "skipCount", default, skip_serializing_if = "Option::is_none")]
    pub skip_count: Option<i64>,
    /// Number of records to fetch.
    #[serde(rename = "pageSize", default, skip_serializing_if = "Option::is_none")]
    pub page_size: Option<i64>,
    /// If present, only return the entries containing this substring in the path
    #[serde(
        rename = "pathFilter",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub path_filter: Option<String>,
}

/// What `CacheStorage.requestEntries` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct RequestEntriesReturns {
    /// Array of object store data entries.
    #[serde(rename = "cacheDataEntries")]
    pub cache_data_entries: Vec<DataEntry>,
    /// Count of returned entries from this storage. If pathFilter is empty, it is
    /// the count of all entries from this storage.
    #[serde(rename = "returnCount")]
    pub return_count: f64,
}

impl crate::typed::Command for RequestEntriesParams {
    const METHOD: &'static str = "CacheStorage.requestEntries";
    type Returns = RequestEntriesReturns;
}