Compare commits

...

2 commits

65 changed files with 113 additions and 101 deletions

View file

@ -1,5 +1,5 @@
[package]
name = "caretta"
name = "caretta-sync"
edition.workspace = true
version.workspace = true
description.workspace = true
@ -7,21 +7,22 @@ license.workspace = true
repository.workspace = true
[features]
default = []
mobile = ["dep:caretta-mobile"]
desktop = ["dep:caretta-desktop"]
test = ["caretta-core/test"]
default = ["dep:caretta-sync-macros"]
mobile = ["dep:caretta-sync-mobile"]
desktop = ["dep:caretta-sync-cli"]
test = ["caretta-sync-core/test"]
[dependencies]
caretta-core.workspace = true
caretta-desktop = { path="desktop", optional = true }
caretta-mobile = { path = "mobile", optional = true }
caretta-sync-core.workspace = true
caretta-sync-cli = { path="cli", optional = true }
caretta-sync-mobile = { path = "mobile", optional = true }
caretta-sync-macros = { path="macros", optional = true}
[dev-dependencies]
caretta-core = {workspace = true, features = ["test"]}
caretta-sync-core = {workspace = true, features = ["test"]}
[workspace]
members = [ ".", "core", "core/macros", "desktop", "mobile", "examples/*" ]
members = [ ".", "core", "macros", "cli", "mobile", "examples/demo/*" ]
resolver = "3"
[workspace.package]
@ -36,7 +37,7 @@ chrono = "0.4.41"
ciborium = "0.2.2"
clap = { version = "4.5.38", features = ["derive"] }
dioxus = { version = "0.6.0", features = [] }
caretta-core.path = "core"
caretta-sync-core.path = "core"
libp2p = { version = "0.55.0", features = ["macros", "mdns", "noise", "ping", "tcp", "tokio", "yamux" ] }
sea-orm = { version = "1.1.11", features = ["sqlx-sqlite", "runtime-tokio-native-tls", "macros", "with-chrono", "with-uuid"] }
sea-orm-migration = { version = "1.1.0", features = ["runtime-tokio-rustls", "sqlx-postgres"] }

View file

@ -1,5 +1,5 @@
[package]
name = "caretta-desktop"
name = "caretta-sync-cli"
edition.workspace = true
version.workspace = true
description.workspace = true
@ -8,13 +8,13 @@ repository.workspace = true
[features]
default = []
test = ["caretta-core/test"]
test = ["caretta-sync-core/test"]
[dependencies]
ciborium.workspace = true
clap.workspace = true
dirs = "6.0.0"
caretta-core = { workspace = true, features = ["desktop"] }
caretta-sync-core = { workspace = true, features = ["cli"] }
libp2p.workspace = true
sea-orm.workspace = true
serde.workspace = true
@ -25,7 +25,5 @@ tonic.workspace = true
uuid.workspace = true
[dev-dependencies]
caretta-core = {workspace = true, features = ["test"]}
caretta-sync-core = {workspace = true, features = ["test"]}
[build-dependencies]
tonic-prost-build = "0.14.0"

View file

