Compare commits

...

2 commits

65 changed files with 113 additions and 101 deletions

View file

@ -1,5 +1,5 @@
[package] [package]
name = "caretta" name = "caretta-sync"
edition.workspace = true edition.workspace = true
version.workspace = true version.workspace = true
description.workspace = true description.workspace = true
@ -7,21 +7,22 @@ license.workspace = true
repository.workspace = true repository.workspace = true
[features] [features]
default = [] default = ["dep:caretta-sync-macros"]
mobile = ["dep:caretta-mobile"] mobile = ["dep:caretta-sync-mobile"]
desktop = ["dep:caretta-desktop"] desktop = ["dep:caretta-sync-cli"]
test = ["caretta-core/test"] test = ["caretta-sync-core/test"]
[dependencies] [dependencies]
caretta-core.workspace = true caretta-sync-core.workspace = true
caretta-desktop = { path="desktop", optional = true } caretta-sync-cli = { path="cli", optional = true }
caretta-mobile = { path = "mobile", optional = true } caretta-sync-mobile = { path = "mobile", optional = true }
caretta-sync-macros = { path="macros", optional = true}
[dev-dependencies] [dev-dependencies]
caretta-core = {workspace = true, features = ["test"]} caretta-sync-core = {workspace = true, features = ["test"]}
[workspace] [workspace]
members = [ ".", "core", "core/macros", "desktop", "mobile", "examples/*" ] members = [ ".", "core", "macros", "cli", "mobile", "examples/demo/*" ]
resolver = "3" resolver = "3"
[workspace.package] [workspace.package]
@ -36,7 +37,7 @@ chrono = "0.4.41"
ciborium = "0.2.2" ciborium = "0.2.2"
clap = { version = "4.5.38", features = ["derive"] } clap = { version = "4.5.38", features = ["derive"] }
dioxus = { version = "0.6.0", features = [] } 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" ] } 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 = { 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"] } sea-orm-migration = { version = "1.1.0", features = ["runtime-tokio-rustls", "sqlx-postgres"] }

View file

