From 5a50aeefd6ea8dad655a821f50e4b936da738d15 Mon Sep 17 00:00:00 2001 From: Abdulla Abdurakhmanov Date: Sun, 1 Oct 2023 13:24:41 +0200 Subject: [PATCH] Updated gcloud-sdk to v0.21 and removed direct tonic/prost deps (#127) --- Cargo.toml | 6 ++--- src/cache/backends/persistent_backend.rs | 2 +- src/db/aggregated_query.rs | 4 ++-- src/db/batch_streaming_writer.rs | 3 +-- src/db/create.rs | 2 +- src/db/delete.rs | 2 +- src/db/get.rs | 4 ++-- src/db/list.rs | 8 +++---- src/db/listen_changes.rs | 2 +- src/db/query.rs | 6 ++--- src/db/transaction.rs | 6 ++--- src/db/update.rs | 2 +- src/errors.rs | 28 ++++++++++++------------ src/timestamp_utils.rs | 6 ++--- 14 files changed, 39 insertions(+), 42 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f93d418..7ea8999 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,19 +25,17 @@ path = "src/lib.rs" default = [] caching = [] caching-memory = ["caching", "dep:moka"] -caching-persistent = ["caching", "dep:redb", "dep:prost"] +caching-persistent = ["caching", "dep:redb"] [dependencies] tracing = "0.1" -gcloud-sdk = { version = "0.20.7", features = ["google-firestore-v1"] } +gcloud-sdk = { version = "0.21", features = ["google-firestore-v1"] } tonic = { version = "0.9", features = ["tls"] } hyper = { version ="0.14" } struct-path = "0.2" rvstruct = "0.3.2" rsb_derive = "0.5" serde = { version = "1.0", features = ["derive"] } -prost-types = "0.11" -prost = { version = "0.11", optional = true } tokio = { version = "1" } tokio-stream = "0.1" futures = "0.3" diff --git a/src/cache/backends/persistent_backend.rs b/src/cache/backends/persistent_backend.rs index d1cbf91..bf0c096 100644 --- a/src/cache/backends/persistent_backend.rs +++ b/src/cache/backends/persistent_backend.rs @@ -6,7 +6,7 @@ use futures::stream::BoxStream; use chrono::Utc; use futures::StreamExt; use gcloud_sdk::google::firestore::v1::Document; -use prost::Message; +use gcloud_sdk::prost::Message; use redb::*; use std::collections::HashMap; use std::path::PathBuf; diff --git a/src/db/aggregated_query.rs b/src/db/aggregated_query.rs index 3dc3193..c146a22 100644 --- a/src/db/aggregated_query.rs +++ b/src/db/aggregated_query.rs @@ -272,8 +272,8 @@ impl FirestoreDb { fn create_aggregated_query_request( &self, params: FirestoreAggregatedQueryParams, - ) -> FirestoreResult> { - Ok(tonic::Request::new(RunAggregationQueryRequest { + ) -> FirestoreResult> { + Ok(gcloud_sdk::tonic::Request::new(RunAggregationQueryRequest { parent: params .query_params .parent diff --git a/src/db/batch_streaming_writer.rs b/src/db/batch_streaming_writer.rs index 76ff03e..562cfca 100644 --- a/src/db/batch_streaming_writer.rs +++ b/src/db/batch_streaming_writer.rs @@ -14,7 +14,6 @@ use std::time::Duration; use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender}; use tokio::sync::{mpsc, RwLock}; use tokio::task::JoinHandle; -use tonic::Code; use crate::timestamp_utils::from_timestamp; use tracing::*; @@ -142,7 +141,7 @@ impl FirestoreStreamingBatchWriter { .ok(); break; } - Err(err) if err.code() == Code::Cancelled => { + Err(err) if err.code() == gcloud_sdk::tonic::Code::Cancelled => { debug!("Batch write operation finished on: {}", received_counter); responses_writer .send(Ok(FirestoreBatchWriteResponse::new( diff --git a/src/db/create.rs b/src/db/create.rs index 4ec7f43..80a214f 100644 --- a/src/db/create.rs +++ b/src/db/create.rs @@ -95,7 +95,7 @@ impl FirestoreCreateSupport for FirestoreDb { "/firestore/document_name" = field::Empty, ); - let create_document_request = tonic::Request::new(CreateDocumentRequest { + let create_document_request = gcloud_sdk::tonic::Request::new(CreateDocumentRequest { parent: parent.into(), document_id: document_id .as_ref() diff --git a/src/db/delete.rs b/src/db/delete.rs index e8a67ca..dd97eed 100644 --- a/src/db/delete.rs +++ b/src/db/delete.rs @@ -67,7 +67,7 @@ impl FirestoreDeleteSupport for FirestoreDb { "/firestore/document_name" = document_path.as_str(), ); - let request = tonic::Request::new(DeleteDocumentRequest { + let request = gcloud_sdk::tonic::Request::new(DeleteDocumentRequest { name: document_path, current_document: precondition.map(|cond| cond.try_into()).transpose()?, }); diff --git a/src/db/get.rs b/src/db/get.rs index ab18e01..8d57cbf 100644 --- a/src/db/get.rs +++ b/src/db/get.rs @@ -578,7 +578,7 @@ impl FirestoreDb { ); let begin_query_utc: DateTime = Utc::now(); - let request = tonic::Request::new(GetDocumentRequest { + let request = gcloud_sdk::tonic::Request::new(GetDocumentRequest { name: document_path.clone(), consistency_selector: self .session_params @@ -675,7 +675,7 @@ impl FirestoreDb { "/firestore/ids_count" = full_doc_ids.len() ); - let request = tonic::Request::new(BatchGetDocumentsRequest { + let request = gcloud_sdk::tonic::Request::new(BatchGetDocumentsRequest { database: self.get_database_path().clone(), documents: full_doc_ids, consistency_selector: self diff --git a/src/db/list.rs b/src/db/list.rs index 84e0fa1..570bf70 100644 --- a/src/db/list.rs +++ b/src/db/list.rs @@ -305,8 +305,8 @@ impl FirestoreDb { fn create_list_doc_request( &self, params: FirestoreListDocParams, - ) -> FirestoreResult> { - Ok(tonic::Request::new(ListDocumentsRequest { + ) -> FirestoreResult> { + Ok(gcloud_sdk::tonic::Request::new(ListDocumentsRequest { parent: params .parent .as_ref() @@ -403,8 +403,8 @@ impl FirestoreDb { fn create_list_collection_ids_request( &self, params: &FirestoreListCollectionIdsParams, - ) -> FirestoreResult> { - Ok(tonic::Request::new(ListCollectionIdsRequest { + ) -> FirestoreResult> { + Ok(gcloud_sdk::tonic::Request::new(ListCollectionIdsRequest { parent: params .parent .as_ref() diff --git a/src/db/listen_changes.rs b/src/db/listen_changes.rs index 668e578..1af517c 100644 --- a/src/db/listen_changes.rs +++ b/src/db/listen_changes.rs @@ -73,7 +73,7 @@ impl FirestoreListenSupport for FirestoreDb { .map(|target_params| self.create_listen_request(target_params)) .collect::>>()?; - let request = tonic::Request::new( + let request = gcloud_sdk::tonic::Request::new( futures::stream::iter(listen_requests).chain(futures::stream::pending()), ); diff --git a/src/db/query.rs b/src/db/query.rs index 82000f9..9453b5c 100644 --- a/src/db/query.rs +++ b/src/db/query.rs @@ -74,8 +74,8 @@ impl FirestoreDb { fn create_query_request( &self, params: FirestoreQueryParams, - ) -> FirestoreResult> { - Ok(tonic::Request::new(RunQueryRequest { + ) -> FirestoreResult> { + Ok(gcloud_sdk::tonic::Request::new(RunQueryRequest { parent: params .parent .as_ref() @@ -350,7 +350,7 @@ impl FirestoreQuerySupport for FirestoreDb { Some((params, consistency_selector)), move |maybe_params| async move { if let Some((params, maybe_consistency_selector)) = maybe_params { - let request = tonic::Request::new(PartitionQueryRequest { + let request = gcloud_sdk::tonic::Request::new(PartitionQueryRequest { page_size: params.page_size as i32, partition_count: params.partition_count as i64, parent: params diff --git a/src/db/transaction.rs b/src/db/transaction.rs index 600307d..f60476e 100644 --- a/src/db/transaction.rs +++ b/src/db/transaction.rs @@ -32,7 +32,7 @@ impl<'a> FirestoreTransaction<'a> { "/firestore/commit_time" = field::Empty ); - let request = tonic::Request::new(BeginTransactionRequest { + let request = gcloud_sdk::tonic::Request::new(BeginTransactionRequest { database: db.get_database_path().clone(), options: Some(options.clone().try_into()?), }); @@ -87,7 +87,7 @@ impl<'a> FirestoreTransaction<'a> { return Ok(FirestoreTransactionResponse::new(Vec::new())); } - let request = tonic::Request::new(CommitRequest { + let request = gcloud_sdk::tonic::Request::new(CommitRequest { database: self.db.get_database_path().clone(), writes: self.writes.drain(..).collect(), transaction: self.transaction_id.clone(), @@ -118,7 +118,7 @@ impl<'a> FirestoreTransaction<'a> { pub async fn rollback(mut self) -> FirestoreResult<()> { self.finished = true; - let request = tonic::Request::new(RollbackRequest { + let request = gcloud_sdk::tonic::Request::new(RollbackRequest { database: self.db.get_database_path().clone(), transaction: self.transaction_id.clone(), }); diff --git a/src/db/update.rs b/src/db/update.rs index 3747058..06859c2 100644 --- a/src/db/update.rs +++ b/src/db/update.rs @@ -126,7 +126,7 @@ impl FirestoreUpdateSupport for FirestoreDb { "/firestore/response_time" = field::Empty, ); - let update_document_request = tonic::Request::new(UpdateDocumentRequest { + let update_document_request = gcloud_sdk::tonic::Request::new(UpdateDocumentRequest { update_mask: update_only.map({ |vf| DocumentMask { field_paths: vf.iter().map(|f| f.to_string()).collect(), diff --git a/src/errors.rs b/src/errors.rs index 01bd374..44ce2f9 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -163,32 +163,32 @@ impl From for FirestoreError { } } -impl From for FirestoreError { - fn from(status: tonic::Status) -> Self { +impl From for FirestoreError { + fn from(status: gcloud_sdk::tonic::Status) -> Self { match status.code() { - tonic::Code::AlreadyExists => { + gcloud_sdk::tonic::Code::AlreadyExists => { FirestoreError::DataConflictError(FirestoreDataConflictError::new( FirestoreErrorPublicGenericDetails::new(format!("{:?}", status.code())), format!("{status}"), )) } - tonic::Code::NotFound => { + gcloud_sdk::tonic::Code::NotFound => { FirestoreError::DataNotFoundError(FirestoreDataNotFoundError::new( FirestoreErrorPublicGenericDetails::new(format!("{:?}", status.code())), format!("{status}"), )) } - tonic::Code::Aborted - | tonic::Code::Cancelled - | tonic::Code::Unavailable - | tonic::Code::ResourceExhausted => { + gcloud_sdk::tonic::Code::Aborted + | gcloud_sdk::tonic::Code::Cancelled + | gcloud_sdk::tonic::Code::Unavailable + | gcloud_sdk::tonic::Code::ResourceExhausted => { FirestoreError::DatabaseError(FirestoreDatabaseError::new( FirestoreErrorPublicGenericDetails::new(format!("{:?}", status.code())), format!("{status}"), true, )) } - tonic::Code::Unknown => check_hyper_errors(status), + gcloud_sdk::tonic::Code::Unknown => check_hyper_errors(status), _ => FirestoreError::DatabaseError(FirestoreDatabaseError::new( FirestoreErrorPublicGenericDetails::new(format!("{:?}", status.code())), format!("{status}"), @@ -198,7 +198,7 @@ impl From for FirestoreError { } } -fn check_hyper_errors(status: tonic::Status) -> FirestoreError { +fn check_hyper_errors(status: gcloud_sdk::tonic::Status) -> FirestoreError { match status.source() { Some(hyper_error) => match hyper_error.downcast_ref::() { Some(err) if err.is_closed() => { @@ -406,8 +406,8 @@ impl From for FirestoreError { } #[cfg(feature = "caching-persistent")] -impl From for FirestoreError { - fn from(err: prost::EncodeError) -> Self { +impl From for FirestoreError { + fn from(err: gcloud_sdk::prost::EncodeError) -> Self { FirestoreError::SerializeError(FirestoreSerializationError::new( FirestoreErrorPublicGenericDetails::new("PrototBufEncodeError".into()), format!("Protobuf serialization error: {err}"), @@ -416,8 +416,8 @@ impl From for FirestoreError { } #[cfg(feature = "caching-persistent")] -impl From for FirestoreError { - fn from(err: prost::DecodeError) -> Self { +impl From for FirestoreError { + fn from(err: gcloud_sdk::prost::DecodeError) -> Self { FirestoreError::SerializeError(FirestoreSerializationError::new( FirestoreErrorPublicGenericDetails::new("PrototBufDecodeError".into()), format!("Protobuf deserialization error: {err}"), diff --git a/src/timestamp_utils.rs b/src/timestamp_utils.rs index ba48da7..94a7b5a 100644 --- a/src/timestamp_utils.rs +++ b/src/timestamp_utils.rs @@ -2,7 +2,7 @@ use crate::errors::*; use crate::FirestoreResult; use chrono::prelude::*; -pub fn from_timestamp(ts: prost_types::Timestamp) -> FirestoreResult> { +pub fn from_timestamp(ts: gcloud_sdk::prost_types::Timestamp) -> FirestoreResult> { if let Some(dt) = chrono::NaiveDateTime::from_timestamp_opt(ts.seconds, ts.nanos as u32) { Ok(DateTime::::from_naive_utc_and_offset(dt, Utc)) } else { @@ -14,8 +14,8 @@ pub fn from_timestamp(ts: prost_types::Timestamp) -> FirestoreResult) -> prost_types::Timestamp { - prost_types::Timestamp { +pub fn to_timestamp(dt: DateTime) -> gcloud_sdk::prost_types::Timestamp { + gcloud_sdk::prost_types::Timestamp { seconds: dt.timestamp(), nanos: dt.nanosecond() as i32, }