diff --git a/sdk/data_cosmos/examples/attachments_00.rs b/sdk/data_cosmos/examples/attachments_00.rs index 8f4a0dc139..49b4dc17d7 100644 --- a/sdk/data_cosmos/examples/attachments_00.rs +++ b/sdk/data_cosmos/examples/attachments_00.rs @@ -75,12 +75,12 @@ async fn main() -> Result<(), Box> { println!("creating"); let attachment_client = document_client.clone().into_attachment_client("myref06"); let resp = attachment_client - .create_reference() - .consistency_level(ret) - .execute( + .create_reference( "https://cdn.pixabay.com/photo/2020/01/11/09/30/abstract-background-4756987__340.jpg", "image/jpeg", ) + .consistency_level(ret) + .into_future() .await?; println!("create reference == {:#?}", resp); @@ -91,7 +91,7 @@ async fn main() -> Result<(), Box> { let resp = attachment_client .get() .consistency_level(session_token) - .execute() + .into_future() .await?; println!("get attachment == {:#?}", resp); @@ -113,7 +113,7 @@ async fn main() -> Result<(), Box> { let resp_delete = attachment_client .delete() .consistency_level(&resp) - .execute() + .into_future() .await?; println!("delete attachment == {:#?}", resp_delete); @@ -121,10 +121,10 @@ async fn main() -> Result<(), Box> { println!("creating slug attachment"); let attachment_client = document_client.into_attachment_client("slug00".to_owned()); let resp = attachment_client - .create_slug() + .create_slug("FFFFF".into()) .consistency_level(&resp_delete) .content_type("text/plain") - .execute("FFFFF") + .into_future() .await?; println!("create slug == {:#?}", resp); @@ -133,7 +133,7 @@ async fn main() -> Result<(), Box> { let resp_delete = attachment_client .delete() .consistency_level(&resp) - .execute() + .into_future() .await?; println!("delete attachment == {:#?}", resp_delete); diff --git a/sdk/data_cosmos/examples/trigger_00.rs b/sdk/data_cosmos/examples/trigger_00.rs index 58df2cb0b0..05939222a0 100644 --- a/sdk/data_cosmos/examples/trigger_00.rs +++ b/sdk/data_cosmos/examples/trigger_00.rs @@ -62,25 +62,25 @@ async fn main() -> Result<(), Box> { let trigger_client = collection_client.clone().into_trigger_client(trigger_name); let ret = trigger_client - .create_trigger() - .execute("something", TriggerType::Post, TriggerOperation::All) + .create_trigger("something", TriggerType::Post, TriggerOperation::All) + .into_future() .await?; - println!("Creeate response object:\n{:#?}", ret); + println!("Create response object:\n{:#?}", ret); let ret = trigger_client - .replace_trigger() + .replace_trigger(TRIGGER_BODY, TriggerType::Post, TriggerOperation::All) .consistency_level(ret) - .execute(TRIGGER_BODY, TriggerType::Post, TriggerOperation::All) + .into_future() .await?; println!("Replace response object:\n{:#?}", ret); let mut last_session_token: Option = None; - let stream = collection_client + let mut stream = collection_client .list_triggers() .max_item_count(3) - .consistency_level(&ret); - let mut stream = Box::pin(stream.stream()); + .consistency_level(&ret) + .into_stream(); while let Some(ret) = stream.next().await { let ret = ret.unwrap(); println!( @@ -93,7 +93,7 @@ async fn main() -> Result<(), Box> { let ret = trigger_client .delete_trigger() .consistency_level(last_session_token.unwrap()) - .execute() + .into_future() .await?; println!("Delete response object:\n{:#?}", ret); diff --git a/sdk/data_cosmos/examples/user_defined_function_00.rs b/sdk/data_cosmos/examples/user_defined_function_00.rs index b90ff2bb04..6bf4f03b4e 100644 --- a/sdk/data_cosmos/examples/user_defined_function_00.rs +++ b/sdk/data_cosmos/examples/user_defined_function_00.rs @@ -42,8 +42,8 @@ async fn main() -> Result<(), Box> { .into_user_defined_function_client("test15"); let ret = user_defined_function_client - .create_user_defined_function() - .execute("body") + .create_user_defined_function("body") + .into_future() .await?; println!("Creeate response object:\n{:#?}", ret); @@ -61,9 +61,9 @@ async fn main() -> Result<(), Box> { } let ret = user_defined_function_client - .replace_user_defined_function() + .replace_user_defined_function(FN_BODY) .consistency_level(&ret) - .execute(FN_BODY) + .into_future() .await?; println!("Replace response object:\n{:#?}", ret); @@ -95,7 +95,7 @@ async fn main() -> Result<(), Box> { let ret = user_defined_function_client .delete_user_defined_function() .consistency_level(&ret) - .execute() + .into_future() .await?; println!("Delete response object:\n{:#?}", ret); diff --git a/sdk/data_cosmos/src/clients/attachment_client.rs b/sdk/data_cosmos/src/clients/attachment_client.rs index 6fdcdb7043..fddc875199 100644 --- a/sdk/data_cosmos/src/clients/attachment_client.rs +++ b/sdk/data_cosmos/src/clients/attachment_client.rs @@ -1,7 +1,11 @@ +use crate::operations::*; use crate::requests; use crate::resources::ResourceType; use crate::ReadonlyString; use azure_core::HttpClient; +use azure_core::Pipeline; +use azure_core::Request; +use bytes::Bytes; use super::*; @@ -50,28 +54,36 @@ impl AttachmentClient { } /// Initiate a request to get an attachment. - pub fn get(&self) -> requests::GetAttachmentBuilder<'_, '_> { - requests::GetAttachmentBuilder::new(self) + pub fn get(&self) -> GetAttachmentBuilder { + GetAttachmentBuilder::new(self.clone()) } /// Initiate a request to delete an attachment. - pub fn delete(&self) -> requests::DeleteAttachmentBuilder<'_, '_> { - requests::DeleteAttachmentBuilder::new(self) + pub fn delete(&self) -> DeleteAttachmentBuilder { + DeleteAttachmentBuilder::new(self.clone()) } /// Initiate a request to create an attachment with a slug. - pub fn create_slug(&self) -> requests::CreateSlugAttachmentBuilder<'_, '_> { - requests::CreateSlugAttachmentBuilder::new(self) + pub fn create_slug(&self, body: Bytes) -> CreateOrReplaceSlugAttachmentBuilder { + CreateOrReplaceSlugAttachmentBuilder::new(self.clone(), true, body) } /// Initiate a request to replace an attachment. - pub fn replace_slug(&self) -> requests::ReplaceSlugAttachmentBuilder<'_, '_> { - requests::ReplaceSlugAttachmentBuilder::new(self) + pub fn replace_slug(&self, body: Bytes) -> CreateOrReplaceSlugAttachmentBuilder { + CreateOrReplaceSlugAttachmentBuilder::new(self.clone(), false, body) } - /// Initiate a request to create an attachment. - pub fn create_reference(&self) -> requests::CreateReferenceAttachmentBuilder<'_, '_> { - requests::CreateReferenceAttachmentBuilder::new(self) + /// Initiate a request to create ant. + pub fn create_reference( + &self, + media: M, + content_type: C, + ) -> CreateReferenceAttachmentBuilder + where + M: Into, + C: Into, + { + CreateReferenceAttachmentBuilder::new(self.clone(), media.into(), content_type.into()) } /// Initiate a request to replace an attachment. @@ -84,8 +96,8 @@ impl AttachmentClient { self.cosmos_client().http_client() } - pub(crate) fn prepare_request(&self, method: http::Method) -> http::request::Builder { - self.cosmos_client().prepare_request( + pub(crate) fn prepare_pipeline(&self, method: http::Method) -> Request { + self.cosmos_client().prepare_request_pipeline( &format!( "dbs/{}/colls/{}/docs/{}/attachments", self.database_client().database_name(), @@ -93,7 +105,6 @@ impl AttachmentClient { self.document_client().document_name(), ), method, - ResourceType::Attachments, ) } @@ -113,4 +124,21 @@ impl AttachmentClient { ResourceType::Attachments, ) } + + pub(crate) fn prepare_pipeline_with_attachment_name(&self, method: http::Method) -> Request { + self.cosmos_client().prepare_request_pipeline( + &format!( + "dbs/{}/colls/{}/docs/{}/attachments/{}", + self.database_client().database_name(), + self.collection_client().collection_name(), + self.document_client().document_name(), + self.attachment_name() + ), + method, + ) + } + + pub(crate) fn pipeline(&self) -> &Pipeline { + self.cosmos_client().pipeline() + } } diff --git a/sdk/data_cosmos/src/clients/collection_client.rs b/sdk/data_cosmos/src/clients/collection_client.rs index 1a1cba3452..7db94bfb05 100644 --- a/sdk/data_cosmos/src/clients/collection_client.rs +++ b/sdk/data_cosmos/src/clients/collection_client.rs @@ -89,8 +89,8 @@ impl CollectionClient { } /// list triggers in a collection - pub fn list_triggers(&self) -> requests::ListTriggersBuilder<'_, '_> { - requests::ListTriggersBuilder::new(self) + pub fn list_triggers(&self) -> ListTriggersBuilder { + ListTriggersBuilder::new(self.clone()) } /// list the partition key ranges in a collection diff --git a/sdk/data_cosmos/src/clients/trigger_client.rs b/sdk/data_cosmos/src/clients/trigger_client.rs index e98b9013c8..71463704c1 100644 --- a/sdk/data_cosmos/src/clients/trigger_client.rs +++ b/sdk/data_cosmos/src/clients/trigger_client.rs @@ -1,7 +1,8 @@ use super::*; -use crate::resources::ResourceType; -use crate::{requests, ReadonlyString}; -use azure_core::HttpClient; +use crate::operations::*; +use crate::resources::trigger::{TriggerOperation, TriggerType}; +use crate::ReadonlyString; +use azure_core::{Pipeline, Request}; /// A client for Cosmos trigger resources. #[derive(Debug, Clone)] @@ -43,29 +44,54 @@ impl TriggerClient { } /// Create a trigger - pub fn create_trigger(&self) -> requests::CreateOrReplaceTriggerBuilder<'_> { - requests::CreateOrReplaceTriggerBuilder::new(self, true) + pub fn create_trigger( + &self, + body: B, + trigger_type: T, + trigger_operation: O, + ) -> CreateOrReplaceTriggerBuilder + where + B: Into, + T: Into, + O: Into, + { + CreateOrReplaceTriggerBuilder::new( + self.clone(), + true, + body.into(), + trigger_type.into(), + trigger_operation.into(), + ) } /// Replace a trigger - pub fn replace_trigger(&self) -> requests::CreateOrReplaceTriggerBuilder<'_> { - requests::CreateOrReplaceTriggerBuilder::new(self, false) + pub fn replace_trigger( + &self, + body: B, + trigger_type: T, + trigger_operation: O, + ) -> CreateOrReplaceTriggerBuilder + where + B: Into, + T: Into, + O: Into, + { + CreateOrReplaceTriggerBuilder::new( + self.clone(), + false, + body.into(), + trigger_type.into(), + trigger_operation.into(), + ) } /// Delete a trigger - pub fn delete_trigger(&self) -> requests::DeleteTriggerBuilder<'_, '_> { - requests::DeleteTriggerBuilder::new(self) + pub fn delete_trigger(&self) -> DeleteTriggerBuilder { + DeleteTriggerBuilder::new(self.clone()) } - pub(crate) fn http_client(&self) -> &dyn HttpClient { - self.cosmos_client().http_client() - } - - pub(crate) fn prepare_request_with_trigger_name( - &self, - method: http::Method, - ) -> http::request::Builder { - self.cosmos_client().prepare_request( + pub(crate) fn prepare_pipeline_with_trigger_name(&self, method: http::Method) -> Request { + self.cosmos_client().prepare_request_pipeline( &format!( "dbs/{}/colls/{}/triggers/{}", self.database_client().database_name(), @@ -73,19 +99,21 @@ impl TriggerClient { self.trigger_name() ), method, - ResourceType::Triggers, ) } - pub(crate) fn prepare_request(&self, method: http::Method) -> http::request::Builder { - self.cosmos_client().prepare_request( + pub(crate) fn prepare_pipeline(&self, method: http::Method) -> Request { + self.cosmos_client().prepare_request_pipeline( &format!( "dbs/{}/colls/{}/triggers", self.database_client().database_name(), self.collection_client().collection_name(), ), method, - ResourceType::Triggers, ) } + + pub(crate) fn pipeline(&self) -> &Pipeline { + self.cosmos_client().pipeline() + } } diff --git a/sdk/data_cosmos/src/clients/user_defined_function_client.rs b/sdk/data_cosmos/src/clients/user_defined_function_client.rs index 87db7a410a..93a9cc9eb6 100644 --- a/sdk/data_cosmos/src/clients/user_defined_function_client.rs +++ b/sdk/data_cosmos/src/clients/user_defined_function_client.rs @@ -1,7 +1,7 @@ use super::*; -use crate::resources::ResourceType; -use crate::{requests, ReadonlyString}; -use azure_core::HttpClient; +use crate::operations::*; +use crate::ReadonlyString; +use azure_core::{Pipeline, Request}; /// A client for Cosmos user defined function resources. #[derive(Debug, Clone)] @@ -42,43 +42,48 @@ impl UserDefinedFunctionClient { } /// Create the user defined function - pub fn create_user_defined_function( + pub fn create_user_defined_function( &self, - ) -> requests::CreateOrReplaceUserDefinedFunctionBuilder<'_, '_> { - requests::CreateOrReplaceUserDefinedFunctionBuilder::new(self, true) + body: B, + ) -> CreateOrReplaceUserDefinedFunctionBuilder + where + B: Into, + { + CreateOrReplaceUserDefinedFunctionBuilder::new(self.clone(), true, body.into()) } /// Replace the user defined function - pub fn replace_user_defined_function( + pub fn replace_user_defined_function( &self, - ) -> requests::CreateOrReplaceUserDefinedFunctionBuilder<'_, '_> { - requests::CreateOrReplaceUserDefinedFunctionBuilder::new(self, false) + body: B, + ) -> CreateOrReplaceUserDefinedFunctionBuilder + where + B: Into, + { + CreateOrReplaceUserDefinedFunctionBuilder::new(self.clone(), false, body.into()) } /// Delete the user defined function - pub fn delete_user_defined_function( - &self, - ) -> requests::DeleteUserDefinedFunctionBuilder<'_, '_> { - requests::DeleteUserDefinedFunctionBuilder::new(self) + pub fn delete_user_defined_function(&self) -> DeleteUserDefinedFunctionBuilder { + DeleteUserDefinedFunctionBuilder::new(self.clone()) } - pub(crate) fn prepare_request(&self, method: http::Method) -> http::request::Builder { - self.cosmos_client().prepare_request( + pub(crate) fn prepare_pipeline(&self, method: http::Method) -> Request { + self.cosmos_client().prepare_request_pipeline( &format!( "dbs/{}/colls/{}/udfs", self.database_client().database_name(), self.collection_client().collection_name(), ), method, - ResourceType::UserDefinedFunctions, ) } - pub(crate) fn prepare_request_with_user_defined_function_name( + pub(crate) fn prepare_pipeline_with_user_defined_function_name( &self, method: http::Method, - ) -> http::request::Builder { - self.cosmos_client().prepare_request( + ) -> Request { + self.cosmos_client().prepare_request_pipeline( &format!( "dbs/{}/colls/{}/udfs/{}", self.database_client().database_name(), @@ -86,11 +91,11 @@ impl UserDefinedFunctionClient { self.user_defined_function_name() ), method, - ResourceType::UserDefinedFunctions, ) } - pub(crate) fn http_client(&self) -> &dyn HttpClient { - self.cosmos_client().http_client() + /// Get a [`Pipeline`] + pub(crate) fn pipeline(&self) -> &Pipeline { + self.cosmos_client().pipeline() } } diff --git a/sdk/data_cosmos/src/consistency_level.rs b/sdk/data_cosmos/src/consistency_level.rs index 72f300a8e3..db02581653 100644 --- a/sdk/data_cosmos/src/consistency_level.rs +++ b/sdk/data_cosmos/src/consistency_level.rs @@ -64,7 +64,7 @@ macro_rules! implement_from { }; } -implement_from!(CreateSlugAttachmentResponse); +implement_from!(CreateOrReplaceSlugAttachmentResponse); implement_from!(GetCollectionResponse); implement_from!(UserResponse); implement_from!(DeleteAttachmentResponse); @@ -75,10 +75,10 @@ implement_from!(GetAttachmentResponse); implement_from!(CreateDocumentResponse); implement_from!(ReplaceDocumentResponse); implement_from!(DeleteDocumentResponse); -implement_from!(CreateUserDefinedFunctionResponse); +implement_from!(CreateOrReplaceUserDefinedFunctionResponse); implement_from!(DeleteUserDefinedFunctionResponse); implement_from!(ListUserDefinedFunctionsResponse); -implement_from!(CreateTriggerResponse); +implement_from!(CreateOrReplaceTriggerResponse); implement_from!(ListTriggersResponse); implement_from!(DeleteTriggerResponse); implement_from!(ListDocumentsResponse, T); diff --git a/sdk/data_cosmos/src/operations/create_or_replace_slug_attachment.rs b/sdk/data_cosmos/src/operations/create_or_replace_slug_attachment.rs new file mode 100644 index 0000000000..7f8a80acb0 --- /dev/null +++ b/sdk/data_cosmos/src/operations/create_or_replace_slug_attachment.rs @@ -0,0 +1,166 @@ +use crate::headers::from_headers::*; +use crate::prelude::*; +use crate::resources::Attachment; +use crate::ResourceQuota; + +use azure_core::collect_pinned_stream; +use azure_core::headers::{etag_from_headers, session_token_from_headers}; +use azure_core::prelude::*; +use azure_core::Response as HttpResponse; +use azure_core::SessionToken; +use bytes::Bytes; +use chrono::{DateTime, Utc}; + +#[derive(Debug, Clone)] +pub struct CreateOrReplaceSlugAttachmentBuilder { + client: AttachmentClient, + is_create: bool, + body: Bytes, + if_match_condition: Option, + consistency_level: Option, + content_type: Option, + context: Context, +} + +impl CreateOrReplaceSlugAttachmentBuilder { + pub(crate) fn new(client: AttachmentClient, is_create: bool, body: Bytes) -> Self { + Self { + client, + is_create, + body, + if_match_condition: None, + consistency_level: None, + content_type: None, + context: Context::new(), + } + } +} + +impl CreateOrReplaceSlugAttachmentBuilder { + setters! { + consistency_level: ConsistencyLevel => Some(consistency_level), + if_match_condition: IfMatchCondition => Some(if_match_condition), + content_type: String => Some(content_type), + context: Context => context, + } + + pub fn into_future(self) -> CreateOrReplaceSlugAttachment { + Box::pin(async move { + let mut req = if self.is_create { + self.client.prepare_pipeline(http::Method::POST) + } else { + self.client + .prepare_pipeline_with_attachment_name(http::Method::PUT) + }; + + azure_core::headers::add_optional_header2(&self.if_match_condition, &mut req)?; + azure_core::headers::add_optional_header2(&self.consistency_level, &mut req)?; + + crate::cosmos_entity::add_as_partition_key_header_serialized2( + self.client.document_client().partition_key_serialized(), + &mut req, + ); + let body = self.body; + req.headers_mut().insert( + http::header::CONTENT_TYPE, + http::HeaderValue::from_str(self.content_type.as_deref().unwrap_or("text/plain")) + .unwrap(), + ); + + req.headers_mut().insert( + "Slug", + http::HeaderValue::from_str(self.client.attachment_name()).unwrap(), + ); + req.headers_mut().insert( + http::header::CONTENT_LENGTH, + http::HeaderValue::from_str(&format!("{}", body.len())).unwrap(), + ); + + req.set_body(body.into()); + let response = self + .client + .pipeline() + .send( + self.context.clone().insert(ResourceType::Attachments), + &mut req, + ) + .await?; + + CreateOrReplaceSlugAttachmentResponse::try_from(response).await + }) + } +} +/// The future returned by calling `into_future` on the builder. +pub type CreateOrReplaceSlugAttachment = + futures::future::BoxFuture<'static, crate::Result>; + +#[cfg(feature = "into_future")] +impl std::future::IntoFuture for CreateOrReplaceSlugAttachmentBuilder { + type Future = CreateOrReplaceSlugAttachment; + type Output = ::Output; + fn into_future(self) -> Self::Future { + Self::into_future(self) + } +} + +#[derive(Debug, Clone, PartialEq)] +pub struct CreateOrReplaceSlugAttachmentResponse { + pub attachment: Attachment, + pub max_media_storage_usage_mb: u64, + pub media_storage_usage_mb: u64, + pub last_change: DateTime, + pub etag: String, + pub resource_quota: Vec, + pub resource_usage: Vec, + pub lsn: u64, + pub alt_content_path: String, + pub quorum_acked_lsn: u64, + pub current_write_quorum: u64, + pub current_replica_set_size: u64, + pub global_committed_lsn: u64, + pub number_of_read_regions: u32, + pub transport_request_id: u64, + pub cosmos_llsn: u64, + pub cosmos_quorum_acked_llsn: u64, + pub session_token: SessionToken, + pub request_charge: f64, + pub service_version: String, + pub activity_id: uuid::Uuid, + pub gateway_version: String, + pub date: DateTime, +} + +impl CreateOrReplaceSlugAttachmentResponse { + pub async fn try_from(response: HttpResponse) -> crate::Result { + let (_status_code, headers, pinned_stream) = response.deconstruct(); + let body = collect_pinned_stream(pinned_stream).await?; + + let attachment: Attachment = serde_json::from_slice(&body)?; + + Ok(Self { + attachment, + max_media_storage_usage_mb: max_media_storage_usage_mb_from_headers(&headers)?, + media_storage_usage_mb: media_storage_usage_mb_from_headers(&headers)?, + last_change: last_state_change_from_headers(&headers)?, + etag: etag_from_headers(&headers)?, + resource_quota: resource_quota_from_headers(&headers)?, + resource_usage: resource_usage_from_headers(&headers)?, + lsn: lsn_from_headers(&headers)?, + alt_content_path: alt_content_path_from_headers(&headers)?.to_owned(), + quorum_acked_lsn: quorum_acked_lsn_from_headers(&headers)?, + current_write_quorum: current_write_quorum_from_headers(&headers)?, + current_replica_set_size: current_replica_set_size_from_headers(&headers)?, + global_committed_lsn: global_committed_lsn_from_headers(&headers)?, + number_of_read_regions: number_of_read_regions_from_headers(&headers)?, + transport_request_id: transport_request_id_from_headers(&headers)?, + cosmos_llsn: cosmos_llsn_from_headers(&headers)?, + cosmos_quorum_acked_llsn: cosmos_quorum_acked_llsn_from_headers(&headers)?, + session_token: session_token_from_headers(&headers)?, + request_charge: request_charge_from_headers(&headers)?, + service_version: service_version_from_headers(&headers)?.to_owned(), + activity_id: activity_id_from_headers(&headers)?, + gateway_version: gateway_version_from_headers(&headers)?.to_owned(), + date: date_from_headers(&headers)?, + }) + } +} diff --git a/sdk/data_cosmos/src/operations/create_or_replace_trigger.rs b/sdk/data_cosmos/src/operations/create_or_replace_trigger.rs new file mode 100644 index 0000000000..bfdcb0214b --- /dev/null +++ b/sdk/data_cosmos/src/operations/create_or_replace_trigger.rs @@ -0,0 +1,164 @@ +use crate::headers::from_headers::*; +use crate::prelude::*; +use crate::resources::trigger::*; +use crate::resources::Trigger; +use crate::ResourceQuota; +use azure_core::collect_pinned_stream; +use azure_core::headers::{etag_from_headers, session_token_from_headers}; +use azure_core::prelude::*; +use azure_core::Response as HttpResponse; +use chrono::{DateTime, Utc}; + +#[derive(Debug, Clone)] +pub struct CreateOrReplaceTriggerBuilder { + client: TriggerClient, + is_create: bool, + body: String, + trigger_type: TriggerType, + trigger_operation: TriggerOperation, + consistency_level: Option, + context: Context, +} + +impl CreateOrReplaceTriggerBuilder { + pub(crate) fn new( + client: TriggerClient, + is_create: bool, + body: String, + trigger_type: TriggerType, + trigger_operation: TriggerOperation, + ) -> Self { + Self { + client, + is_create, + body, + trigger_operation, + trigger_type, + consistency_level: None, + context: Context::new(), + } + } + + setters! { + consistency_level: ConsistencyLevel => Some(consistency_level), + context: Context => context, + } + + pub fn into_future(self) -> CreateOrReplaceTrigger { + Box::pin(async move { + let mut request = if self.is_create { + self.client.prepare_pipeline(http::Method::POST) + } else { + self.client + .prepare_pipeline_with_trigger_name(http::Method::PUT) + }; + + azure_core::headers::add_optional_header2(&self.consistency_level, &mut request)?; + + #[derive(Debug, Deserialize, Serialize)] + struct Request<'a> { + pub id: &'a str, + #[serde(rename = "triggerOperation")] + pub trigger_operation: TriggerOperation, + #[serde(rename = "triggerType")] + pub trigger_type: TriggerType, + pub body: &'a str, + } + + let request_body = Request { + id: self.client.trigger_name(), + trigger_operation: self.trigger_operation, + trigger_type: self.trigger_type, + body: &self.body, + }; + + request.set_body(bytes::Bytes::from(serde_json::to_string(&request_body)?).into()); + let response = self + .client + .pipeline() + .send( + self.context.clone().insert(ResourceType::Triggers), + &mut request, + ) + .await?; + + CreateOrReplaceTriggerResponse::try_from(response).await + }) + } +} +/// The future returned by calling `into_future` on the builder. +pub type CreateOrReplaceTrigger = + futures::future::BoxFuture<'static, crate::Result>; + +#[cfg(feature = "into_future")] +impl std::future::IntoFuture for CreateOrReplaceTriggerBuilder { + type Future = CreateOrReplaceTrigger; + type Output = ::Output; + fn into_future(self) -> Self::Future { + Self::into_future(self) + } +} + +#[derive(Debug, Clone, PartialEq)] +pub struct CreateOrReplaceTriggerResponse { + pub trigger: Trigger, + pub server: String, + pub last_state_change: DateTime, + pub etag: String, + pub resource_quota: Vec, + pub resource_usage: Vec, + pub lsn: u64, + pub schema_version: String, + pub alt_content_path: String, + pub content_path: String, + pub quorum_acked_lsn: u64, + pub current_write_quorum: u64, + pub current_replica_set_size: u64, + pub role: u32, + pub global_committed_lsn: u64, + pub number_of_read_regions: u32, + pub transport_request_id: u64, + pub cosmos_llsn: u64, + pub cosmos_quorum_acked_llsn: u64, + pub session_token: String, + pub charge: f64, + pub service_version: String, + pub activity_id: uuid::Uuid, + pub gateway_version: String, + pub date: DateTime, +} + +impl CreateOrReplaceTriggerResponse { + pub async fn try_from(response: HttpResponse) -> crate::Result { + let (_status_code, headers, pinned_stream) = response.deconstruct(); + let body = collect_pinned_stream(pinned_stream).await?; + + Ok(Self { + trigger: serde_json::from_slice(&body)?, + server: server_from_headers(&headers)?.to_owned(), + last_state_change: last_state_change_from_headers(&headers)?, + etag: etag_from_headers(&headers)?, + resource_quota: resource_quota_from_headers(&headers)?, + resource_usage: resource_usage_from_headers(&headers)?, + lsn: lsn_from_headers(&headers)?, + schema_version: schema_version_from_headers(&headers)?.to_owned(), + alt_content_path: alt_content_path_from_headers(&headers)?.to_owned(), + content_path: content_path_from_headers(&headers)?.to_owned(), + quorum_acked_lsn: quorum_acked_lsn_from_headers(&headers)?, + current_write_quorum: current_write_quorum_from_headers(&headers)?, + current_replica_set_size: current_replica_set_size_from_headers(&headers)?, + role: role_from_headers(&headers)?, + global_committed_lsn: global_committed_lsn_from_headers(&headers)?, + number_of_read_regions: number_of_read_regions_from_headers(&headers)?, + transport_request_id: transport_request_id_from_headers(&headers)?, + cosmos_llsn: cosmos_llsn_from_headers(&headers)?, + cosmos_quorum_acked_llsn: cosmos_quorum_acked_llsn_from_headers(&headers)?, + session_token: session_token_from_headers(&headers)?, + charge: request_charge_from_headers(&headers)?, + service_version: service_version_from_headers(&headers)?.to_owned(), + activity_id: activity_id_from_headers(&headers)?, + gateway_version: gateway_version_from_headers(&headers)?.to_owned(), + date: date_from_headers(&headers)?, + }) + } +} diff --git a/sdk/data_cosmos/src/operations/create_or_replace_user_defined_function.rs b/sdk/data_cosmos/src/operations/create_or_replace_user_defined_function.rs new file mode 100644 index 0000000000..aaa6b59dd4 --- /dev/null +++ b/sdk/data_cosmos/src/operations/create_or_replace_user_defined_function.rs @@ -0,0 +1,146 @@ +use crate::headers::from_headers::*; +use crate::prelude::*; +use crate::resources::UserDefinedFunction; +use crate::ResourceQuota; + +use azure_core::headers::{etag_from_headers, session_token_from_headers}; +use azure_core::prelude::*; +use azure_core::{collect_pinned_stream, Response as HttpResponse}; +use chrono::{DateTime, Utc}; + +#[derive(Debug, Clone)] +pub struct CreateOrReplaceUserDefinedFunctionBuilder { + client: UserDefinedFunctionClient, + is_create: bool, + body: String, + consistency_level: Option, + context: Context, +} + +impl CreateOrReplaceUserDefinedFunctionBuilder { + pub(crate) fn new(client: UserDefinedFunctionClient, is_create: bool, body: String) -> Self { + Self { + client, + is_create, + body, + consistency_level: None, + context: Context::new(), + } + } + + setters! { + consistency_level: ConsistencyLevel => Some(consistency_level), + context: Context => context, + } + + pub fn into_future(self) -> CreateOrReplaceUserDefinedFunction { + Box::pin(async move { + let mut request = match self.is_create { + true => self.client.prepare_pipeline(http::Method::POST), + false => self + .client + .prepare_pipeline_with_user_defined_function_name(http::Method::PUT), + }; + + azure_core::headers::add_optional_header2(&self.consistency_level, &mut request)?; + + #[derive(Debug, Serialize)] + struct Request<'a> { + body: &'a str, + id: &'a str, + } + let request_body = Request { + body: &self.body, + id: self.client.user_defined_function_name(), + }; + request.set_body(bytes::Bytes::from(serde_json::to_string(&request_body)?).into()); + let response = self + .client + .pipeline() + .send( + self.context.clone().insert(ResourceType::Permissions), + &mut request, + ) + .await?; + + CreateOrReplaceUserDefinedFunctionResponse::try_from(response).await + }) + } +} + +/// The future returned by calling `into_future` on the builder. +pub type CreateOrReplaceUserDefinedFunction = + futures::future::BoxFuture<'static, crate::Result>; + +#[cfg(feature = "into_future")] +impl std::future::IntoFuture for CreateOrReplaceUserDefinedFunctionBuilder { + type Future = CreateOrReplaceUserDefinedFunction; + type Output = ::Output; + fn into_future(self) -> Self::Future { + Self::into_future(self) + } +} + +#[derive(Debug, Clone, PartialEq)] +pub struct CreateOrReplaceUserDefinedFunctionResponse { + pub user_defined_function: UserDefinedFunction, + pub server: String, + pub last_state_change: DateTime, + pub etag: String, + pub resource_quota: Vec, + pub resource_usage: Vec, + pub lsn: u64, + pub schema_version: String, + pub alt_content_path: String, + pub content_path: String, + pub quorum_acked_lsn: u64, + pub current_write_quorum: u64, + pub current_replica_set_size: u64, + pub role: u32, + pub global_committed_lsn: u64, + pub number_of_read_regions: u32, + pub transport_request_id: u64, + pub cosmos_llsn: u64, + pub cosmos_quorum_acked_llsn: u64, + pub session_token: String, + pub charge: f64, + pub service_version: String, + pub activity_id: uuid::Uuid, + pub gateway_version: String, + pub date: DateTime, +} + +impl CreateOrReplaceUserDefinedFunctionResponse { + pub async fn try_from(response: HttpResponse) -> crate::Result { + let (_status_code, headers, pinned_stream) = response.deconstruct(); + let body = collect_pinned_stream(pinned_stream).await?; + + Ok(Self { + user_defined_function: serde_json::from_slice(&body)?, + server: server_from_headers(&headers)?.to_owned(), + last_state_change: last_state_change_from_headers(&headers)?, + etag: etag_from_headers(&headers)?, + resource_quota: resource_quota_from_headers(&headers)?, + resource_usage: resource_usage_from_headers(&headers)?, + lsn: lsn_from_headers(&headers)?, + schema_version: schema_version_from_headers(&headers)?.to_owned(), + alt_content_path: alt_content_path_from_headers(&headers)?.to_owned(), + content_path: content_path_from_headers(&headers)?.to_owned(), + quorum_acked_lsn: quorum_acked_lsn_from_headers(&headers)?, + current_write_quorum: current_write_quorum_from_headers(&headers)?, + current_replica_set_size: current_replica_set_size_from_headers(&headers)?, + role: role_from_headers(&headers)?, + global_committed_lsn: global_committed_lsn_from_headers(&headers)?, + number_of_read_regions: number_of_read_regions_from_headers(&headers)?, + transport_request_id: transport_request_id_from_headers(&headers)?, + cosmos_llsn: cosmos_llsn_from_headers(&headers)?, + cosmos_quorum_acked_llsn: cosmos_quorum_acked_llsn_from_headers(&headers)?, + session_token: session_token_from_headers(&headers)?, + charge: request_charge_from_headers(&headers)?, + service_version: service_version_from_headers(&headers)?.to_owned(), + activity_id: activity_id_from_headers(&headers)?, + gateway_version: gateway_version_from_headers(&headers)?.to_owned(), + date: date_from_headers(&headers)?, + }) + } +} diff --git a/sdk/data_cosmos/src/operations/create_reference_attachment.rs b/sdk/data_cosmos/src/operations/create_reference_attachment.rs new file mode 100644 index 0000000000..d7604a2632 --- /dev/null +++ b/sdk/data_cosmos/src/operations/create_reference_attachment.rs @@ -0,0 +1,150 @@ +use crate::headers::from_headers::*; +use crate::prelude::*; +use crate::resources::Attachment; +use crate::ResourceQuota; + +use azure_core::headers::{etag_from_headers, session_token_from_headers}; +use azure_core::prelude::*; +use azure_core::SessionToken; +use azure_core::{collect_pinned_stream, Response as HttpResponse}; +use chrono::{DateTime, Utc}; + +#[derive(Debug, Clone)] +pub struct CreateReferenceAttachmentBuilder { + client: AttachmentClient, + media: String, + content_type: String, + consistency_level: Option, + context: Context, +} + +impl CreateReferenceAttachmentBuilder { + pub(crate) fn new(client: AttachmentClient, media: String, content_type: String) -> Self { + Self { + client, + media, + content_type, + consistency_level: None, + context: Context::new(), + } + } + setters! { + consistency_level: ConsistencyLevel => Some(consistency_level), + context: Context => context, + } + + pub fn into_future(self) -> CreateReferenceAttachment { + Box::pin(async move { + let mut req = self.client.prepare_pipeline(http::Method::POST); + + azure_core::headers::add_optional_header2(&self.consistency_level, &mut req)?; + crate::cosmos_entity::add_as_partition_key_header_serialized2( + self.client.document_client().partition_key_serialized(), + &mut req, + ); + + #[derive(Debug, Serialize)] + struct Request<'r> { + pub id: &'r str, + #[serde(rename = "contentType")] + pub content_type: &'r str, + pub media: &'r str, + } + + let body = azure_core::to_json(&Request { + id: self.client.attachment_name(), + content_type: &self.content_type, + media: &self.media, + })?; + + req.set_body(body.into()); + + let response = self + .client + .pipeline() + .send( + self.context.clone().insert(ResourceType::Attachments), + &mut req, + ) + .await?; + CreateReferenceAttachmentResponse::try_from(response).await + }) + } +} + +/// The future returned by calling `into_future` on the builder. +pub type CreateReferenceAttachment = + futures::future::BoxFuture<'static, crate::Result>; + +#[cfg(feature = "into_future")] +impl std::future::IntoFuture for CreateReferenceAttachmentBuilder { + type Future = CreateReferenceAttachment; + type Output = ::Output; + fn into_future(self) -> Self::Future { + Self::into_future(self) + } +} + +#[derive(Debug, Clone, PartialEq)] +pub struct CreateReferenceAttachmentResponse { + pub attachment: Attachment, + pub max_media_storage_usage_mb: u64, + pub media_storage_usage_mb: u64, + pub last_change: DateTime, + pub etag: String, + pub resource_quota: Vec, + pub resource_usage: Vec, + pub lsn: u64, + pub alt_content_path: String, + pub content_path: String, + pub quorum_acked_lsn: u64, + pub current_write_quorum: u64, + pub current_replica_set_size: u64, + pub global_committed_lsn: u64, + pub number_of_read_regions: u32, + pub transport_request_id: u64, + pub cosmos_llsn: u64, + pub cosmos_quorum_acked_llsn: u64, + pub session_token: SessionToken, + pub request_charge: f64, + pub service_version: String, + pub activity_id: uuid::Uuid, + pub gateway_version: String, + pub date: DateTime, +} + +impl CreateReferenceAttachmentResponse { + pub async fn try_from(response: HttpResponse) -> crate::Result { + let (_status_code, headers, pinned_stream) = response.deconstruct(); + let body = collect_pinned_stream(pinned_stream).await?; + + let attachment: Attachment = serde_json::from_slice(&body)?; + + Ok(Self { + attachment, + max_media_storage_usage_mb: max_media_storage_usage_mb_from_headers(&headers)?, + media_storage_usage_mb: media_storage_usage_mb_from_headers(&headers)?, + last_change: last_state_change_from_headers(&headers)?, + etag: etag_from_headers(&headers)?, + resource_quota: resource_quota_from_headers(&headers)?, + resource_usage: resource_usage_from_headers(&headers)?, + lsn: lsn_from_headers(&headers)?, + alt_content_path: alt_content_path_from_headers(&headers)?.to_owned(), + content_path: content_path_from_headers(&headers)?.to_owned(), + quorum_acked_lsn: quorum_acked_lsn_from_headers(&headers)?, + current_write_quorum: current_write_quorum_from_headers(&headers)?, + current_replica_set_size: current_replica_set_size_from_headers(&headers)?, + global_committed_lsn: global_committed_lsn_from_headers(&headers)?, + number_of_read_regions: number_of_read_regions_from_headers(&headers)?, + transport_request_id: transport_request_id_from_headers(&headers)?, + cosmos_llsn: cosmos_llsn_from_headers(&headers)?, + cosmos_quorum_acked_llsn: cosmos_quorum_acked_llsn_from_headers(&headers)?, + session_token: session_token_from_headers(&headers)?, + request_charge: request_charge_from_headers(&headers)?, + service_version: service_version_from_headers(&headers)?.to_owned(), + activity_id: activity_id_from_headers(&headers)?, + gateway_version: gateway_version_from_headers(&headers)?.to_owned(), + date: date_from_headers(&headers)?, + }) + } +} diff --git a/sdk/data_cosmos/src/responses/delete_attachment_response.rs b/sdk/data_cosmos/src/operations/delete_attachment.rs similarity index 53% rename from sdk/data_cosmos/src/responses/delete_attachment_response.rs rename to sdk/data_cosmos/src/operations/delete_attachment.rs index c418a55572..9e83b6b31d 100644 --- a/sdk/data_cosmos/src/responses/delete_attachment_response.rs +++ b/sdk/data_cosmos/src/operations/delete_attachment.rs @@ -1,9 +1,77 @@ use crate::headers::from_headers::*; +use crate::prelude::*; use crate::ResourceQuota; + use azure_core::headers::session_token_from_headers; +use azure_core::prelude::*; +use azure_core::Response as HttpResponse; use azure_core::SessionToken; use chrono::{DateTime, Utc}; -use http::response::Response; + +#[derive(Debug, Clone)] +pub struct DeleteAttachmentBuilder { + client: AttachmentClient, + if_match_condition: Option, + consistency_level: Option, + context: Context, +} + +impl DeleteAttachmentBuilder { + pub(crate) fn new(client: AttachmentClient) -> Self { + Self { + client, + if_match_condition: None, + consistency_level: None, + context: Context::new(), + } + } + + setters! { + consistency_level: ConsistencyLevel => Some(consistency_level), + if_match_condition: IfMatchCondition => Some(if_match_condition), + context: Context => context, + } + + pub fn into_future(self) -> DeleteAttachment { + Box::pin(async move { + let mut request = self + .client + .prepare_pipeline_with_attachment_name(http::Method::DELETE); + + // add trait headers + azure_core::headers::add_optional_header2(&self.if_match_condition, &mut request)?; + azure_core::headers::add_optional_header2(&self.consistency_level, &mut request)?; + + crate::cosmos_entity::add_as_partition_key_header_serialized2( + self.client.document_client().partition_key_serialized(), + &mut request, + ); + let response = self + .client + .pipeline() + .send( + self.context.clone().insert(ResourceType::Attachments), + &mut request, + ) + .await?; + + DeleteAttachmentResponse::try_from(response).await + }) + } +} + +/// The future returned by calling `into_future` on the builder. +pub type DeleteAttachment = + futures::future::BoxFuture<'static, crate::Result>; + +#[cfg(feature = "into_future")] +impl std::future::IntoFuture for DeleteAttachmentBuilder { + type Future = DeleteAttachment; + type Output = ::Output; + fn into_future(self) -> Self::Future { + Self::into_future(self) + } +} #[derive(Debug, Clone, PartialEq)] pub struct DeleteAttachmentResponse { @@ -31,15 +99,9 @@ pub struct DeleteAttachmentResponse { pub date: DateTime, } -impl std::convert::TryFrom> for DeleteAttachmentResponse { - type Error = crate::Error; - - fn try_from(response: Response) -> Result { +impl DeleteAttachmentResponse { + pub async fn try_from(response: HttpResponse) -> crate::Result { let headers = response.headers(); - let body = response.body(); - - debug!("headers == {:#?}", headers); - debug!("body == {:#?}", body); Ok(Self { max_media_storage_usage_mb: max_media_storage_usage_mb_from_headers(headers)?, diff --git a/sdk/data_cosmos/src/operations/delete_trigger.rs b/sdk/data_cosmos/src/operations/delete_trigger.rs new file mode 100644 index 0000000000..71c594f112 --- /dev/null +++ b/sdk/data_cosmos/src/operations/delete_trigger.rs @@ -0,0 +1,123 @@ +use crate::headers::from_headers::*; +use crate::prelude::*; +use crate::ResourceQuota; + +use azure_core::headers::session_token_from_headers; +use azure_core::prelude::*; +use azure_core::Response as HttpResponse; +use chrono::{DateTime, Utc}; + +#[derive(Debug, Clone)] +pub struct DeleteTriggerBuilder { + client: TriggerClient, + consistency_level: Option, + context: Context, +} + +impl DeleteTriggerBuilder { + pub(crate) fn new(client: TriggerClient) -> Self { + Self { + client, + consistency_level: None, + context: Context::new(), + } + } + + setters! { + consistency_level: ConsistencyLevel => Some(consistency_level), + context: Context => context, + } + + pub fn into_future(self) -> DeleteTrigger { + Box::pin(async move { + let mut request = self + .client + .prepare_pipeline_with_trigger_name(http::Method::DELETE); + + azure_core::headers::add_optional_header2(&self.consistency_level, &mut request)?; + + let response = self + .client + .pipeline() + .send( + self.context.clone().insert(ResourceType::Triggers), + &mut request, + ) + .await?; + + DeleteTriggerResponse::try_from(response).await + }) + } +} + +/// The future returned by calling `into_future` on the builder. +pub type DeleteTrigger = futures::future::BoxFuture<'static, crate::Result>; + +#[cfg(feature = "into_future")] +impl std::future::IntoFuture for DeleteTriggerBuilder { + type Future = DeleteTrigger; + type Output = ::Output; + fn into_future(self) -> Self::Future { + Self::into_future(self) + } +} + +#[derive(Debug, Clone, PartialEq)] +pub struct DeleteTriggerResponse { + pub content_location: String, + pub server: String, + pub last_state_change: DateTime, + pub resource_quota: Vec, + pub resource_usage: Vec, + pub lsn: u64, + pub schema_version: String, + pub alt_content_path: String, + pub content_path: String, + pub quorum_acked_lsn: u64, + pub current_write_quorum: u64, + pub current_replica_set_size: u64, + pub role: u32, + pub global_committed_lsn: u64, + pub number_of_read_regions: u32, + pub transport_request_id: u64, + pub cosmos_llsn: u64, + pub cosmos_quorum_acked_llsn: u64, + pub session_token: String, + pub charge: f64, + pub service_version: String, + pub activity_id: uuid::Uuid, + pub gateway_version: String, + pub date: DateTime, +} +impl DeleteTriggerResponse { + pub async fn try_from(response: HttpResponse) -> crate::Result { + let (_status_code, headers, _pinned_stream) = response.deconstruct(); + + Ok(Self { + content_location: content_location_from_headers(&headers)?.to_owned(), + server: server_from_headers(&headers)?.to_owned(), + last_state_change: last_state_change_from_headers(&headers)?, + resource_quota: resource_quota_from_headers(&headers)?, + resource_usage: resource_usage_from_headers(&headers)?, + lsn: lsn_from_headers(&headers)?, + schema_version: schema_version_from_headers(&headers)?.to_owned(), + alt_content_path: alt_content_path_from_headers(&headers)?.to_owned(), + content_path: content_path_from_headers(&headers)?.to_owned(), + quorum_acked_lsn: quorum_acked_lsn_from_headers(&headers)?, + current_write_quorum: current_write_quorum_from_headers(&headers)?, + current_replica_set_size: current_replica_set_size_from_headers(&headers)?, + role: role_from_headers(&headers)?, + global_committed_lsn: global_committed_lsn_from_headers(&headers)?, + number_of_read_regions: number_of_read_regions_from_headers(&headers)?, + transport_request_id: transport_request_id_from_headers(&headers)?, + cosmos_llsn: cosmos_llsn_from_headers(&headers)?, + cosmos_quorum_acked_llsn: cosmos_quorum_acked_llsn_from_headers(&headers)?, + session_token: session_token_from_headers(&headers)?, + charge: request_charge_from_headers(&headers)?, + service_version: service_version_from_headers(&headers)?.to_owned(), + activity_id: activity_id_from_headers(&headers)?, + gateway_version: gateway_version_from_headers(&headers)?.to_owned(), + date: date_from_headers(&headers)?, + }) + } +} diff --git a/sdk/data_cosmos/src/operations/delete_user_defined_function.rs b/sdk/data_cosmos/src/operations/delete_user_defined_function.rs new file mode 100644 index 0000000000..67d0c93ef9 --- /dev/null +++ b/sdk/data_cosmos/src/operations/delete_user_defined_function.rs @@ -0,0 +1,127 @@ +use crate::headers::from_headers::*; +use crate::prelude::*; +use crate::ResourceQuota; + +use azure_core::headers::session_token_from_headers; +use azure_core::prelude::*; +use azure_core::Response as HttpResponse; +use chrono::{DateTime, Utc}; + +#[derive(Debug, Clone)] +pub struct DeleteUserDefinedFunctionBuilder { + client: UserDefinedFunctionClient, + consistency_level: Option, + context: Context, +} + +impl DeleteUserDefinedFunctionBuilder { + pub(crate) fn new(client: UserDefinedFunctionClient) -> Self { + Self { + client, + consistency_level: None, + context: Context::new(), + } + } + + setters! { + consistency_level: ConsistencyLevel => Some(consistency_level), + context: Context => context, + } + + pub fn into_future(self) -> DeleteUserDefinedFunction { + Box::pin(async move { + let mut request = self + .client + .prepare_pipeline_with_user_defined_function_name(http::Method::DELETE); + + azure_core::headers::add_optional_header2(&self.consistency_level, &mut request)?; + + let response = self + .client + .pipeline() + .send( + self.context + .clone() + .insert(ResourceType::UserDefinedFunctions), + &mut request, + ) + .await?; + + DeleteUserDefinedFunctionResponse::try_from(response).await + }) + } +} + +#[cfg(feature = "into_future")] +impl std::future::IntoFuture for DeleteUserDefinedFunctionBuilder { + type Future = DeleteUserDefinedFunction; + type Output = ::Output; + fn into_future(self) -> Self::Future { + Self::into_future(self) + } +} + +/// The future returned by calling `into_future` on the builder. +pub type DeleteUserDefinedFunction = + futures::future::BoxFuture<'static, crate::Result>; + +#[derive(Debug, Clone, PartialEq)] +pub struct DeleteUserDefinedFunctionResponse { + pub content_location: String, + pub server: String, + pub last_state_change: DateTime, + pub resource_quota: Vec, + pub resource_usage: Vec, + pub lsn: u64, + pub schema_version: String, + pub alt_content_path: String, + pub content_path: String, + pub quorum_acked_lsn: u64, + pub current_write_quorum: u64, + pub current_replica_set_size: u64, + pub role: u32, + pub global_committed_lsn: u64, + pub number_of_read_regions: u32, + pub transport_request_id: u64, + pub cosmos_llsn: u64, + pub cosmos_quorum_acked_llsn: u64, + pub session_token: String, + pub charge: f64, + pub service_version: String, + pub activity_id: uuid::Uuid, + pub gateway_version: String, + pub date: DateTime, +} + +impl DeleteUserDefinedFunctionResponse { + pub async fn try_from(response: HttpResponse) -> crate::Result { + let (_status_code, headers, _pinned_stream) = response.deconstruct(); + + Ok(Self { + content_location: content_location_from_headers(&headers)?.to_owned(), + server: server_from_headers(&headers)?.to_owned(), + last_state_change: last_state_change_from_headers(&headers)?, + resource_quota: resource_quota_from_headers(&headers)?, + resource_usage: resource_usage_from_headers(&headers)?, + lsn: lsn_from_headers(&headers)?, + schema_version: schema_version_from_headers(&headers)?.to_owned(), + alt_content_path: alt_content_path_from_headers(&headers)?.to_owned(), + content_path: content_path_from_headers(&headers)?.to_owned(), + quorum_acked_lsn: quorum_acked_lsn_from_headers(&headers)?, + current_write_quorum: current_write_quorum_from_headers(&headers)?, + current_replica_set_size: current_replica_set_size_from_headers(&headers)?, + role: role_from_headers(&headers)?, + global_committed_lsn: global_committed_lsn_from_headers(&headers)?, + number_of_read_regions: number_of_read_regions_from_headers(&headers)?, + transport_request_id: transport_request_id_from_headers(&headers)?, + cosmos_llsn: cosmos_llsn_from_headers(&headers)?, + cosmos_quorum_acked_llsn: cosmos_quorum_acked_llsn_from_headers(&headers)?, + session_token: session_token_from_headers(&headers)?, + charge: request_charge_from_headers(&headers)?, + service_version: service_version_from_headers(&headers)?.to_owned(), + activity_id: activity_id_from_headers(&headers)?, + gateway_version: gateway_version_from_headers(&headers)?.to_owned(), + date: date_from_headers(&headers)?, + }) + } +} diff --git a/sdk/data_cosmos/src/operations/get_attachment.rs b/sdk/data_cosmos/src/operations/get_attachment.rs new file mode 100644 index 0000000000..75cd3ac842 --- /dev/null +++ b/sdk/data_cosmos/src/operations/get_attachment.rs @@ -0,0 +1,135 @@ +use crate::headers::from_headers::*; +use crate::prelude::*; +use crate::resources::document::IndexingDirective; +use crate::resources::Attachment; +use crate::ResourceQuota; +use azure_core::headers::{ + content_type_from_headers, etag_from_headers, session_token_from_headers, +}; +use azure_core::SessionToken; +use azure_core::{collect_pinned_stream, prelude::*, Response as HttpResponse}; +use chrono::{DateTime, Utc}; + +#[derive(Debug, Clone)] +pub struct GetAttachmentBuilder { + client: AttachmentClient, + if_match_condition: Option, + consistency_level: Option, + context: Context, +} + +impl GetAttachmentBuilder { + pub(crate) fn new(client: AttachmentClient) -> Self { + Self { + client, + if_match_condition: None, + consistency_level: None, + context: Context::new(), + } + } + + setters! { + consistency_level: ConsistencyLevel => Some(consistency_level), + if_match_condition: IfMatchCondition => Some(if_match_condition), + context: Context => context, + } + + pub fn into_future(self) -> GetAttachment { + Box::pin(async move { + let mut request = self + .client + .prepare_pipeline_with_attachment_name(http::Method::GET); + + azure_core::headers::add_optional_header2(&self.if_match_condition, &mut request)?; + azure_core::headers::add_optional_header2(&self.consistency_level, &mut request)?; + + crate::cosmos_entity::add_as_partition_key_header_serialized2( + self.client.document_client().partition_key_serialized(), + &mut request, + ); + let response = self + .client + .pipeline() + .send( + self.context.clone().insert(ResourceType::Attachments), + &mut request, + ) + .await?; + + GetAttachmentResponse::try_from(response).await + }) + } +} + +#[cfg(feature = "into_future")] +impl std::future::IntoFuture for GetAttachmentBuilder { + type Future = GetAttachment; + type Output = ::Output; + fn into_future(self) -> Self::Future { + Self::into_future(self) + } +} + +/// The future returned by calling `into_future` on the builder. +pub type GetAttachment = futures::future::BoxFuture<'static, crate::Result>; + +#[derive(Debug, Clone, PartialEq)] +pub struct GetAttachmentResponse { + pub attachment: Attachment, + + pub content_type: String, + pub content_location: String, + pub last_change: DateTime, + pub etag: String, + pub resource_quota: Vec, + pub resource_usage: Vec, + pub lsn: u64, + pub alt_content_path: String, + pub content_path: String, + pub global_committed_lsn: u64, + pub number_of_read_regions: u32, + pub item_lsn: u64, + pub transport_request_id: u64, + pub cosmos_llsn: u64, + pub cosmos_item_llsn: u64, + pub session_token: SessionToken, + pub request_charge: f64, + pub indexing_directive: Option, + pub service_version: String, + pub activity_id: uuid::Uuid, + pub gateway_version: String, + pub date: DateTime, +} + +impl GetAttachmentResponse { + pub async fn try_from(response: HttpResponse) -> crate::Result { + let (_status_code, headers, pinned_stream) = response.deconstruct(); + let body = collect_pinned_stream(pinned_stream).await?; + + Ok(Self { + attachment: serde_json::from_slice(&body)?, + content_type: content_type_from_headers(&headers)?.to_owned(), + content_location: content_location_from_headers(&headers)?.to_owned(), + last_change: last_state_change_from_headers(&headers)?, + etag: etag_from_headers(&headers)?, + resource_quota: resource_quota_from_headers(&headers)?, + resource_usage: resource_usage_from_headers(&headers)?, + lsn: lsn_from_headers(&headers)?, + alt_content_path: alt_content_path_from_headers(&headers)?.to_owned(), + content_path: content_path_from_headers(&headers)?.to_owned(), + global_committed_lsn: global_committed_lsn_from_headers(&headers)?, + number_of_read_regions: number_of_read_regions_from_headers(&headers)?, + item_lsn: item_lsn_from_headers(&headers)?, + transport_request_id: transport_request_id_from_headers(&headers)?, + cosmos_llsn: cosmos_llsn_from_headers(&headers)?, + cosmos_item_llsn: cosmos_item_llsn_from_headers(&headers)?, + session_token: session_token_from_headers(&headers)?, + request_charge: request_charge_from_headers(&headers)?, + indexing_directive: indexing_directive_from_headers_optional(&headers)?, + service_version: service_version_from_headers(&headers)?.to_owned(), + activity_id: activity_id_from_headers(&headers)?, + gateway_version: gateway_version_from_headers(&headers)?.to_owned(), + date: date_from_headers(&headers)?, + }) + } +} diff --git a/sdk/data_cosmos/src/operations/list_triggers.rs b/sdk/data_cosmos/src/operations/list_triggers.rs new file mode 100644 index 0000000000..6e4028f594 --- /dev/null +++ b/sdk/data_cosmos/src/operations/list_triggers.rs @@ -0,0 +1,158 @@ +use crate::headers::from_headers::*; +use crate::prelude::*; +use crate::resources::ResourceType; +use crate::ResourceQuota; +use azure_core::collect_pinned_stream; +use azure_core::headers; +use azure_core::headers::item_count_from_headers; +use azure_core::headers::{continuation_token_from_headers_optional, session_token_from_headers}; +use azure_core::prelude::*; +use azure_core::{Pageable, Response as HttpResponse}; +use chrono::{DateTime, Utc}; + +#[derive(Debug, Clone)] +pub struct ListTriggersBuilder { + client: CollectionClient, + if_match_condition: Option, + consistency_level: Option, + max_item_count: MaxItemCount, + context: Context, +} + +impl ListTriggersBuilder { + pub(crate) fn new(client: CollectionClient) -> Self { + Self { + client, + if_match_condition: None, + consistency_level: None, + max_item_count: MaxItemCount::new(-1), + context: Context::new(), + } + } + + setters! { + consistency_level: ConsistencyLevel => Some(consistency_level), + max_item_count: i32 => MaxItemCount::new(max_item_count), + if_match_condition: IfMatchCondition => Some(if_match_condition), + context: Context => context, + } + + pub fn into_stream(self) -> ListTriggers { + let make_request = move |continuation: Option| { + let this = self.clone(); + let ctx = self.context.clone(); + async move { + let mut request = this.client.cosmos_client().prepare_request_pipeline( + &format!( + "dbs/{}/colls/{}/triggers", + this.client.database_client().database_name(), + this.client.collection_name() + ), + http::Method::GET, + ); + + azure_core::headers::add_optional_header2(&this.if_match_condition, &mut request)?; + azure_core::headers::add_optional_header2(&this.consistency_level, &mut request)?; + azure_core::headers::add_mandatory_header2(&this.max_item_count, &mut request)?; + + if let Some(c) = continuation { + let h = http::HeaderValue::from_str(c.as_str()) + .map_err(azure_core::HttpHeaderError::InvalidHeaderValue)?; + request.headers_mut().append(headers::CONTINUATION, h); + } + + let response = this + .client + .pipeline() + .send(ctx.clone().insert(ResourceType::Triggers), &mut request) + .await?; + ListTriggersResponse::try_from(response).await + } + }; + + Pageable::new(make_request) + } +} + +/// The future returned by calling `into_future` on the builder. +pub type ListTriggers = Pageable; + +#[derive(Debug, Clone, PartialEq)] +pub struct ListTriggersResponse { + pub rid: String, + pub triggers: Vec, + pub content_location: String, + pub server: String, + pub last_state_change: DateTime, + pub continuation_token: Option, + pub resource_quota: Vec, + pub resource_usage: Vec, + pub lsn: u64, + pub item_count: u32, + pub schema_version: String, + pub alt_content_path: String, + pub content_path: String, + pub role: u32, + pub global_committed_lsn: u64, + pub number_of_read_regions: u32, + pub transport_request_id: u64, + pub cosmos_llsn: u64, + pub session_token: String, + pub charge: f64, + pub service_version: String, + pub activity_id: uuid::Uuid, + pub gateway_version: String, + pub date: DateTime, +} + +impl ListTriggersResponse { + pub async fn try_from(response: HttpResponse) -> crate::Result { + let (_status_code, headers, pinned_stream) = response.deconstruct(); + let body = collect_pinned_stream(pinned_stream).await?; + + #[derive(Debug, Deserialize)] + struct Response<'a> { + #[serde(rename = "_rid")] + rid: &'a str, + #[serde(rename = "Triggers")] + triggers: Vec, + #[serde(rename = "_count")] + #[allow(unused)] + count: u32, + } + let response: Response = serde_json::from_slice(&body)?; + + Ok(Self { + rid: response.rid.to_owned(), + triggers: response.triggers, + content_location: content_location_from_headers(&headers)?.to_owned(), + server: server_from_headers(&headers)?.to_owned(), + last_state_change: last_state_change_from_headers(&headers)?, + continuation_token: continuation_token_from_headers_optional(&headers)?, + resource_quota: resource_quota_from_headers(&headers)?, + resource_usage: resource_usage_from_headers(&headers)?, + lsn: lsn_from_headers(&headers)?, + item_count: item_count_from_headers(&headers)?, + schema_version: schema_version_from_headers(&headers)?.to_owned(), + alt_content_path: alt_content_path_from_headers(&headers)?.to_owned(), + content_path: content_path_from_headers(&headers)?.to_owned(), + role: role_from_headers(&headers)?, + global_committed_lsn: global_committed_lsn_from_headers(&headers)?, + number_of_read_regions: number_of_read_regions_from_headers(&headers)?, + transport_request_id: transport_request_id_from_headers(&headers)?, + cosmos_llsn: cosmos_llsn_from_headers(&headers)?, + session_token: session_token_from_headers(&headers)?, + charge: request_charge_from_headers(&headers)?, + service_version: service_version_from_headers(&headers)?.to_owned(), + activity_id: activity_id_from_headers(&headers)?, + gateway_version: gateway_version_from_headers(&headers)?.to_owned(), + date: date_from_headers(&headers)?, + }) + } +} + +impl Continuable for ListTriggersResponse { + fn continuation(&self) -> Option { + self.continuation_token.clone() + } +} diff --git a/sdk/data_cosmos/src/operations/mod.rs b/sdk/data_cosmos/src/operations/mod.rs index edf562e87b..2b7bbcfe8f 100644 --- a/sdk/data_cosmos/src/operations/mod.rs +++ b/sdk/data_cosmos/src/operations/mod.rs @@ -5,15 +5,23 @@ mod create_collection; mod create_database; mod create_document; +mod create_or_replace_slug_attachment; +mod create_or_replace_trigger; +mod create_or_replace_user_defined_function; mod create_permission; +mod create_reference_attachment; mod create_stored_procedure; mod create_user; +mod delete_attachment; mod delete_collection; mod delete_database; mod delete_document; mod delete_permission; mod delete_stored_procedure; +mod delete_trigger; mod delete_user; +mod delete_user_defined_function; +mod get_attachment; mod get_collection; mod get_database; mod get_document; @@ -25,6 +33,7 @@ mod list_databases; mod list_documents; mod list_permissions; mod list_stored_procedures; +mod list_triggers; mod list_user_defined_functions; mod list_users; mod query_documents; @@ -37,15 +46,23 @@ mod replace_user; pub use create_collection::*; pub use create_database::*; pub use create_document::*; +pub use create_or_replace_slug_attachment::*; +pub use create_or_replace_trigger::*; +pub use create_or_replace_user_defined_function::*; pub use create_permission::*; +pub use create_reference_attachment::*; pub use create_stored_procedure::*; pub use create_user::*; +pub use delete_attachment::*; pub use delete_collection::*; pub use delete_database::*; pub use delete_document::*; pub use delete_permission::*; pub use delete_stored_procedure::*; +pub use delete_trigger::*; pub use delete_user::*; +pub use delete_user_defined_function::*; +pub use get_attachment::*; pub use get_collection::*; pub use get_database::*; pub use get_document::*; @@ -57,6 +74,7 @@ pub use list_databases::*; pub use list_documents::*; pub use list_permissions::*; pub use list_stored_procedures::*; +pub use list_triggers::*; pub use list_user_defined_functions::*; pub use list_users::*; pub use query_documents::*; diff --git a/sdk/data_cosmos/src/requests/create_or_replace_trigger_builder.rs b/sdk/data_cosmos/src/requests/create_or_replace_trigger_builder.rs deleted file mode 100644 index a5d811e019..0000000000 --- a/sdk/data_cosmos/src/requests/create_or_replace_trigger_builder.rs +++ /dev/null @@ -1,97 +0,0 @@ -use crate::prelude::*; -use crate::resources::trigger::*; -use crate::responses::CreateTriggerResponse; -use azure_core::prelude::*; -use http::StatusCode; -use std::convert::TryInto; - -#[derive(Debug, Clone)] -pub struct CreateOrReplaceTriggerBuilder<'a> { - trigger_client: &'a TriggerClient, - is_create: bool, - user_agent: Option>, - activity_id: Option>, - consistency_level: Option, -} - -impl<'a> CreateOrReplaceTriggerBuilder<'a> { - pub(crate) fn new(trigger_client: &'a TriggerClient, is_create: bool) -> Self { - Self { - trigger_client, - is_create, - user_agent: None, - activity_id: None, - consistency_level: None, - } - } -} - -impl<'a> CreateOrReplaceTriggerBuilder<'a> { - setters! { - user_agent: &'a str => Some(UserAgent::new(user_agent)), - activity_id: &'a str => Some(ActivityId::new(activity_id)), - consistency_level: ConsistencyLevel => Some(consistency_level), - } -} - -impl<'a> CreateOrReplaceTriggerBuilder<'a> { - pub async fn execute( - &self, - body: B, - trigger_type: T, - trigger_operation: O, - ) -> crate::Result - where - B: AsRef, - T: Into, - O: Into, - { - trace!("CreateOrReplaceTriggerBuilder::execute called"); - - let req = self.trigger_client; - let req = if self.is_create { - req.prepare_request(http::Method::POST) - } else { - req.prepare_request_with_trigger_name(http::Method::PUT) - }; - - let req = azure_core::headers::add_optional_header(&self.user_agent, req); - let req = azure_core::headers::add_optional_header(&self.activity_id, req); - let req = azure_core::headers::add_optional_header(&self.consistency_level, req); - - let req = req.header(http::header::CONTENT_TYPE, "application/json"); - - #[derive(Debug, Deserialize, Serialize)] - struct Request<'a> { - pub id: &'a str, - #[serde(rename = "triggerOperation")] - pub trigger_operation: TriggerOperation, - #[serde(rename = "triggerType")] - pub trigger_type: TriggerType, - pub body: &'a str, - } - - let request = Request { - id: self.trigger_client.trigger_name(), - trigger_operation: trigger_operation.into(), - trigger_type: trigger_type.into(), - body: body.as_ref(), - }; - - let request = azure_core::to_json(&request)?; - let request = req.body(request)?; - - let expected_status = if self.is_create { - StatusCode::CREATED - } else { - StatusCode::OK - }; - - Ok(self - .trigger_client - .http_client() - .execute_request_check_status(request, expected_status) - .await? - .try_into()?) - } -} diff --git a/sdk/data_cosmos/src/requests/create_or_replace_user_defined_function_builder.rs b/sdk/data_cosmos/src/requests/create_or_replace_user_defined_function_builder.rs deleted file mode 100644 index 4186f99da6..0000000000 --- a/sdk/data_cosmos/src/requests/create_or_replace_user_defined_function_builder.rs +++ /dev/null @@ -1,94 +0,0 @@ -use crate::prelude::*; -use crate::responses::CreateUserDefinedFunctionResponse; -use azure_core::prelude::*; -use http::StatusCode; -use std::convert::TryInto; - -#[derive(Debug, Clone)] -pub struct CreateOrReplaceUserDefinedFunctionBuilder<'a, 'b> { - user_defined_function_client: &'a UserDefinedFunctionClient, - is_create: bool, - user_agent: Option>, - activity_id: Option>, - consistency_level: Option, -} - -impl<'a, 'b> CreateOrReplaceUserDefinedFunctionBuilder<'a, 'b> { - pub(crate) fn new( - user_defined_function_client: &'a UserDefinedFunctionClient, - is_create: bool, - ) -> Self { - Self { - user_defined_function_client, - is_create, - user_agent: None, - activity_id: None, - consistency_level: None, - } - } -} - -impl<'a, 'b> CreateOrReplaceUserDefinedFunctionBuilder<'a, 'b> { - setters! { - user_agent: &'b str => Some(UserAgent::new(user_agent)), - activity_id: &'b str => Some(ActivityId::new(activity_id)), - consistency_level: ConsistencyLevel => Some(consistency_level), - } -} - -impl<'a, 'b> CreateOrReplaceUserDefinedFunctionBuilder<'a, 'b> { - pub async fn execute>( - &self, - body: B, - ) -> crate::Result { - trace!("CreateOrReplaceUserDefinedFunctionBuilder::execute called"); - - // Create is POST with no name in the URL. Expected return is CREATED. - // See https://docs.microsoft.com/rest/api/cosmos-db/create-a-user-defined-function - // Replace is PUT with name appended to the URL. Expected return is OK. - // See: https://docs.microsoft.com/rest/api/cosmos-db/replace-a-user-defined-function - let req = match self.is_create { - true => self - .user_defined_function_client - .prepare_request(http::Method::POST), - false => self - .user_defined_function_client - .prepare_request_with_user_defined_function_name(http::Method::PUT), - }; - - // add trait headers - let req = azure_core::headers::add_optional_header(&self.user_agent, req); - let req = azure_core::headers::add_optional_header(&self.activity_id, req); - let req = azure_core::headers::add_optional_header(&self.consistency_level, req); - - let req = req.header(http::header::CONTENT_TYPE, "application/json"); - - #[derive(Debug, Serialize)] - struct Request<'a> { - body: &'a str, - id: &'a str, - } - let request = Request { - body: body.as_ref(), - id: self - .user_defined_function_client - .user_defined_function_name(), - }; - - let request = azure_core::to_json(&request)?; - let request = req.body(request)?; - - let result = if self.is_create { - self.user_defined_function_client - .http_client() - .execute_request_check_status(request, StatusCode::CREATED) - .await? - } else { - self.user_defined_function_client - .http_client() - .execute_request_check_status(request, StatusCode::OK) - .await? - }; - Ok(result.try_into()?) - } -} diff --git a/sdk/data_cosmos/src/requests/create_reference_attachment_builder.rs b/sdk/data_cosmos/src/requests/create_reference_attachment_builder.rs deleted file mode 100644 index 85b601a377..0000000000 --- a/sdk/data_cosmos/src/requests/create_reference_attachment_builder.rs +++ /dev/null @@ -1,82 +0,0 @@ -use crate::prelude::*; -use azure_core::prelude::*; -use http::StatusCode; -use std::convert::TryInto; - -#[derive(Debug, Clone)] -pub struct CreateReferenceAttachmentBuilder<'a, 'b> { - attachment_client: &'a AttachmentClient, - user_agent: Option>, - activity_id: Option>, - consistency_level: Option, -} - -impl<'a, 'b> CreateReferenceAttachmentBuilder<'a, 'b> { - pub(crate) fn new(attachment_client: &'a AttachmentClient) -> Self { - Self { - attachment_client, - user_agent: None, - activity_id: None, - consistency_level: None, - } - } -} - -impl<'a, 'b> CreateReferenceAttachmentBuilder<'a, 'b> { - setters! { - user_agent: &'b str => Some(UserAgent::new(user_agent)), - activity_id: &'b str => Some(ActivityId::new(activity_id)), - consistency_level: ConsistencyLevel => Some(consistency_level), - } -} - -impl<'a, 'b> CreateReferenceAttachmentBuilder<'a, 'b> { - pub async fn execute( - &self, - media: M, - content_type: C, - ) -> crate::Result - where - M: AsRef, - C: AsRef, - { - let mut req = self.attachment_client.prepare_request(http::Method::POST); - - req = azure_core::headers::add_optional_header(&self.user_agent, req); - req = azure_core::headers::add_optional_header(&self.activity_id, req); - req = azure_core::headers::add_optional_header(&self.consistency_level, req); - - req = crate::cosmos_entity::add_as_partition_key_header_serialized( - self.attachment_client - .document_client() - .partition_key_serialized(), - req, - ); - - #[derive(Debug, Serialize)] - struct Request<'r> { - pub id: &'r str, - #[serde(rename = "contentType")] - pub content_type: &'r str, - pub media: &'r str, - } - - let request = azure_core::to_json(&Request { - id: self.attachment_client.attachment_name(), - content_type: content_type.as_ref(), - media: media.as_ref(), - })?; - - req = req.header(http::header::CONTENT_TYPE, "application/json"); - req = req.header(http::header::CONTENT_LENGTH, request.len()); - let req = req.body(request)?; - debug!("req == {:#?}", req); - - Ok(self - .attachment_client - .http_client() - .execute_request_check_status(req, StatusCode::CREATED) - .await? - .try_into()?) - } -} diff --git a/sdk/data_cosmos/src/requests/create_slug_attachment_builder.rs b/sdk/data_cosmos/src/requests/create_slug_attachment_builder.rs deleted file mode 100644 index cccb4ad629..0000000000 --- a/sdk/data_cosmos/src/requests/create_slug_attachment_builder.rs +++ /dev/null @@ -1,76 +0,0 @@ -use crate::prelude::*; -use crate::responses::CreateSlugAttachmentResponse; -use azure_core::prelude::*; -use bytes::Bytes; -use http::StatusCode; -use std::convert::TryInto; - -#[derive(Debug, Clone)] -pub struct CreateSlugAttachmentBuilder<'a, 'b> { - attachment_client: &'a AttachmentClient, - content_type: Option>, - if_match_condition: Option, - user_agent: Option>, - activity_id: Option>, - consistency_level: Option, -} - -impl<'a, 'b> CreateSlugAttachmentBuilder<'a, 'b> { - pub(crate) fn new(attachment_client: &'a AttachmentClient) -> Self { - Self { - attachment_client, - content_type: None, - if_match_condition: None, - user_agent: None, - activity_id: None, - consistency_level: None, - } - } -} - -impl<'a, 'b> CreateSlugAttachmentBuilder<'a, 'b> { - setters! { - user_agent: &'b str => Some(UserAgent::new(user_agent)), - activity_id: &'b str => Some(ActivityId::new(activity_id)), - consistency_level: ConsistencyLevel => Some(consistency_level), - if_match_condition: IfMatchCondition => Some(if_match_condition), - content_type: ContentType<'b> => Some(content_type), - } -} - -impl<'a, 'b> CreateSlugAttachmentBuilder<'a, 'b> { - pub async fn execute>( - &self, - body: B, - ) -> crate::Result { - let body = body.into(); - let mut req = self.attachment_client.prepare_request(http::Method::POST); - - req = azure_core::headers::add_optional_header(&self.if_match_condition, req); - req = azure_core::headers::add_optional_header(&self.user_agent, req); - req = azure_core::headers::add_optional_header(&self.activity_id, req); - req = azure_core::headers::add_optional_header(&self.consistency_level, req); - req = azure_core::headers::add_optional_header(&self.content_type, req); - - req = crate::cosmos_entity::add_as_partition_key_header_serialized( - self.attachment_client - .document_client() - .partition_key_serialized(), - req, - ); - - req = req.header("Slug", self.attachment_client.attachment_name()); - req = req.header(http::header::CONTENT_LENGTH, body.len()); - - let req = req.body(body)?; - - debug!("req == {:#?}", req); - - Ok(self - .attachment_client - .http_client() - .execute_request_check_status(req, StatusCode::CREATED) - .await? - .try_into()?) - } -} diff --git a/sdk/data_cosmos/src/requests/delete_attachment_builder.rs b/sdk/data_cosmos/src/requests/delete_attachment_builder.rs deleted file mode 100644 index aa035a923a..0000000000 --- a/sdk/data_cosmos/src/requests/delete_attachment_builder.rs +++ /dev/null @@ -1,63 +0,0 @@ -use crate::prelude::*; -use azure_core::prelude::*; - -use http::StatusCode; -use std::convert::TryInto; - -#[derive(Debug, Clone)] -pub struct DeleteAttachmentBuilder<'a, 'b> { - attachment_client: &'a AttachmentClient, - if_match_condition: Option, - user_agent: Option>, - activity_id: Option>, - consistency_level: Option, -} - -impl<'a, 'b> DeleteAttachmentBuilder<'a, 'b> { - pub(crate) fn new(attachment_client: &'a AttachmentClient) -> Self { - Self { - attachment_client, - if_match_condition: None, - user_agent: None, - activity_id: None, - consistency_level: None, - } - } - - setters! { - user_agent: &'b str => Some(UserAgent::new(user_agent)), - activity_id: &'b str => Some(ActivityId::new(activity_id)), - consistency_level: ConsistencyLevel => Some(consistency_level), - if_match_condition: IfMatchCondition => Some(if_match_condition), - } - - pub async fn execute(&self) -> crate::Result { - let mut req = self - .attachment_client - .prepare_request_with_attachment_name(http::Method::DELETE); - - // add trait headers - req = azure_core::headers::add_optional_header(&self.if_match_condition, req); - req = azure_core::headers::add_optional_header(&self.user_agent, req); - req = azure_core::headers::add_optional_header(&self.activity_id, req); - req = azure_core::headers::add_optional_header(&self.consistency_level, req); - - req = crate::cosmos_entity::add_as_partition_key_header_serialized( - self.attachment_client - .document_client() - .partition_key_serialized(), - req, - ); - - let req = req.body(azure_core::EMPTY_BODY)?; - - debug!("req == {:#?}", req); - - Ok(self - .attachment_client - .http_client() - .execute_request_check_status(req, StatusCode::NO_CONTENT) - .await? - .try_into()?) - } -} diff --git a/sdk/data_cosmos/src/requests/delete_trigger_builder.rs b/sdk/data_cosmos/src/requests/delete_trigger_builder.rs deleted file mode 100644 index 16b9e3672b..0000000000 --- a/sdk/data_cosmos/src/requests/delete_trigger_builder.rs +++ /dev/null @@ -1,53 +0,0 @@ -use crate::prelude::*; -use crate::responses::DeleteTriggerResponse; -use azure_core::prelude::*; - -use http::StatusCode; -use std::convert::TryInto; - -#[derive(Debug, Clone)] -pub struct DeleteTriggerBuilder<'a, 'b> { - trigger_client: &'a TriggerClient, - user_agent: Option>, - activity_id: Option>, - consistency_level: Option, -} - -impl<'a, 'b> DeleteTriggerBuilder<'a, 'b> { - pub(crate) fn new(trigger_client: &'a TriggerClient) -> Self { - Self { - trigger_client, - user_agent: None, - activity_id: None, - consistency_level: None, - } - } - - setters! { - user_agent: &'b str => Some(UserAgent::new(user_agent)), - activity_id: &'b str => Some(ActivityId::new(activity_id)), - consistency_level: ConsistencyLevel => Some(consistency_level), - } - - pub async fn execute(&self) -> crate::Result { - trace!("DeleteTriggerBuilder::execute called"); - - let req = self - .trigger_client - .prepare_request_with_trigger_name(http::Method::DELETE); - - // add trait headers - let req = azure_core::headers::add_optional_header(&self.user_agent, req); - let req = azure_core::headers::add_optional_header(&self.activity_id, req); - let req = azure_core::headers::add_optional_header(&self.consistency_level, req); - - let request = req.body(azure_core::EMPTY_BODY)?; - - Ok(self - .trigger_client - .http_client() - .execute_request_check_status(request, StatusCode::NO_CONTENT) - .await? - .try_into()?) - } -} diff --git a/sdk/data_cosmos/src/requests/delete_user_defined_function_builder.rs b/sdk/data_cosmos/src/requests/delete_user_defined_function_builder.rs deleted file mode 100644 index 68999ebfe8..0000000000 --- a/sdk/data_cosmos/src/requests/delete_user_defined_function_builder.rs +++ /dev/null @@ -1,53 +0,0 @@ -use crate::prelude::*; -use crate::responses::DeleteUserDefinedFunctionResponse; -use azure_core::prelude::*; - -use http::StatusCode; -use std::convert::TryInto; - -#[derive(Debug, Clone)] -pub struct DeleteUserDefinedFunctionBuilder<'a, 'b> { - user_defined_function_client: &'a UserDefinedFunctionClient, - user_agent: Option>, - activity_id: Option>, - consistency_level: Option, -} - -impl<'a, 'b> DeleteUserDefinedFunctionBuilder<'a, 'b> { - pub(crate) fn new(user_defined_function_client: &'a UserDefinedFunctionClient) -> Self { - Self { - user_defined_function_client, - user_agent: None, - activity_id: None, - consistency_level: None, - } - } - - setters! { - user_agent: &'b str => Some(UserAgent::new(user_agent)), - activity_id: &'b str => Some(ActivityId::new(activity_id)), - consistency_level: ConsistencyLevel => Some(consistency_level), - } - - pub async fn execute(&self) -> crate::Result { - trace!("DeleteUserDefinedFunctionBuilder::execute called"); - - let request = self - .user_defined_function_client - .prepare_request_with_user_defined_function_name(http::Method::DELETE); - - // add trait headers - let request = azure_core::headers::add_optional_header(&self.user_agent, request); - let request = azure_core::headers::add_optional_header(&self.activity_id, request); - let request = azure_core::headers::add_optional_header(&self.consistency_level, request); - - let request = request.body(azure_core::EMPTY_BODY)?; - - Ok(self - .user_defined_function_client - .http_client() - .execute_request_check_status(request, StatusCode::NO_CONTENT) - .await? - .try_into()?) - } -} diff --git a/sdk/data_cosmos/src/requests/get_attachment_builder.rs b/sdk/data_cosmos/src/requests/get_attachment_builder.rs deleted file mode 100644 index 4e511e49cc..0000000000 --- a/sdk/data_cosmos/src/requests/get_attachment_builder.rs +++ /dev/null @@ -1,63 +0,0 @@ -use crate::prelude::*; -use azure_core::prelude::*; - -use http::StatusCode; -use std::convert::TryInto; - -#[derive(Debug, Clone)] -pub struct GetAttachmentBuilder<'a, 'b> { - attachment_client: &'a AttachmentClient, - if_match_condition: Option, - user_agent: Option>, - activity_id: Option>, - consistency_level: Option, -} - -impl<'a, 'b> GetAttachmentBuilder<'a, 'b> { - pub(crate) fn new(attachment_client: &'a AttachmentClient) -> Self { - Self { - attachment_client, - if_match_condition: None, - user_agent: None, - activity_id: None, - consistency_level: None, - } - } - - setters! { - user_agent: &'b str => Some(UserAgent::new(user_agent)), - activity_id: &'b str => Some(ActivityId::new(activity_id)), - consistency_level: ConsistencyLevel => Some(consistency_level), - if_match_condition: IfMatchCondition => Some(if_match_condition), - } - - pub async fn execute(&self) -> crate::Result { - let mut req = self - .attachment_client - .prepare_request_with_attachment_name(http::Method::GET); - - // add trait headers - req = azure_core::headers::add_optional_header(&self.if_match_condition, req); - req = azure_core::headers::add_optional_header(&self.user_agent, req); - req = azure_core::headers::add_optional_header(&self.activity_id, req); - req = azure_core::headers::add_optional_header(&self.consistency_level, req); - - req = crate::cosmos_entity::add_as_partition_key_header_serialized( - self.attachment_client - .document_client() - .partition_key_serialized(), - req, - ); - - let req = req.body(azure_core::EMPTY_BODY)?; - - debug!("req == {:#?}", req); - - Ok(self - .attachment_client - .http_client() - .execute_request_check_status(req, StatusCode::OK) - .await? - .try_into()?) - } -} diff --git a/sdk/data_cosmos/src/requests/list_triggers_builder.rs b/sdk/data_cosmos/src/requests/list_triggers_builder.rs deleted file mode 100644 index 2d226680c1..0000000000 --- a/sdk/data_cosmos/src/requests/list_triggers_builder.rs +++ /dev/null @@ -1,113 +0,0 @@ -use crate::prelude::*; -use crate::resources::ResourceType; -use crate::responses::ListTriggersResponse; -use azure_core::prelude::*; -use futures::stream::{unfold, Stream}; -use http::StatusCode; -use std::convert::TryInto; - -#[derive(Debug, Clone)] -pub struct ListTriggersBuilder<'a, 'b> { - collection_client: &'a CollectionClient, - if_match_condition: Option, - user_agent: Option>, - activity_id: Option>, - consistency_level: Option, - continuation: Option>, - max_item_count: MaxItemCount, -} - -impl<'a, 'b> ListTriggersBuilder<'a, 'b> { - pub(crate) fn new(collection_client: &'a CollectionClient) -> Self { - Self { - collection_client, - if_match_condition: None, - user_agent: None, - activity_id: None, - consistency_level: None, - continuation: None, - max_item_count: MaxItemCount::new(-1), - } - } - - setters! { - user_agent: &'b str => Some(UserAgent::new(user_agent)), - activity_id: &'b str => Some(ActivityId::new(activity_id)), - consistency_level: ConsistencyLevel => Some(consistency_level), - continuation: &'b str => Some(Continuation::new(continuation)), - max_item_count: i32 => MaxItemCount::new(max_item_count), - if_match_condition: IfMatchCondition => Some(if_match_condition), - } - - pub async fn execute(&self) -> crate::Result { - trace!("ListTriggersBuilder::execute called"); - - let request = self.collection_client.cosmos_client().prepare_request( - &format!( - "dbs/{}/colls/{}/triggers", - self.collection_client.database_client().database_name(), - self.collection_client.collection_name() - ), - http::Method::GET, - ResourceType::Triggers, - ); - - // add trait headers - let request = azure_core::headers::add_optional_header(&self.if_match_condition, request); - let request = azure_core::headers::add_optional_header(&self.user_agent, request); - let request = azure_core::headers::add_optional_header(&self.activity_id, request); - let request = azure_core::headers::add_optional_header(&self.consistency_level, request); - let request = azure_core::headers::add_optional_header(&self.continuation, request); - let request = azure_core::headers::add_mandatory_header(&self.max_item_count, request); - - let request = request.body(azure_core::EMPTY_BODY)?; - - Ok(self - .collection_client - .http_client() - .execute_request_check_status(request, StatusCode::OK) - .await? - .try_into()?) - } - - pub fn stream(&self) -> impl Stream> + '_ { - #[derive(Debug, Clone, PartialEq)] - enum States { - Init, - Continuation(String), - } - - unfold( - Some(States::Init), - move |continuation_token: Option| { - async move { - debug!("continuation_token == {:?}", &continuation_token); - let response = match continuation_token { - Some(States::Init) => self.execute().await, - Some(States::Continuation(continuation_token)) => { - self.clone() - .continuation(continuation_token.as_str()) - .execute() - .await - } - None => return None, - }; - - // the ? operator does not work in async move (yet?) - // so we have to resort to this boilerplate - let response = match response { - Ok(response) => response, - Err(err) => return Some((Err(err), None)), - }; - - let continuation_token = response - .continuation_token - .as_ref() - .map(|ct| States::Continuation(ct.to_owned())); - - Some((Ok(response), continuation_token)) - } - }, - ) - } -} diff --git a/sdk/data_cosmos/src/requests/mod.rs b/sdk/data_cosmos/src/requests/mod.rs index 5332c5ac54..29cc0eaae6 100644 --- a/sdk/data_cosmos/src/requests/mod.rs +++ b/sdk/data_cosmos/src/requests/mod.rs @@ -6,30 +6,10 @@ #![allow(missing_docs)] -mod create_or_replace_trigger_builder; -mod create_or_replace_user_defined_function_builder; -mod create_reference_attachment_builder; -mod create_slug_attachment_builder; -mod delete_attachment_builder; -mod delete_trigger_builder; -mod delete_user_defined_function_builder; mod execute_stored_procedure_builder; -mod get_attachment_builder; mod get_partition_key_ranges_builder; -mod list_triggers_builder; mod replace_reference_attachment_builder; -mod replace_slug_attachment_builder; -pub use create_or_replace_trigger_builder::CreateOrReplaceTriggerBuilder; -pub use create_or_replace_user_defined_function_builder::CreateOrReplaceUserDefinedFunctionBuilder; -pub use create_reference_attachment_builder::CreateReferenceAttachmentBuilder; -pub use create_slug_attachment_builder::CreateSlugAttachmentBuilder; -pub use delete_attachment_builder::DeleteAttachmentBuilder; -pub use delete_trigger_builder::DeleteTriggerBuilder; -pub use delete_user_defined_function_builder::DeleteUserDefinedFunctionBuilder; pub use execute_stored_procedure_builder::ExecuteStoredProcedureBuilder; -pub use get_attachment_builder::GetAttachmentBuilder; pub use get_partition_key_ranges_builder::GetPartitionKeyRangesBuilder; -pub use list_triggers_builder::ListTriggersBuilder; pub use replace_reference_attachment_builder::ReplaceReferenceAttachmentBuilder; -pub use replace_slug_attachment_builder::ReplaceSlugAttachmentBuilder; diff --git a/sdk/data_cosmos/src/requests/replace_slug_attachment_builder.rs b/sdk/data_cosmos/src/requests/replace_slug_attachment_builder.rs deleted file mode 100644 index 90d4194223..0000000000 --- a/sdk/data_cosmos/src/requests/replace_slug_attachment_builder.rs +++ /dev/null @@ -1,77 +0,0 @@ -use crate::prelude::*; -use crate::responses::CreateSlugAttachmentResponse; -use azure_core::prelude::*; -use bytes::Bytes; -use http::StatusCode; -use std::convert::TryInto; - -#[derive(Debug, Clone)] -pub struct ReplaceSlugAttachmentBuilder<'a, 'b> { - attachment_client: &'a AttachmentClient, - content_type: Option>, - if_match_condition: Option, - user_agent: Option>, - activity_id: Option>, - consistency_level: Option, -} - -impl<'a, 'b> ReplaceSlugAttachmentBuilder<'a, 'b> { - pub(crate) fn new(attachment_client: &'a AttachmentClient) -> Self { - Self { - attachment_client, - content_type: None, - if_match_condition: None, - user_agent: None, - activity_id: None, - consistency_level: None, - } - } -} - -impl<'a, 'b> ReplaceSlugAttachmentBuilder<'a, 'b> { - setters! { - user_agent: &'b str => Some(UserAgent::new(user_agent)), - activity_id: &'b str => Some(ActivityId::new(activity_id)), - consistency_level: ConsistencyLevel => Some(consistency_level), - if_match_condition: IfMatchCondition => Some(if_match_condition), - content_type: ContentType<'b> => Some(content_type), - } -} - -impl<'a, 'b> ReplaceSlugAttachmentBuilder<'a, 'b> { - pub async fn execute>( - &self, - body: B, - ) -> crate::Result { - let body = body.into(); - let mut req = self.attachment_client.prepare_request(http::Method::PUT); - - req = azure_core::headers::add_optional_header(&self.if_match_condition, req); - req = azure_core::headers::add_optional_header(&self.user_agent, req); - req = azure_core::headers::add_optional_header(&self.activity_id, req); - req = azure_core::headers::add_optional_header(&self.consistency_level, req); - - req = crate::cosmos_entity::add_as_partition_key_header_serialized( - self.attachment_client - .document_client() - .partition_key_serialized(), - req, - ); - - req = azure_core::headers::add_optional_header(&self.content_type, req); - - req = req.header("Slug", self.attachment_client.attachment_name()); - req = req.header(http::header::CONTENT_LENGTH, body.len()); - - let req = req.body(body)?; - - debug!("req == {:#?}", req); - - Ok(self - .attachment_client - .http_client() - .execute_request_check_status(req, StatusCode::OK) - .await? - .try_into()?) - } -} diff --git a/sdk/data_cosmos/src/responses/create_collection_response.rs b/sdk/data_cosmos/src/responses/create_collection_response.rs deleted file mode 100644 index 189c0788f2..0000000000 --- a/sdk/data_cosmos/src/responses/create_collection_response.rs +++ /dev/null @@ -1,47 +0,0 @@ -use crate::headers::from_headers::*; -use crate::resources::Collection; -use azure_core::headers::{etag_from_headers, session_token_from_headers}; -use chrono::{DateTime, Utc}; -use http::response::Response; - -#[derive(Debug, Clone, PartialEq)] -pub struct CreateCollectionResponse { - pub collection: Collection, - pub charge: f64, - pub activity_id: uuid::Uuid, - pub etag: String, - pub session_token: String, - pub last_state_change: DateTime, - pub schema_version: String, - pub service_version: String, - pub gateway_version: String, - pub alt_content_path: String, - pub quorum_acked_lsn: u64, - pub current_write_quorum: u64, - pub current_replica_set_size: u64, -} - -impl std::convert::TryFrom> for CreateCollectionResponse { - type Error = crate::Error; - - fn try_from(response: Response) -> Result { - let headers = response.headers(); - let body = response.body(); - - Ok(Self { - collection: serde_json::from_slice(body)?, - charge: request_charge_from_headers(headers)?, - activity_id: activity_id_from_headers(headers)?, - etag: etag_from_headers(headers)?, - session_token: session_token_from_headers(headers)?, - last_state_change: last_state_change_from_headers(headers)?, - schema_version: schema_version_from_headers(headers)?.to_owned(), - service_version: service_version_from_headers(headers)?.to_owned(), - gateway_version: gateway_version_from_headers(headers)?.to_owned(), - alt_content_path: alt_content_path_from_headers(headers)?.to_owned(), - quorum_acked_lsn: quorum_acked_lsn_from_headers(headers)?, - current_write_quorum: current_write_quorum_from_headers(headers)?, - current_replica_set_size: current_replica_set_size_from_headers(headers)?, - }) - } -} diff --git a/sdk/data_cosmos/src/responses/create_reference_attachment_response.rs b/sdk/data_cosmos/src/responses/create_reference_attachment_response.rs deleted file mode 100644 index 6222864102..0000000000 --- a/sdk/data_cosmos/src/responses/create_reference_attachment_response.rs +++ /dev/null @@ -1,76 +0,0 @@ -use crate::headers::from_headers::*; -use crate::resources::Attachment; -use crate::ResourceQuota; -use azure_core::headers::{etag_from_headers, session_token_from_headers}; -use azure_core::SessionToken; -use chrono::{DateTime, Utc}; -use http::response::Response; - -#[derive(Debug, Clone, PartialEq)] -pub struct CreateReferenceAttachmentResponse { - pub attachment: Attachment, - pub max_media_storage_usage_mb: u64, - pub media_storage_usage_mb: u64, - pub last_change: DateTime, - pub etag: String, - pub resource_quota: Vec, - pub resource_usage: Vec, - pub lsn: u64, - pub alt_content_path: String, - pub content_path: String, - pub quorum_acked_lsn: u64, - pub current_write_quorum: u64, - pub current_replica_set_size: u64, - pub global_committed_lsn: u64, - pub number_of_read_regions: u32, - pub transport_request_id: u64, - pub cosmos_llsn: u64, - pub cosmos_quorum_acked_llsn: u64, - pub session_token: SessionToken, - pub request_charge: f64, - pub service_version: String, - pub activity_id: uuid::Uuid, - pub gateway_version: String, - pub date: DateTime, -} - -impl std::convert::TryFrom> for CreateReferenceAttachmentResponse { - type Error = crate::Error; - - fn try_from(response: Response) -> Result { - let headers = response.headers(); - let body = response.body(); - - debug!("headers == {:#?}", headers); - debug!("body == {:#?}", body); - - let attachment: Attachment = serde_json::from_slice(body)?; - - Ok(Self { - attachment, - max_media_storage_usage_mb: max_media_storage_usage_mb_from_headers(headers)?, - media_storage_usage_mb: media_storage_usage_mb_from_headers(headers)?, - last_change: last_state_change_from_headers(headers)?, - etag: etag_from_headers(headers)?, - resource_quota: resource_quota_from_headers(headers)?, - resource_usage: resource_usage_from_headers(headers)?, - lsn: lsn_from_headers(headers)?, - alt_content_path: alt_content_path_from_headers(headers)?.to_owned(), - content_path: content_path_from_headers(headers)?.to_owned(), - quorum_acked_lsn: quorum_acked_lsn_from_headers(headers)?, - current_write_quorum: current_write_quorum_from_headers(headers)?, - current_replica_set_size: current_replica_set_size_from_headers(headers)?, - global_committed_lsn: global_committed_lsn_from_headers(headers)?, - number_of_read_regions: number_of_read_regions_from_headers(headers)?, - transport_request_id: transport_request_id_from_headers(headers)?, - cosmos_llsn: cosmos_llsn_from_headers(headers)?, - cosmos_quorum_acked_llsn: cosmos_quorum_acked_llsn_from_headers(headers)?, - session_token: session_token_from_headers(headers)?, - request_charge: request_charge_from_headers(headers)?, - service_version: service_version_from_headers(headers)?.to_owned(), - activity_id: activity_id_from_headers(headers)?, - gateway_version: gateway_version_from_headers(headers)?.to_owned(), - date: date_from_headers(headers)?, - }) - } -} diff --git a/sdk/data_cosmos/src/responses/create_slug_attachment_response.rs b/sdk/data_cosmos/src/responses/create_slug_attachment_response.rs deleted file mode 100644 index 541393ea4c..0000000000 --- a/sdk/data_cosmos/src/responses/create_slug_attachment_response.rs +++ /dev/null @@ -1,74 +0,0 @@ -use crate::headers::from_headers::*; -use crate::resources::Attachment; -use crate::ResourceQuota; -use azure_core::headers::{etag_from_headers, session_token_from_headers}; -use azure_core::SessionToken; -use chrono::{DateTime, Utc}; -use http::response::Response; - -#[derive(Debug, Clone, PartialEq)] -pub struct CreateSlugAttachmentResponse { - pub attachment: Attachment, - pub max_media_storage_usage_mb: u64, - pub media_storage_usage_mb: u64, - pub last_change: DateTime, - pub etag: String, - pub resource_quota: Vec, - pub resource_usage: Vec, - pub lsn: u64, - pub alt_content_path: String, - pub quorum_acked_lsn: u64, - pub current_write_quorum: u64, - pub current_replica_set_size: u64, - pub global_committed_lsn: u64, - pub number_of_read_regions: u32, - pub transport_request_id: u64, - pub cosmos_llsn: u64, - pub cosmos_quorum_acked_llsn: u64, - pub session_token: SessionToken, - pub request_charge: f64, - pub service_version: String, - pub activity_id: uuid::Uuid, - pub gateway_version: String, - pub date: DateTime, -} - -impl std::convert::TryFrom> for CreateSlugAttachmentResponse { - type Error = crate::Error; - - fn try_from(response: Response) -> Result { - let headers = response.headers(); - let body = response.body(); - - debug!("headers == {:#?}", headers); - debug!("body == {:#?}", body); - - let attachment: Attachment = serde_json::from_slice(body)?; - - Ok(Self { - attachment, - max_media_storage_usage_mb: max_media_storage_usage_mb_from_headers(headers)?, - media_storage_usage_mb: media_storage_usage_mb_from_headers(headers)?, - last_change: last_state_change_from_headers(headers)?, - etag: etag_from_headers(headers)?, - resource_quota: resource_quota_from_headers(headers)?, - resource_usage: resource_usage_from_headers(headers)?, - lsn: lsn_from_headers(headers)?, - alt_content_path: alt_content_path_from_headers(headers)?.to_owned(), - quorum_acked_lsn: quorum_acked_lsn_from_headers(headers)?, - current_write_quorum: current_write_quorum_from_headers(headers)?, - current_replica_set_size: current_replica_set_size_from_headers(headers)?, - global_committed_lsn: global_committed_lsn_from_headers(headers)?, - number_of_read_regions: number_of_read_regions_from_headers(headers)?, - transport_request_id: transport_request_id_from_headers(headers)?, - cosmos_llsn: cosmos_llsn_from_headers(headers)?, - cosmos_quorum_acked_llsn: cosmos_quorum_acked_llsn_from_headers(headers)?, - session_token: session_token_from_headers(headers)?, - request_charge: request_charge_from_headers(headers)?, - service_version: service_version_from_headers(headers)?.to_owned(), - activity_id: activity_id_from_headers(headers)?, - gateway_version: gateway_version_from_headers(headers)?.to_owned(), - date: date_from_headers(headers)?, - }) - } -} diff --git a/sdk/data_cosmos/src/responses/create_trigger_response.rs b/sdk/data_cosmos/src/responses/create_trigger_response.rs deleted file mode 100644 index 351c38c744..0000000000 --- a/sdk/data_cosmos/src/responses/create_trigger_response.rs +++ /dev/null @@ -1,75 +0,0 @@ -use crate::headers::from_headers::*; -use crate::resources::Trigger; -use crate::ResourceQuota; -use azure_core::headers::{etag_from_headers, session_token_from_headers}; -use chrono::{DateTime, Utc}; -use http::response::Response; - -#[derive(Debug, Clone, PartialEq)] -pub struct CreateTriggerResponse { - pub trigger: Trigger, - pub server: String, - pub last_state_change: DateTime, - pub etag: String, - pub resource_quota: Vec, - pub resource_usage: Vec, - pub lsn: u64, - pub schema_version: String, - pub alt_content_path: String, - pub content_path: String, - pub quorum_acked_lsn: u64, - pub current_write_quorum: u64, - pub current_replica_set_size: u64, - pub role: u32, - pub global_committed_lsn: u64, - pub number_of_read_regions: u32, - pub transport_request_id: u64, - pub cosmos_llsn: u64, - pub cosmos_quorum_acked_llsn: u64, - pub session_token: String, - pub charge: f64, - pub service_version: String, - pub activity_id: uuid::Uuid, - pub gateway_version: String, - pub date: DateTime, -} - -impl std::convert::TryFrom> for CreateTriggerResponse { - type Error = crate::Error; - - fn try_from(response: Response) -> Result { - let headers = response.headers(); - let body = response.body(); - - debug!("{:#?}", headers); - debug!("{:#?}", std::str::from_utf8(body)); - - Ok(Self { - trigger: serde_json::from_slice(body)?, - server: server_from_headers(headers)?.to_owned(), - last_state_change: last_state_change_from_headers(headers)?, - etag: etag_from_headers(headers)?, - resource_quota: resource_quota_from_headers(headers)?, - resource_usage: resource_usage_from_headers(headers)?, - lsn: lsn_from_headers(headers)?, - schema_version: schema_version_from_headers(headers)?.to_owned(), - alt_content_path: alt_content_path_from_headers(headers)?.to_owned(), - content_path: content_path_from_headers(headers)?.to_owned(), - quorum_acked_lsn: quorum_acked_lsn_from_headers(headers)?, - current_write_quorum: current_write_quorum_from_headers(headers)?, - current_replica_set_size: current_replica_set_size_from_headers(headers)?, - role: role_from_headers(headers)?, - global_committed_lsn: global_committed_lsn_from_headers(headers)?, - number_of_read_regions: number_of_read_regions_from_headers(headers)?, - transport_request_id: transport_request_id_from_headers(headers)?, - cosmos_llsn: cosmos_llsn_from_headers(headers)?, - cosmos_quorum_acked_llsn: cosmos_quorum_acked_llsn_from_headers(headers)?, - session_token: session_token_from_headers(headers)?, - charge: request_charge_from_headers(headers)?, - service_version: service_version_from_headers(headers)?.to_owned(), - activity_id: activity_id_from_headers(headers)?, - gateway_version: gateway_version_from_headers(headers)?.to_owned(), - date: date_from_headers(headers)?, - }) - } -} diff --git a/sdk/data_cosmos/src/responses/create_user_defined_function_response.rs b/sdk/data_cosmos/src/responses/create_user_defined_function_response.rs deleted file mode 100644 index 9a379b56e1..0000000000 --- a/sdk/data_cosmos/src/responses/create_user_defined_function_response.rs +++ /dev/null @@ -1,75 +0,0 @@ -use crate::headers::from_headers::*; -use crate::resources::UserDefinedFunction; -use crate::ResourceQuota; -use azure_core::headers::{etag_from_headers, session_token_from_headers}; -use chrono::{DateTime, Utc}; -use http::response::Response; - -#[derive(Debug, Clone, PartialEq)] -pub struct CreateUserDefinedFunctionResponse { - pub user_defined_function: UserDefinedFunction, - pub server: String, - pub last_state_change: DateTime, - pub etag: String, - pub resource_quota: Vec, - pub resource_usage: Vec, - pub lsn: u64, - pub schema_version: String, - pub alt_content_path: String, - pub content_path: String, - pub quorum_acked_lsn: u64, - pub current_write_quorum: u64, - pub current_replica_set_size: u64, - pub role: u32, - pub global_committed_lsn: u64, - pub number_of_read_regions: u32, - pub transport_request_id: u64, - pub cosmos_llsn: u64, - pub cosmos_quorum_acked_llsn: u64, - pub session_token: String, - pub charge: f64, - pub service_version: String, - pub activity_id: uuid::Uuid, - pub gateway_version: String, - pub date: DateTime, -} - -impl std::convert::TryFrom> for CreateUserDefinedFunctionResponse { - type Error = crate::Error; - - fn try_from(response: Response) -> Result { - let headers = response.headers(); - let body = response.body(); - - debug!("{:#?}", headers); - debug!("{:#?}", std::str::from_utf8(body)); - - Ok(Self { - user_defined_function: serde_json::from_slice(body)?, - server: server_from_headers(headers)?.to_owned(), - last_state_change: last_state_change_from_headers(headers)?, - etag: etag_from_headers(headers)?, - resource_quota: resource_quota_from_headers(headers)?, - resource_usage: resource_usage_from_headers(headers)?, - lsn: lsn_from_headers(headers)?, - schema_version: schema_version_from_headers(headers)?.to_owned(), - alt_content_path: alt_content_path_from_headers(headers)?.to_owned(), - content_path: content_path_from_headers(headers)?.to_owned(), - quorum_acked_lsn: quorum_acked_lsn_from_headers(headers)?, - current_write_quorum: current_write_quorum_from_headers(headers)?, - current_replica_set_size: current_replica_set_size_from_headers(headers)?, - role: role_from_headers(headers)?, - global_committed_lsn: global_committed_lsn_from_headers(headers)?, - number_of_read_regions: number_of_read_regions_from_headers(headers)?, - transport_request_id: transport_request_id_from_headers(headers)?, - cosmos_llsn: cosmos_llsn_from_headers(headers)?, - cosmos_quorum_acked_llsn: cosmos_quorum_acked_llsn_from_headers(headers)?, - session_token: session_token_from_headers(headers)?, - charge: request_charge_from_headers(headers)?, - service_version: service_version_from_headers(headers)?.to_owned(), - activity_id: activity_id_from_headers(headers)?, - gateway_version: gateway_version_from_headers(headers)?.to_owned(), - date: date_from_headers(headers)?, - }) - } -} diff --git a/sdk/data_cosmos/src/responses/delete_trigger_response.rs b/sdk/data_cosmos/src/responses/delete_trigger_response.rs deleted file mode 100644 index 9cb1e440db..0000000000 --- a/sdk/data_cosmos/src/responses/delete_trigger_response.rs +++ /dev/null @@ -1,72 +0,0 @@ -use crate::headers::from_headers::*; -use crate::ResourceQuota; -use azure_core::headers::session_token_from_headers; -use chrono::{DateTime, Utc}; -use http::response::Response; - -#[derive(Debug, Clone, PartialEq)] -pub struct DeleteTriggerResponse { - pub content_location: String, - pub server: String, - pub last_state_change: DateTime, - pub resource_quota: Vec, - pub resource_usage: Vec, - pub lsn: u64, - pub schema_version: String, - pub alt_content_path: String, - pub content_path: String, - pub quorum_acked_lsn: u64, - pub current_write_quorum: u64, - pub current_replica_set_size: u64, - pub role: u32, - pub global_committed_lsn: u64, - pub number_of_read_regions: u32, - pub transport_request_id: u64, - pub cosmos_llsn: u64, - pub cosmos_quorum_acked_llsn: u64, - pub session_token: String, - pub charge: f64, - pub service_version: String, - pub activity_id: uuid::Uuid, - pub gateway_version: String, - pub date: DateTime, -} - -impl std::convert::TryFrom> for DeleteTriggerResponse { - type Error = crate::Error; - - fn try_from(response: Response) -> Result { - let headers = response.headers(); - let body = response.body(); - - debug!("{:#?}", headers); - debug!("{:#?}", std::str::from_utf8(body)); - - Ok(Self { - content_location: content_location_from_headers(headers)?.to_owned(), - server: server_from_headers(headers)?.to_owned(), - last_state_change: last_state_change_from_headers(headers)?, - resource_quota: resource_quota_from_headers(headers)?, - resource_usage: resource_usage_from_headers(headers)?, - lsn: lsn_from_headers(headers)?, - schema_version: schema_version_from_headers(headers)?.to_owned(), - alt_content_path: alt_content_path_from_headers(headers)?.to_owned(), - content_path: content_path_from_headers(headers)?.to_owned(), - quorum_acked_lsn: quorum_acked_lsn_from_headers(headers)?, - current_write_quorum: current_write_quorum_from_headers(headers)?, - current_replica_set_size: current_replica_set_size_from_headers(headers)?, - role: role_from_headers(headers)?, - global_committed_lsn: global_committed_lsn_from_headers(headers)?, - number_of_read_regions: number_of_read_regions_from_headers(headers)?, - transport_request_id: transport_request_id_from_headers(headers)?, - cosmos_llsn: cosmos_llsn_from_headers(headers)?, - cosmos_quorum_acked_llsn: cosmos_quorum_acked_llsn_from_headers(headers)?, - session_token: session_token_from_headers(headers)?, - charge: request_charge_from_headers(headers)?, - service_version: service_version_from_headers(headers)?.to_owned(), - activity_id: activity_id_from_headers(headers)?, - gateway_version: gateway_version_from_headers(headers)?.to_owned(), - date: date_from_headers(headers)?, - }) - } -} diff --git a/sdk/data_cosmos/src/responses/delete_user_defined_function_response.rs b/sdk/data_cosmos/src/responses/delete_user_defined_function_response.rs deleted file mode 100644 index c6cbf1ff8f..0000000000 --- a/sdk/data_cosmos/src/responses/delete_user_defined_function_response.rs +++ /dev/null @@ -1,72 +0,0 @@ -use crate::headers::from_headers::*; -use crate::ResourceQuota; -use azure_core::headers::session_token_from_headers; -use chrono::{DateTime, Utc}; -use http::response::Response; - -#[derive(Debug, Clone, PartialEq)] -pub struct DeleteUserDefinedFunctionResponse { - pub content_location: String, - pub server: String, - pub last_state_change: DateTime, - pub resource_quota: Vec, - pub resource_usage: Vec, - pub lsn: u64, - pub schema_version: String, - pub alt_content_path: String, - pub content_path: String, - pub quorum_acked_lsn: u64, - pub current_write_quorum: u64, - pub current_replica_set_size: u64, - pub role: u32, - pub global_committed_lsn: u64, - pub number_of_read_regions: u32, - pub transport_request_id: u64, - pub cosmos_llsn: u64, - pub cosmos_quorum_acked_llsn: u64, - pub session_token: String, - pub charge: f64, - pub service_version: String, - pub activity_id: uuid::Uuid, - pub gateway_version: String, - pub date: DateTime, -} - -impl std::convert::TryFrom> for DeleteUserDefinedFunctionResponse { - type Error = crate::Error; - - fn try_from(response: Response) -> Result { - let headers = response.headers(); - let body = response.body(); - - debug!("{:#?}", headers); - debug!("{:#?}", std::str::from_utf8(body)); - - Ok(Self { - content_location: content_location_from_headers(headers)?.to_owned(), - server: server_from_headers(headers)?.to_owned(), - last_state_change: last_state_change_from_headers(headers)?, - resource_quota: resource_quota_from_headers(headers)?, - resource_usage: resource_usage_from_headers(headers)?, - lsn: lsn_from_headers(headers)?, - schema_version: schema_version_from_headers(headers)?.to_owned(), - alt_content_path: alt_content_path_from_headers(headers)?.to_owned(), - content_path: content_path_from_headers(headers)?.to_owned(), - quorum_acked_lsn: quorum_acked_lsn_from_headers(headers)?, - current_write_quorum: current_write_quorum_from_headers(headers)?, - current_replica_set_size: current_replica_set_size_from_headers(headers)?, - role: role_from_headers(headers)?, - global_committed_lsn: global_committed_lsn_from_headers(headers)?, - number_of_read_regions: number_of_read_regions_from_headers(headers)?, - transport_request_id: transport_request_id_from_headers(headers)?, - cosmos_llsn: cosmos_llsn_from_headers(headers)?, - cosmos_quorum_acked_llsn: cosmos_quorum_acked_llsn_from_headers(headers)?, - session_token: session_token_from_headers(headers)?, - charge: request_charge_from_headers(headers)?, - service_version: service_version_from_headers(headers)?.to_owned(), - activity_id: activity_id_from_headers(headers)?, - gateway_version: gateway_version_from_headers(headers)?.to_owned(), - date: date_from_headers(headers)?, - }) - } -} diff --git a/sdk/data_cosmos/src/responses/get_attachment_response.rs b/sdk/data_cosmos/src/responses/get_attachment_response.rs deleted file mode 100644 index 1e83479abc..0000000000 --- a/sdk/data_cosmos/src/responses/get_attachment_response.rs +++ /dev/null @@ -1,79 +0,0 @@ -use crate::headers::from_headers::*; -use crate::resources::document::IndexingDirective; -use crate::resources::Attachment; -use crate::ResourceQuota; -use azure_core::headers::{ - content_type_from_headers, etag_from_headers, session_token_from_headers, -}; -use azure_core::SessionToken; -use chrono::{DateTime, Utc}; -use http::response::Response; - -#[derive(Debug, Clone, PartialEq)] -pub struct GetAttachmentResponse { - pub attachment: Attachment, - - pub content_type: String, - pub content_location: String, - pub last_change: DateTime, - pub etag: String, - pub resource_quota: Vec, - pub resource_usage: Vec, - pub lsn: u64, - pub alt_content_path: String, - pub content_path: String, - pub global_committed_lsn: u64, - pub number_of_read_regions: u32, - pub item_lsn: u64, - pub transport_request_id: u64, - pub cosmos_llsn: u64, - pub cosmos_item_llsn: u64, - pub session_token: SessionToken, - pub request_charge: f64, - pub indexing_directive: Option, - pub service_version: String, - pub activity_id: uuid::Uuid, - pub gateway_version: String, - pub date: DateTime, -} - -impl std::convert::TryFrom> for GetAttachmentResponse { - type Error = crate::Error; - - fn try_from(response: Response) -> Result { - let headers = response.headers(); - let body = response.body(); - - debug!("headers == {:#?}", headers); - debug!("body == {:?}", std::str::from_utf8(body)); - - Ok(Self { - attachment: serde_json::from_slice(body)?, - content_type: content_type_from_headers(headers)?.to_owned(), - content_location: content_location_from_headers(headers)?.to_owned(), - last_change: last_state_change_from_headers(headers)?, - etag: etag_from_headers(headers)?, - resource_quota: resource_quota_from_headers(headers)?, - resource_usage: resource_usage_from_headers(headers)?, - lsn: lsn_from_headers(headers)?, - alt_content_path: alt_content_path_from_headers(headers)?.to_owned(), - content_path: content_path_from_headers(headers)?.to_owned(), - global_committed_lsn: global_committed_lsn_from_headers(headers)?, - number_of_read_regions: number_of_read_regions_from_headers(headers)?, - item_lsn: item_lsn_from_headers(headers)?, - transport_request_id: transport_request_id_from_headers(headers)?, - cosmos_llsn: cosmos_llsn_from_headers(headers)?, - cosmos_item_llsn: cosmos_item_llsn_from_headers(headers)?, - session_token: session_token_from_headers(headers)?, - request_charge: request_charge_from_headers(headers)?, - indexing_directive: indexing_directive_from_headers_optional(headers)?, - service_version: service_version_from_headers(headers)?.to_owned(), - activity_id: activity_id_from_headers(headers)?, - gateway_version: gateway_version_from_headers(headers)?.to_owned(), - date: date_from_headers(headers)?, - }) - } -} - -#[cfg(test)] -mod tests {} diff --git a/sdk/data_cosmos/src/responses/list_triggers_response.rs b/sdk/data_cosmos/src/responses/list_triggers_response.rs deleted file mode 100644 index 318b1b9053..0000000000 --- a/sdk/data_cosmos/src/responses/list_triggers_response.rs +++ /dev/null @@ -1,84 +0,0 @@ -use crate::headers::from_headers::*; -use crate::resources::Trigger; -use crate::ResourceQuota; -use azure_core::headers::{ - continuation_token_from_headers_optional, item_count_from_headers, session_token_from_headers, -}; -use chrono::{DateTime, Utc}; -use http::response::Response; - -#[derive(Debug, Clone, PartialEq)] -pub struct ListTriggersResponse { - pub rid: String, - pub triggers: Vec, - pub content_location: String, - pub server: String, - pub last_state_change: DateTime, - pub continuation_token: Option, - pub resource_quota: Vec, - pub resource_usage: Vec, - pub lsn: u64, - pub item_count: u32, - pub schema_version: String, - pub alt_content_path: String, - pub content_path: String, - pub role: u32, - pub global_committed_lsn: u64, - pub number_of_read_regions: u32, - pub transport_request_id: u64, - pub cosmos_llsn: u64, - pub session_token: String, - pub charge: f64, - pub service_version: String, - pub activity_id: uuid::Uuid, - pub gateway_version: String, - pub date: DateTime, -} - -impl std::convert::TryFrom> for ListTriggersResponse { - type Error = crate::Error; - - fn try_from(response: Response) -> Result { - let headers = response.headers(); - let body = response.body(); - - #[derive(Debug, Deserialize)] - struct Response<'a> { - #[serde(rename = "_rid")] - rid: &'a str, - #[serde(rename = "Triggers")] - triggers: Vec, - #[serde(rename = "_count")] - #[allow(unused)] - count: u32, - } - let response: Response = serde_json::from_slice(body)?; - - Ok(Self { - rid: response.rid.to_owned(), - triggers: response.triggers, - content_location: content_location_from_headers(headers)?.to_owned(), - server: server_from_headers(headers)?.to_owned(), - last_state_change: last_state_change_from_headers(headers)?, - continuation_token: continuation_token_from_headers_optional(headers)?, - resource_quota: resource_quota_from_headers(headers)?, - resource_usage: resource_usage_from_headers(headers)?, - lsn: lsn_from_headers(headers)?, - item_count: item_count_from_headers(headers)?, - schema_version: schema_version_from_headers(headers)?.to_owned(), - alt_content_path: alt_content_path_from_headers(headers)?.to_owned(), - content_path: content_path_from_headers(headers)?.to_owned(), - role: role_from_headers(headers)?, - global_committed_lsn: global_committed_lsn_from_headers(headers)?, - number_of_read_regions: number_of_read_regions_from_headers(headers)?, - transport_request_id: transport_request_id_from_headers(headers)?, - cosmos_llsn: cosmos_llsn_from_headers(headers)?, - session_token: session_token_from_headers(headers)?, - charge: request_charge_from_headers(headers)?, - service_version: service_version_from_headers(headers)?.to_owned(), - activity_id: activity_id_from_headers(headers)?, - gateway_version: gateway_version_from_headers(headers)?.to_owned(), - date: date_from_headers(headers)?, - }) - } -} diff --git a/sdk/data_cosmos/src/responses/mod.rs b/sdk/data_cosmos/src/responses/mod.rs index aac6522e4d..cef0288007 100644 --- a/sdk/data_cosmos/src/responses/mod.rs +++ b/sdk/data_cosmos/src/responses/mod.rs @@ -2,30 +2,10 @@ #![allow(missing_docs)] -mod create_collection_response; -mod create_reference_attachment_response; -mod create_slug_attachment_response; -mod create_trigger_response; -mod create_user_defined_function_response; -mod delete_attachment_response; -mod delete_trigger_response; -mod delete_user_defined_function_response; mod execute_stored_procedure_response; -mod get_attachment_response; mod get_partition_key_ranges_response; -mod list_triggers_response; mod replace_reference_attachment_response; -pub use create_collection_response::CreateCollectionResponse; -pub use create_reference_attachment_response::CreateReferenceAttachmentResponse; -pub use create_slug_attachment_response::CreateSlugAttachmentResponse; -pub use create_trigger_response::CreateTriggerResponse; -pub use create_user_defined_function_response::CreateUserDefinedFunctionResponse; -pub use delete_attachment_response::DeleteAttachmentResponse; -pub use delete_trigger_response::DeleteTriggerResponse; -pub use delete_user_defined_function_response::DeleteUserDefinedFunctionResponse; pub use execute_stored_procedure_response::ExecuteStoredProcedureResponse; -pub use get_attachment_response::GetAttachmentResponse; pub use get_partition_key_ranges_response::GetPartitionKeyRangesResponse; -pub use list_triggers_response::ListTriggersResponse; pub use replace_reference_attachment_response::ReplaceReferenceAttachmentResponse; diff --git a/sdk/data_cosmos/tests/attachment_00.rs b/sdk/data_cosmos/tests/attachment_00.rs index b651eaf1b4..27bad910c5 100644 --- a/sdk/data_cosmos/tests/attachment_00.rs +++ b/sdk/data_cosmos/tests/attachment_00.rs @@ -107,9 +107,9 @@ async fn attachment() -> Result<(), azure_data_cosmos::Error> { // create reference attachment let attachment_client = document_client.clone().into_attachment_client("reference"); let resp = attachment_client - .create_reference() + .create_reference("https://www.bing.com", "image/jpeg") .consistency_level(&ret) - .execute("https://www.bing.com", "image/jpeg") + .into_future() .await?; // replace reference attachment @@ -122,10 +122,10 @@ async fn attachment() -> Result<(), azure_data_cosmos::Error> { // create slug attachment let attachment_client = document_client.clone().into_attachment_client("slug"); let resp = attachment_client - .create_slug() + .create_slug("something cool here".into()) .consistency_level(&resp) .content_type("text/plain") - .execute("something cool here") + .into_future() .await?; // list attachments, there must be two. @@ -144,7 +144,7 @@ async fn attachment() -> Result<(), azure_data_cosmos::Error> { .into_attachment_client("reference") .get() .consistency_level(&ret) - .execute() + .into_future() .await?; assert_eq!( "https://www.microsoft.com", @@ -158,7 +158,7 @@ async fn attachment() -> Result<(), azure_data_cosmos::Error> { .into_attachment_client("slug") .get() .consistency_level(&reference_attachment) - .execute() + .into_future() .await .unwrap(); assert_eq!("text/plain", slug_attachment.attachment.content_type); @@ -167,7 +167,7 @@ async fn attachment() -> Result<(), azure_data_cosmos::Error> { let resp_delete = attachment_client .delete() .consistency_level(&slug_attachment) - .execute() + .into_future() .await?; // list attachments, there must be one. diff --git a/sdk/data_cosmos/tests/trigger.rs b/sdk/data_cosmos/tests/trigger.rs index 090ec58bd8..9507c35fb4 100644 --- a/sdk/data_cosmos/tests/trigger.rs +++ b/sdk/data_cosmos/tests/trigger.rs @@ -66,22 +66,22 @@ async fn trigger() -> Result<(), azure_data_cosmos::Error> { let trigger_client = collection_client.clone().into_trigger_client(TRIGGER_NAME); let ret = trigger_client - .create_trigger() - .execute( + .create_trigger( "something", trigger::TriggerType::Post, trigger::TriggerOperation::All, ) + .into_future() .await?; let ret = trigger_client - .replace_trigger() - .consistency_level(ret) - .execute( + .replace_trigger( TRIGGER_BODY, trigger::TriggerType::Post, trigger::TriggerOperation::All, ) + .consistency_level(ret) + .into_future() .await?; let mut last_session_token: Option = None; @@ -90,7 +90,7 @@ async fn trigger() -> Result<(), azure_data_cosmos::Error> { .list_triggers() .max_item_count(3) .consistency_level(&ret); - let mut stream = Box::pin(stream.stream()); + let mut stream = stream.into_stream(); while let Some(ret) = stream.next().await { let ret = ret.unwrap(); last_session_token = Some(ConsistencyLevel::Session(ret.session_token)); @@ -99,7 +99,7 @@ async fn trigger() -> Result<(), azure_data_cosmos::Error> { let _ret = trigger_client .delete_trigger() .consistency_level(last_session_token.unwrap()) - .execute() + .into_future() .await?; // delete the database diff --git a/sdk/data_cosmos/tests/user_defined_function00.rs b/sdk/data_cosmos/tests/user_defined_function00.rs index d4aa517887..48548ebf79 100644 --- a/sdk/data_cosmos/tests/user_defined_function00.rs +++ b/sdk/data_cosmos/tests/user_defined_function00.rs @@ -48,8 +48,8 @@ async fn user_defined_function00() -> Result<(), azure_data_cosmos::Error> { .into_user_defined_function_client(USER_DEFINED_FUNCTION_NAME); let ret = user_defined_function_client - .create_user_defined_function() - .execute("body") + .create_user_defined_function("body") + .into_future() .await?; let stream = collection_client @@ -63,9 +63,9 @@ async fn user_defined_function00() -> Result<(), azure_data_cosmos::Error> { } let ret = user_defined_function_client - .replace_user_defined_function() + .replace_user_defined_function(FN_BODY) .consistency_level(&ret) - .execute(FN_BODY) + .into_future() .await?; let query_stmt = format!("SELECT udf.{}(100)", USER_DEFINED_FUNCTION_NAME); @@ -112,7 +112,7 @@ async fn user_defined_function00() -> Result<(), azure_data_cosmos::Error> { let _ret = user_defined_function_client .delete_user_defined_function() .consistency_level(&ret) - .execute() + .into_future() .await?; // delete the database