@ -1,5 +1,5 @@
[package] [package]
name = "caretta-desktop" name = "caretta-sync-cli"
edition.workspace = true edition.workspace = true
version.workspace = true version.workspace = true
description.workspace = true description.workspace = true
@ -8,13 +8,13 @@ repository.workspace = true
[features] [features]
default = [] default = []
test = ["caretta-core/test"] test = ["caretta-sync-core/test"]
[dependencies] [dependencies]
ciborium.workspace = true ciborium.workspace = true
clap.workspace = true clap.workspace = true
dirs = "6.0.0" dirs = "6.0.0"
caretta-core = { workspace = true, features = ["desktop"] } caretta-sync-core = { workspace = true, features = ["cli"] }
libp2p.workspace = true libp2p.workspace = true
sea-orm.workspace = true sea-orm.workspace = true
serde.workspace = true serde.workspace = true
@ -25,7 +25,5 @@ tonic.workspace = true
uuid.workspace = true uuid.workspace = true
[dev-dependencies] [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 std::{net::IpAddr, path::PathBuf, sync::LazyLock};
use clap::Args; use clap::Args;
use caretta_core::{ use caretta_sync_core::{
config::{Config, ConfigError, PartialConfig, PartialP2pConfig, PartialStorageConfig}, config::{Config, ConfigError, PartialConfig, PartialP2pConfig, PartialStorageConfig},
utils::{emptiable::Emptiable, mergeable::Mergeable} utils::{emptiable::Emptiable, mergeable::Mergeable}
}; };

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,5 +1,5 @@
use clap::Args; use clap::Args;
use caretta_core::utils::runnable::Runnable; use caretta_sync_core::utils::runnable::Runnable;
use crate::cli::ConfigArgs; use crate::cli::ConfigArgs;
#[derive(Debug, Args)] #[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; use clap::Args;
#[derive(Args, Debug)] #[derive(Args, Debug)]

View file

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

View file

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

View file

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

View file

@ -1,19 +1,28 @@
use caretta_example_core::server::Server; use std::marker::PhantomData;
use clap::Args; 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 libp2p::{noise, ping, swarm::{NetworkBehaviour, SwarmEvent}, tcp, yamux, Swarm};
use super::ConfigArgs; use super::ConfigArgs;
#[derive(Args, Debug)] #[derive(Args, Debug)]
pub struct ServerCommandArgs { pub struct ServeCommandArgs<T>
where
T: ServerTrait
{
#[arg(skip)]
server: PhantomData<T>,
#[command(flatten)] #[command(flatten)]
config: ConfigArgs, config: ConfigArgs,
} }
impl Runnable for ServerCommandArgs { impl<T> Runnable for ServeCommandArgs<T>
where
T: ServerTrait
{
async fn run(self, app_name: &'static str) { async fn run(self, app_name: &'static str) {
let config = CONFIG.get_or_init::<Config>(self.config.into_config(app_name).await).await; 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; 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] [package]
name = "caretta-core" name = "caretta-sync-core"
edition.workspace = true edition.workspace = true
version.workspace = true version.workspace = true
description.workspace = true description.workspace = true
@ -8,14 +8,11 @@ repository.workspace = true
[features] [features]
default = [] default = []
desktop = ["dep:clap", "macros"] cli = ["dep:clap"]
mobile = ["macros"] test = ["dep:tempfile", ]
macros = ["dep:caretta-macros"]
test = ["dep:tempfile", "macros"]
[dependencies] [dependencies]
base64 = "0.22.1" base64 = "0.22.1"
caretta-macros = { path = "macros", optional = true }
chrono.workspace = true chrono.workspace = true
chrono-tz = "0.10.3" chrono-tz = "0.10.3"
ciborium.workspace = true ciborium.workspace = true

View file

@ -1,4 +1,4 @@
fn main() -> Result<(), Box<dyn std::error::Error>> { 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(()) Ok(())
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -10,7 +10,7 @@ pub mod runnable;
/// use chrono::Utc; /// use chrono::Utc;
/// use std::time::SystemTime; /// use std::time::SystemTime;
/// use prost_types::Timestamp; /// 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_utc = Utc::now();
/// let now_timestamp = utc_to_timestamp(&now_utc); /// 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 std::time::SystemTime;
/// use prost_types::Timestamp; /// 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_timestamp = Timestamp::from(SystemTime::now());
/// let now_utc = timestamp_to_utc(&now_timestamp); /// let now_utc = timestamp_to_utc(&now_timestamp);

View file

@ -1,5 +1,5 @@
#[cfg(feature="macros")] #[cfg(feature="macros")]
pub use caretta_macros::Runnable; pub use caretta_sync_macros::Runnable;
pub trait Runnable { pub trait Runnable {
async fn run(self, app_name: &'static str); 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] [package]
name = "caretta-example-core" name = "caretta-sync-demo-core"
edition.workspace = true edition.workspace = true
version.workspace = true version.workspace = true
description.workspace = true description.workspace = true
@ -7,7 +7,7 @@ license.workspace = true
repository.workspace = true repository.workspace = true
[dependencies] [dependencies]
caretta.path = "../.." caretta-sync.path = "../../.."
libp2p.workspace = true libp2p.workspace = true
tokio.workspace = true tokio.workspace = true
tokio-stream = { version = "0.1.17", features = ["net"] } 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 libp2p::{futures::StreamExt, noise, swarm::SwarmEvent, tcp, yamux};
use tokio::net::UnixListener; use tokio::net::UnixListener;
use tokio_stream::wrappers::UnixListenerStream; use tokio_stream::wrappers::UnixListenerStream;
#[derive(Debug)]
pub struct Server{} pub struct Server{}
impl ServerTrait for 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 clap::{Parser, Subcommand};
use caretta::{cli::*, utils::runnable::Runnable}; use caretta::{cli::*, utils::runnable::Runnable};
pub use server::*;
#[derive(Debug, Parser, Runnable)] #[derive(Debug, Parser, Runnable)]
@ -17,5 +16,5 @@ pub enum CliCommand {
Device(DeviceCommandArgs), Device(DeviceCommandArgs),
Logs(LogsCommandArgs), Logs(LogsCommandArgs),
Peer(PeerCommandArgs), Peer(PeerCommandArgs),
Server(ServerCommandArgs), Serve(ServeCommandArgs<Server>),
} }

View file

@ -1,5 +1,5 @@
use caretta::utils::runnable::Runnable; use caretta::utils::runnable::Runnable;
use caretta_example_core::global::APP_NAME; use caretta_sync_example_core::global::APP_NAME;
use clap::Parser; use clap::Parser;
use crate::cli::Cli; 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] [package]
name = "caretta-macros" name = "caretta-sync-macros"
edition.workspace = true edition.workspace = true
version.workspace = true version.workspace = true
description.workspace = true description.workspace = true
@ -17,7 +17,7 @@ syn = { version = "2.0.104", features = ["full"] }
[dev-dependencies] [dev-dependencies]
chrono.workspace = true chrono.workspace = true
caretta-core.workspace = true caretta-sync-core.workspace = true
sea-orm.workspace = true sea-orm.workspace = true
tokio.workspace = true tokio.workspace = true
uuid.workspace = true uuid.workspace = true

View file

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

View file

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

View file

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

View file

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

View file

@ -1,5 +1,5 @@
[package] [package]
name = "caretta-mobile" name = "caretta-sync-mobile"
edition.workspace = true edition.workspace = true
version.workspace = true version.workspace = true
description.workspace = true description.workspace = true
@ -8,7 +8,7 @@ repository.workspace = true
[features] [features]
default = [] default = []
test = ["caretta-core/test"] test = ["caretta-sync-core/test"]
[dependencies] [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")] #[cfg(feature = "desktop")]
pub use caretta_desktop::*; pub use caretta_sync_desktop::*;
#[cfg(feature = "mobile")] #[cfg(feature = "mobile")]
pub use caretta_mobile::*; pub use caretta_sync_mobile::*;