use crate::endpoints::workerskv::WorkersKvBulkResult;
use crate::framework::endpoint::{EndpointSpec, Method, RequestBody};
use crate::framework::response::ApiSuccess;
#[derive(Debug)]
pub struct DeleteBulk<'a> {
pub account_identifier: &'a str,
pub namespace_identifier: &'a str,
pub bulk_keys: Vec<String>,
}
impl EndpointSpec for DeleteBulk<'_> {
type JsonResponse = WorkersKvBulkResult;
type ResponseType = ApiSuccess<Self::JsonResponse>;
fn method(&self) -> Method {
Method::DELETE
}
fn path(&self) -> String {
format!(
"accounts/{}/storage/kv/namespaces/{}/bulk",
self.account_identifier, self.namespace_identifier
)
}
#[inline]
fn body(&self) -> Option<RequestBody> {
if self.bulk_keys.len() > 10_000 {
panic!("Bulk delete request can only contain up to 10,000 keys.");
}
let body = serde_json::to_string(&self.bulk_keys).unwrap();
Some(RequestBody::Json(body))
}
}