Skip to content

Commit

Permalink
Updated gcloud-sdk to v0.21 and removed direct tonic/prost deps
Browse files Browse the repository at this point in the history
  • Loading branch information
abdolence committed Oct 1, 2023
1 parent e107080 commit 17990ed
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 41 deletions.
6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions src/db/aggregated_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ impl FirestoreDb {
fn create_aggregated_query_request(
&self,
params: FirestoreAggregatedQueryParams,
) -> FirestoreResult<tonic::Request<RunAggregationQueryRequest>> {
Ok(tonic::Request::new(RunAggregationQueryRequest {
) -> FirestoreResult<gcloud_sdk::tonic::Request<RunAggregationQueryRequest>> {
Ok(gcloud_sdk::tonic::Request::new(RunAggregationQueryRequest {
parent: params
.query_params
.parent
Expand Down
3 changes: 1 addition & 2 deletions src/db/batch_streaming_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/db/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/db/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?,
});
Expand Down
4 changes: 2 additions & 2 deletions src/db/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ impl FirestoreDb {
);
let begin_query_utc: DateTime<Utc> = 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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/db/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ impl FirestoreDb {
fn create_list_doc_request(
&self,
params: FirestoreListDocParams,
) -> FirestoreResult<tonic::Request<ListDocumentsRequest>> {
Ok(tonic::Request::new(ListDocumentsRequest {
) -> FirestoreResult<gcloud_sdk::tonic::Request<ListDocumentsRequest>> {
Ok(gcloud_sdk::tonic::Request::new(ListDocumentsRequest {
parent: params
.parent
.as_ref()
Expand Down Expand Up @@ -403,8 +403,8 @@ impl FirestoreDb {
fn create_list_collection_ids_request(
&self,
params: &FirestoreListCollectionIdsParams,
) -> FirestoreResult<tonic::Request<ListCollectionIdsRequest>> {
Ok(tonic::Request::new(ListCollectionIdsRequest {
) -> FirestoreResult<gcloud_sdk::tonic::Request<ListCollectionIdsRequest>> {
Ok(gcloud_sdk::tonic::Request::new(ListCollectionIdsRequest {
parent: params
.parent
.as_ref()
Expand Down
2 changes: 1 addition & 1 deletion src/db/listen_changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl FirestoreListenSupport for FirestoreDb {
.map(|target_params| self.create_listen_request(target_params))
.collect::<FirestoreResult<Vec<ListenRequest>>>()?;

let request = tonic::Request::new(
let request = gcloud_sdk::tonic::Request::new(
futures::stream::iter(listen_requests).chain(futures::stream::pending()),
);

Expand Down
6 changes: 3 additions & 3 deletions src/db/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ impl FirestoreDb {
fn create_query_request(
&self,
params: FirestoreQueryParams,
) -> FirestoreResult<tonic::Request<RunQueryRequest>> {
Ok(tonic::Request::new(RunQueryRequest {
) -> FirestoreResult<gcloud_sdk::tonic::Request<RunQueryRequest>> {
Ok(gcloud_sdk::tonic::Request::new(RunQueryRequest {
parent: params
.parent
.as_ref()
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/db/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?),
});
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
});
Expand Down
2 changes: 1 addition & 1 deletion src/db/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
28 changes: 14 additions & 14 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,32 +163,32 @@ impl From<gcloud_sdk::error::Error> for FirestoreError {
}
}

impl From<tonic::Status> for FirestoreError {
fn from(status: tonic::Status) -> Self {
impl From<gcloud_sdk::tonic::Status> 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}"),
Expand All @@ -198,7 +198,7 @@ impl From<tonic::Status> 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::<hyper::Error>() {
Some(err) if err.is_closed() => {
Expand Down Expand Up @@ -406,8 +406,8 @@ impl From<std::io::Error> for FirestoreError {
}

#[cfg(feature = "caching-persistent")]
impl From<prost::EncodeError> for FirestoreError {
fn from(err: prost::EncodeError) -> Self {
impl From<gcloud_sdk::prost::EncodeError> for FirestoreError {
fn from(err: gcloud_sdk::prost::EncodeError) -> Self {
FirestoreError::SerializeError(FirestoreSerializationError::new(
FirestoreErrorPublicGenericDetails::new("PrototBufEncodeError".into()),
format!("Protobuf serialization error: {err}"),
Expand All @@ -416,8 +416,8 @@ impl From<prost::EncodeError> for FirestoreError {
}

#[cfg(feature = "caching-persistent")]
impl From<prost::DecodeError> for FirestoreError {
fn from(err: prost::DecodeError) -> Self {
impl From<gcloud_sdk::prost::DecodeError> for FirestoreError {
fn from(err: gcloud_sdk::prost::DecodeError) -> Self {
FirestoreError::SerializeError(FirestoreSerializationError::new(
FirestoreErrorPublicGenericDetails::new("PrototBufDecodeError".into()),
format!("Protobuf deserialization error: {err}"),
Expand Down
6 changes: 3 additions & 3 deletions src/timestamp_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::errors::*;
use crate::FirestoreResult;
use chrono::prelude::*;

pub fn from_timestamp(ts: prost_types::Timestamp) -> FirestoreResult<DateTime<Utc>> {
pub fn from_timestamp(ts: gcloud_sdk::prost_types::Timestamp) -> FirestoreResult<DateTime<Utc>> {
if let Some(dt) = chrono::NaiveDateTime::from_timestamp_opt(ts.seconds, ts.nanos as u32) {
Ok(DateTime::<Utc>::from_naive_utc_and_offset(dt, Utc))
} else {
Expand All @@ -14,8 +14,8 @@ pub fn from_timestamp(ts: prost_types::Timestamp) -> FirestoreResult<DateTime<Ut
}
}

pub fn to_timestamp(dt: DateTime<Utc>) -> prost_types::Timestamp {
prost_types::Timestamp {
pub fn to_timestamp(dt: DateTime<Utc>) -> gcloud_sdk::prost_types::Timestamp {
gcloud_sdk::prost_types::Timestamp {
seconds: dt.timestamp(),
nanos: dt.nanosecond() as i32,
}
Expand Down

0 comments on commit 17990ed

Please sign in to comment.