Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

162 move the repository module of the mediator coordination crate to a separate crate #170

Merged
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ members = [
"crates/plugins/did-endpoint",
"crates/plugins/mediator-coordination",
"crates/plugins/oob-messages",
"crates/database",
]


Expand All @@ -24,6 +25,7 @@ plugin-api = { path = "./crates/plugin-api", version = "0.1.0" }
did-endpoint = { path = "./crates/plugins/did-endpoint", version = "0.1.0" }
oob-messages = { path = "./crates/plugins/oob-messages", version = "0.1.0" }
mediator-coordination = { path = "./crates/plugins/mediator-coordination", version = "0.1.0" }
database = { path = "./crates/database", version = "0.1.0" }

# Other common dependencies
serde = "1.0"
Expand Down
37 changes: 37 additions & 0 deletions crates/database/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[package]
name = "database"
version = "0.1.0"
edition = "2021"

[dependencies]
did-utils.workspace = true
did-endpoint.workspace = true
plugin-api.workspace = true
keystore.workspace = true

chrono.workspace = true
mongodb.workspace = true
async-trait.workspace = true
multibase.workspace = true
serde.workspace = true
serde_json.workspace = true
tracing.workspace = true
thiserror.workspace = true
json-canon.workspace = true
didcomm = { workspace = true, features = ["uniffi"] }
tokio = { workspace = true, features = ["full"] }
axum = { workspace = true, features = ["macros"] }
uuid = { workspace = true, features = ["v4"] }
hyper = { workspace = true, features = ["full"] }
ndefokou marked this conversation as resolved.
Show resolved Hide resolved

[dev-dependencies]
dotenv-flow = "0.15.0"
hyper = "0.14.27"
json-canon = "0.1.3"
tokio = { version = "1.27.0", default-features = false, features = ["macros", "rt"] }
tokio-test = "0.4.2"
tower = { version = "0.4.13", features = ["util"] }

[features]
default = ["stateful"]
stateful = []
ndefokou marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use async_trait::async_trait;
use mongodb::bson::{oid::ObjectId, Document as BsonDocument};
use serde::{Deserialize, Serialize};
use thiserror::Error;

use mongodb::error::Error as MongoError;
/// A trait representing an abstract resource.
/// Any type implementing this trait should also implement `Serialize`.
pub trait Entity: Sized + Serialize {}
pub trait Entity: Sized + Serialize {}
ndefokou marked this conversation as resolved.
Show resolved Hide resolved

/// Definition of custom errors for repository operations
#[derive(Debug, Serialize, Deserialize, Error)]
Expand Down Expand Up @@ -41,3 +41,9 @@ pub trait Repository<Entity>: Sync + Send {
/// Deletes a single entity by its identifier.
async fn delete_one(&self, entity_id: ObjectId) -> Result<(), RepositoryError>;
}

impl From<MongoError> for RepositoryError {
fn from(error: MongoError) -> Self {
RepositoryError::Generic(error.to_string())
}
}
1 change: 1 addition & 0 deletions crates/plugins/mediator-coordination/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ did-utils.workspace = true
did-endpoint.workspace = true
plugin-api.workspace = true
keystore.workspace = true
database.workspace = true

chrono.workspace = true
mongodb.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/plugins/mediator-coordination/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ mod jose;
mod model;
mod repository;
mod util;
mod web;
mod web;
2 changes: 1 addition & 1 deletion crates/plugins/mediator-coordination/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use mongodb::{ options::ClientOptions, Client, Database};
use std::sync::Arc;

use crate::{
repository::stateful::coord::{MongoConnectionRepository, MongoMessagesRepository, MongoSecretsRepository},
repository::stateful::{MongoConnectionRepository, MongoMessagesRepository, MongoSecretsRepository},
util,
web::{self, AppState, AppStateRepository},
};
Expand Down
13 changes: 1 addition & 12 deletions crates/plugins/mediator-coordination/src/repository/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1 @@
pub mod stateful;
pub mod traits;

use mongodb::error::Error as MongoError;

use traits::RepositoryError;

impl From<MongoError> for RepositoryError {
fn from(error: MongoError) -> Self {
RepositoryError::Generic(error.to_string())
}
}
pub(crate) mod stateful;
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use async_trait::async_trait;
use database::{Entity, Repository, RepositoryError};
use mongodb::{
bson::{self, doc, oid::ObjectId, Bson, Document as BsonDocument},
Collection, Database,
};

use crate::{
model::stateful::entity::{Connection, RoutedMessage, Secrets},
repository::traits::{Entity, Repository, RepositoryError},
};

impl Entity for Connection {}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ mod tests {
use super::*;

use crate::{
repository::stateful::coord::tests::MockConnectionRepository, web::handler::tests as global,
repository::stateful::tests::MockConnectionRepository, web::handler::tests as global,
};

#[allow(clippy::needless_update)]
Expand Down
7 changes: 4 additions & 3 deletions crates/plugins/mediator-coordination/src/web/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub mod tests {

use crate::{
didcomm::bridge::LocalSecretsResolver,
repository::stateful::coord::tests::{
repository::stateful::tests::{
MockConnectionRepository, MockMessagesRepository, MockSecretsRepository,
},
util::{self, MockFileSystem},
Expand All @@ -104,7 +104,7 @@ pub mod tests {
let repository = AppStateRepository {
connection_repository: Arc::new(MockConnectionRepository::from(vec![])),
secret_repository: Arc::new(MockSecretsRepository::from(vec![])),
message_repository: Arc::new(MockMessagesRepository::from(vec![])),
message_repository: Arc::new(MockMessagesRepository::from(vec![])), // Merged from origin
ndefokou marked this conversation as resolved.
Show resolved Hide resolved
};

let state = Arc::new(AppState::from(
Expand Down Expand Up @@ -193,12 +193,13 @@ pub mod tests {
}
}


#[cfg(test)]
mod tests2 {
use super::{tests as global, *};
use crate::{
constant::KEYLIST_UPDATE_RESPONSE_2_0,
repository::stateful::coord::tests::MockConnectionRepository,
repository::stateful::tests::MockConnectionRepository,
web::{self, AppStateRepository},
};

Expand Down
2 changes: 1 addition & 1 deletion crates/plugins/mediator-coordination/src/web/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
mod midlw;

use axum::{middleware, routing::post, Router};
use database::Repository;
use keystore::KeyStore;
use did_utils::{didcore::Document, jwk::Jwk};
use std::sync::Arc;

use crate::{
didcomm::bridge::{LocalDIDResolver, LocalSecretsResolver},
model::stateful::entity::{Connection, RoutedMessage, Secrets},
repository::traits::Repository,
util,
};

Expand Down Expand Up @@ -48,7 +48,7 @@
pub struct AppStateRepository {
pub connection_repository: Arc<dyn Repository<Connection>>,
pub secret_repository: Arc<dyn Repository<Secrets>>,
pub message_repository: Arc<dyn Repository<RoutedMessage>>,

Check warning on line 51 in crates/plugins/mediator-coordination/src/web/mod.rs

View workflow job for this annotation

GitHub Actions / Build and Test

field `message_repository` is never read

Check warning on line 51 in crates/plugins/mediator-coordination/src/web/mod.rs

View workflow job for this annotation

GitHub Actions / Build and Test

field `message_repository` is never read
}

impl AppState {
Expand Down
Loading