@ -1,7 +1,7 @@
use std::{net::IpAddr, path::PathBuf, sync::LazyLock};
use clap::Args;
use caretta_core::{
use caretta_sync_core::{
config::{Config, ConfigError, PartialConfig, PartialP2pConfig, PartialStorageConfig},
utils::{emptiable::Emptiable, mergeable::Mergeable}
};

View file

@ -1,5 +1,5 @@
use clap::Args;
use caretta_core::utils::runnable::Runnable;
use caretta_sync_core::utils::runnable::Runnable;
use crate::cli::ConfigArgs;
#[derive(Debug, Args)]

View file

@ -1,5 +1,5 @@
use clap::Args;
use caretta_core::{config::PartialConfig, utils::runnable::Runnable};
use caretta_sync_core::{config::PartialConfig, utils::runnable::Runnable};
use crate::cli::ConfigArgs;
#[derive(Debug, Args)]

View file

@ -4,7 +4,7 @@ mod list;
pub use check::*;
pub use list::*;
use caretta_core::utils::runnable::Runnable;
use caretta_sync_core::utils::runnable::Runnable;
use clap::{Args, Subcommand};

View file

@ -1,5 +1,5 @@
use clap::Args;
use caretta_core::utils::runnable::Runnable;
use caretta_sync_core::utils::runnable::Runnable;
use crate::cli::ConfigArgs;

View file

@ -1,5 +1,5 @@
use clap::Args;
use caretta_core::utils::runnable::Runnable;
use caretta_sync_core::utils::runnable::Runnable;
use crate::cli::ConfigArgs;
#[derive(Debug, Args)]

View file

@ -5,7 +5,7 @@ mod remove;
mod scan;
pub use add::DeviceAddCommandArgs;
use caretta_core::utils::runnable::Runnable;
use caretta_sync_core::utils::runnable::Runnable;
use libp2p::{Multiaddr, PeerId};
pub use list::DeviceListCommandArgs;
pub use ping::DevicePingCommandArgs;

View file

@ -1,5 +1,5 @@
use clap::Args;
use caretta_core::utils::runnable::Runnable;
use caretta_sync_core::utils::runnable::Runnable;
use crate::cli::{ConfigArgs, PeerArgs};
#[derive(Debug, Args)]

View file

@ -1,5 +1,5 @@
use clap::Args;
use caretta_core::utils::runnable::Runnable;
use caretta_sync_core::utils::runnable::Runnable;
use crate::cli::{ConfigArgs, DeviceArgs};
#[derive(Debug, Args)]

View file

@ -1,5 +1,5 @@
use clap::Args;
use caretta_core::utils::runnable::Runnable;
use caretta_sync_core::utils::runnable::Runnable;
use crate::cli::ConfigArgs;
#[derive(Debug, Args)]

View file

@ -1,4 +1,4 @@
use caretta_core::utils::runnable::Runnable;
use caretta_sync_core::utils::runnable::Runnable;
use clap::Args;
#[derive(Args, Debug)]

View file

@ -5,9 +5,11 @@ mod config;
mod device;
mod logs;
mod peer;
mod serve;
pub use args::*;
pub use config::*;
pub use device::*;
pub use logs::*;
pub use peer::*;
pub use serve::*;

View file

@ -1,5 +1,5 @@
use clap::Args;
use caretta_core::utils::runnable::Runnable;
use caretta_sync_core::utils::runnable::Runnable;
use crate::cli::{ConfigArgs, PeerArgs};
#[derive(Debug, Args)]

View file

@ -1,5 +1,5 @@
use clap::Args;
use caretta_core::utils::runnable::Runnable;
use caretta_sync_core::utils::runnable::Runnable;
use crate::cli::{ConfigArgs, PeerArgs};
#[derive(Debug, Args)]

View file

@ -1,19 +1,28 @@
use caretta_example_core::server::Server;
use std::marker::PhantomData;
use clap::Args;
use caretta::{config::Config, data::migration::DataMigrator, global::{CONFIG, DATABASE_CONNECTIONS}, server::ServerTrait, utils::runnable::Runnable};
use caretta_sync_core::{config::Config, data::migration::DataMigrator, global::{CONFIG, DATABASE_CONNECTIONS}, server::ServerTrait, utils::runnable::Runnable};
use libp2p::{noise, ping, swarm::{NetworkBehaviour, SwarmEvent}, tcp, yamux, Swarm};
use super::ConfigArgs;
#[derive(Args, Debug)]
pub struct ServerCommandArgs {
pub struct ServeCommandArgs<T>
where
T: ServerTrait
{
#[arg(skip)]
server: PhantomData<T>,
#[command(flatten)]
config: ConfigArgs,
}
impl Runnable for ServerCommandArgs {
impl<T> Runnable for ServeCommandArgs<T>
where
T: ServerTrait
{
async fn run(self, app_name: &'static str) {
let config = CONFIG.get_or_init::<Config>(self.config.into_config(app_name).await).await;
let _ = DATABASE_CONNECTIONS.get_or_init_unchecked(&config, DataMigrator).await;
Server::serve_all(config).await.unwrap();
T::serve_all(config).await.unwrap();
}
}

View file

@ -1,5 +1,5 @@
[package]
name = "caretta-core"
name = "caretta-sync-core"
edition.workspace = true
version.workspace = true
description.workspace = true
@ -8,14 +8,11 @@ repository.workspace = true
[features]
default = []
desktop = ["dep:clap", "macros"]
mobile = ["macros"]
macros = ["dep:caretta-macros"]
test = ["dep:tempfile", "macros"]
cli = ["dep:clap"]
test = ["dep:tempfile", ]
[dependencies]
base64 = "0.22.1"
caretta-macros = { path = "macros", optional = true }
chrono.workspace = true
chrono-tz = "0.10.3"
ciborium.workspace = true

View file

@ -1,4 +1,4 @@
fn main() -> Result<(), Box<dyn std::error::Error>> {
tonic_prost_build::compile_protos("proto/caretta.proto")?;
tonic_prost_build::compile_protos("proto/caretta_sync.proto")?;
Ok(())
}

View file

@ -1,5 +1,5 @@
syntax = "proto3";
package caretta;
package caretta_sync;
import "google/protobuf/timestamp.proto";
enum PeerListOrderBy {

View file

@ -1,6 +1,6 @@
use sea_orm::{prelude::*, query::*, sea_query::SimpleExpr, *};
#[cfg(feature="macros")]
pub use caretta_macros::SyncableModel;
pub use caretta_sync_macros::SyncableModel;
pub trait SyncableModel: ModelTrait<Entity = Self::SyncableEntity> {
type SyncableEntity: SyncableEntity<SyncableModel = Self>;
fn get_timestamp(&self) -> DateTimeUtc;

View file

@ -28,7 +28,7 @@ pub enum Error {
Noise(#[from] libp2p::noise::Error),
#[error("Parse OsString error: {0:?}")]
OsStringConvert(std::ffi::OsString),
#[cfg(feature="desktop")]
#[cfg(feature="cli")]
#[error("Parse args error: {0}")]
ParseCommand(#[from] clap::Error),
#[error("toml deserialization error: {0}")]

View file

@ -1,5 +1,5 @@
mod cached_address;
mod cached_peer;
tonic::include_proto!("caretta");
tonic::include_proto!("caretta_sync");

View file

@ -1,6 +1,6 @@
use std::collections::{HashMap, HashSet};
#[cfg(feature="macros")]
pub use caretta_macros::Emptiable;
pub use caretta_sync_macros::Emptiable;
pub trait Emptiable{
fn empty() -> Self;

View file

@ -1,5 +1,5 @@
#[cfg(feature="macros")]
pub use caretta_macros::Mergeable;
pub use caretta_sync_macros::Mergeable;
pub trait Mergeable: Sized {
fn merge(&mut self, other: Self);
}

View file

@ -10,7 +10,7 @@ pub mod runnable;
/// use chrono::Utc;
/// use std::time::SystemTime;
/// use prost_types::Timestamp;
/// use caretta_core::utils::utc_to_timestamp;
/// use caretta_sync_core::utils::utc_to_timestamp;
///
/// let now_utc = Utc::now();
/// let now_timestamp = utc_to_timestamp(&now_utc);
@ -27,7 +27,7 @@ pub fn utc_to_timestamp(utc: &DateTime<Utc>) -> Timestamp {
/// ```
/// use std::time::SystemTime;
/// use prost_types::Timestamp;
/// use caretta_core::utils::timestamp_to_utc;
/// use caretta_sync_core::utils::timestamp_to_utc;
///
/// let now_timestamp = Timestamp::from(SystemTime::now());
/// let now_utc = timestamp_to_utc(&now_timestamp);

View file

@ -1,5 +1,5 @@
#[cfg(feature="macros")]
pub use caretta_macros::Runnable;
pub use caretta_sync_macros::Runnable;
pub trait Runnable {
async fn run(self, app_name: &'static str);

View file

@ -1 +0,0 @@
pub const APP_NAME: &str = "caretta_demo";

View file

@ -1,5 +1,5 @@
[package]
name = "caretta-example-core"
name = "caretta-sync-demo-core"
edition.workspace = true
version.workspace = true
description.workspace = true
@ -7,7 +7,7 @@ license.workspace = true
repository.workspace = true
[dependencies]
caretta.path = "../.."
caretta-sync.path = "../../.."
libp2p.workspace = true
tokio.workspace = true
tokio-stream = { version = "0.1.17", features = ["net"] }

View file

@ -0,0 +1 @@
pub const APP_NAME: &str = "caretta_sync_demo";

View file

@ -7,6 +7,8 @@ use caretta::{
use libp2p::{futures::StreamExt, noise, swarm::SwarmEvent, tcp, yamux};
use tokio::net::UnixListener;
use tokio_stream::wrappers::UnixListenerStream;
#[derive(Debug)]
pub struct Server{}
impl ServerTrait for Server {

View file

@ -0,0 +1,17 @@
[package]
name = "caretta-sync-demo-desktop"
edition.workspace = true
version.workspace = true
description.workspace = true
license.workspace = true
repository.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
clap.workspace = true
caretta-sync = { path = "../../..", features = ["desktop", "test"] }
caretta-sync-demo-core.path = "../core"
libp2p.workspace = true
tokio.workspace = true

View file

@ -1,7 +1,6 @@
mod server;
use caretta_sync_example_core::server::Server;
use clap::{Parser, Subcommand};
use caretta::{cli::*, utils::runnable::Runnable};
pub use server::*;
#[derive(Debug, Parser, Runnable)]
@ -17,5 +16,5 @@ pub enum CliCommand {
Device(DeviceCommandArgs),
Logs(LogsCommandArgs),
Peer(PeerCommandArgs),
Server(ServerCommandArgs),
Serve(ServeCommandArgs<Server>),
}

View file

@ -1,5 +1,5 @@
use caretta::utils::runnable::Runnable;
use caretta_example_core::global::APP_NAME;
use caretta_sync_example_core::global::APP_NAME;
use clap::Parser;
use crate::cli::Cli;

View file

@ -0,0 +1,10 @@
[package]
name = "caretta-sync-demo-mobile"
edition.workspace = true
version.workspace = true
description.workspace = true
license.workspace = true
repository.workspace = true
[dependencies]
caretta-sync-demo-core.path = "../core"

View file

@ -0,0 +1,3 @@
fn main() {
dioxus::launch(caretta_sync_examples_core::ui::plain::App);
}

View file

@ -1,14 +0,0 @@
[package]
name = "caretta-example-desktop"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
clap.workspace = true
caretta = { path = "../..", features = ["desktop", "test"] }
caretta-example-core.path = "../core"
libp2p.workspace = true
tokio.workspace = true

View file

@ -1,9 +0,0 @@
[package]
name = "caretta-example-mobile"
version = "0.1.0"
authors = ["fluo10 <fluo10.dev@fireturtle.net>"]
edition = "2021"
[dependencies]
dioxus.workspace = true
caretta-example-core.path = "../core"

View file

@ -1,3 +0,0 @@
fn main() {
dioxus::launch(caretta_examples_core::ui::plain::App);
}

View file

@ -1,5 +1,5 @@
[package]
name = "caretta-macros"
name = "caretta-sync-macros"
edition.workspace = true
version.workspace = true
description.workspace = true
@ -17,7 +17,7 @@ syn = { version = "2.0.104", features = ["full"] }
[dev-dependencies]
chrono.workspace = true
caretta-core.workspace = true
caretta-sync-core.workspace = true
sea-orm.workspace = true
tokio.workspace = true
uuid.workspace = true

View file

@ -1,7 +1,7 @@
use std::collections::{HashMap, HashSet};
use caretta_core::utils::emptiable::Emptiable;
use caretta_macros::Emptiable;
use caretta_sync_core::utils::emptiable::Emptiable;
use caretta_sync_macros::Emptiable;
#[derive(Debug, PartialEq, Emptiable)]
struct EmptiableStruct{

View file

@ -1,7 +1,7 @@
use std::collections::{HashMap, HashSet};
use caretta_core::utils::mergeable::Mergeable;
use caretta_macros::Mergeable;
use caretta_sync_core::utils::mergeable::Mergeable;
use caretta_sync_macros::Mergeable;
#[derive(Clone, Debug, PartialEq, Mergeable)]
struct MergeableStruct {

View file

@ -1,5 +1,5 @@
use caretta_core::utils::runnable::Runnable;
use caretta_macros::Runnable;
use caretta_sync_core::utils::runnable::Runnable;
use caretta_sync_macros::Runnable;
struct RunnableStruct1;

View file

@ -6,8 +6,8 @@ use sea_orm::{
prelude::*
}
};
use caretta_core::data::syncable::*;
use caretta_macros::SyncableModel;
use caretta_sync_core::data::syncable::*;
use caretta_sync_macros::SyncableModel;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, SyncableModel)]
#[sea_orm(table_name = "syncable")]

View file

@ -1,5 +1,5 @@
[package]
name = "caretta-mobile"
name = "caretta-sync-mobile"
edition.workspace = true
version.workspace = true
description.workspace = true
@ -8,7 +8,7 @@ repository.workspace = true
[features]
default = []
test = ["caretta-core/test"]
test = ["caretta-sync-core/test"]
[dependencies]
caretta-core.workspace = true
caretta-sync-core.workspace = true

View file

@ -1,5 +1,5 @@
pub use caretta_core::*;
pub use caretta_sync_core::*;
#[cfg(feature = "desktop")]
pub use caretta_desktop::*;
pub use caretta_sync_desktop::*;
#[cfg(feature = "mobile")]
pub use caretta_mobile::*;
pub use caretta_sync_mobile::*;