move out implementations to a separate crate

This commit is contained in:
tezlm 2024-02-13 19:49:21 -08:00
parent 4d5cd581da
commit bd0b350d11
Signed by: tezlm
GPG key ID: 649733FCD94AFBBA
22 changed files with 49 additions and 24 deletions

21
Cargo.lock generated
View file

@ -683,7 +683,6 @@ dependencies = [
"ed25519",
"ed25519-dalek",
"rand",
"rusqlite",
"serde",
"serde_json",
"sha2",
@ -697,10 +696,21 @@ dependencies = [
"anyhow",
"clap",
"dag-resolve",
"dag-resolve-impls",
"rusqlite",
"serde_json",
]
[[package]]
name = "dag-resolve-impls"
version = "0.1.0"
dependencies = [
"dag-resolve",
"rusqlite",
"serde",
"thiserror",
]
[[package]]
name = "der"
version = "0.7.8"
@ -1123,6 +1133,7 @@ version = "0.1.0"
dependencies = [
"anyhow",
"dag-resolve",
"dag-resolve-impls",
"iced",
"rusqlite",
"serde_json",
@ -2640,18 +2651,18 @@ dependencies = [
[[package]]
name = "thiserror"
version = "1.0.56"
version = "1.0.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad"
checksum = "1e45bcbe8ed29775f228095caf2cd67af7a4ccf756ebff23a306bf3e8b47b24b"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.56"
version = "1.0.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471"
checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81"
dependencies = [
"proc-macro2",
"quote",

View file

@ -9,6 +9,7 @@ edition = "2021"
[dependencies]
anyhow = { version = "1.0.79", features = ["backtrace"] }
clap = { version = "4.5.0", features = ["derive"] }
dag-resolve = { version = "0.1.0", path = "../lib" }
dag-resolve = { version = "0.1.0", path = "../proto" }
dag-resolve-impls = { version = "0.1.0", path = "../impls" }
rusqlite = { version = "0.30.0", features = ["bundled"] }
serde_json = "1.0.113"

View file

@ -8,10 +8,10 @@ use dag_resolve::{
actor::{ActorId, ActorSecret},
event::{CoreContent, Event, HashType, SignatureType},
resolver::Resolver,
resolvers::{forum::ForumResolver, kv::KVResolver},
room::Room,
Error,
};
use dag_resolve_impls::{resolvers::{forum::ForumResolver, kv::KVResolver}, stores::sqlite::Database};
use rusqlite::Connection;
#[derive(Parser)]
@ -43,7 +43,7 @@ struct State<R: Resolver> {
db: Rc<Connection>,
room: Room<R>,
secret: ActorSecret,
store: Box<dag_resolve::store::sqlite::Database>,
store: Box<Database>,
}
impl<R: Resolver> State<R> {
@ -113,7 +113,7 @@ impl<R: Resolver> State<R> {
)?;
}
let db = Rc::new(db);
let store = dag_resolve::store::sqlite::Database::from_conn(db.clone())
let store = Database::from_conn(db.clone())
.init(room.get_resolver().get_state_config())?;
Ok(State {
db,
@ -156,7 +156,7 @@ fn open(path: impl AsRef<Path>) -> Result<Opened> {
drop(q);
dbg!(&room);
let db = Rc::new(db);
let store = dag_resolve::store::sqlite::Database::from_conn(db.clone())
let store = Database::from_conn(db.clone())
.init(room.get_resolver().get_state_config())?;
Ok(Opened::Kv(State {
db,
@ -177,7 +177,7 @@ fn open(path: impl AsRef<Path>) -> Result<Opened> {
drop(q);
dbg!(&room);
let db = Rc::new(db);
let store = dag_resolve::store::sqlite::Database::from_conn(db.clone())
let store = Database::from_conn(db.clone())
.init(room.get_resolver().get_state_config())?;
Ok(Opened::Forum(State {
db,

View file

@ -7,7 +7,8 @@ edition = "2021"
[dependencies]
anyhow = "1.0.79"
dag-resolve = { version = "0.1.0", path = "../lib" }
dag-resolve = { version = "0.1.0", path = "../proto" }
dag-resolve-impls = { version = "0.1.0", path = "../impls" }
iced = { version = "0.10.0", features = ["debug"] }
rusqlite = { version = "0.30.0", features = ["bundled"] }
serde_json = "1.0.113"

View file

@ -3,12 +3,13 @@ use std::{path::Path, rc::Rc, sync::Mutex};
use anyhow::Result;
use dag_resolve::{
actor::{ActorId, ActorSecret},
event::{CoreContent, Event, HashType, SignatureType},
event::{CoreContent, Event},
proto::table::{State as _, Table as _},
resolver::Resolver,
resolvers::kv::{KVEventContent, KVResolver},
room::Room,
};
use dag_resolve_impls::resolvers::kv::{KVEventContent, KVResolver};
use dag_resolve_impls::stores::sqlite::Database;
use iced::{
keyboard::KeyCode,
widget::{button, row, text, text_input, Column},
@ -159,7 +160,7 @@ struct State<R: Resolver> {
db: Rc<rusqlite::Connection>,
room: Room<R>,
secret: ActorSecret,
store: Box<dag_resolve::store::sqlite::Database>,
store: Box<Database>,
}
impl<R: Resolver> State<R> {
@ -177,7 +178,7 @@ impl<R: Resolver> State<R> {
}
}
fn append_event(&mut self, event: Event<R::EventType>) -> Result<()> {
fn _append_event(&mut self, event: Event<R::EventType>) -> Result<()> {
match self.room.append_event(event) {
Ok(event) => {
self.db.execute(
@ -228,7 +229,7 @@ fn open(path: impl AsRef<Path>) -> Result<State<KVResolver>> {
drop(q);
dbg!(&room);
let db = Rc::new(db);
let store = dag_resolve::store::sqlite::Database::from_conn(db.clone())
let store = Database::from_conn(db.clone())
.init(room.get_resolver().get_state_config())?;
Ok(State {
db,

12
crates/impls/Cargo.toml Normal file
View file

@ -0,0 +1,12 @@
[package]
name = "dag-resolve-impls"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
dag-resolve = { version = "0.1.0", path = "../proto" }
rusqlite = { version = "0.30.0", features = ["bundled"] }
serde = { version = "1.0.196", features = ["derive"] }
thiserror = "1.0.57"

2
crates/impls/src/lib.rs Normal file
View file

@ -0,0 +1,2 @@
pub mod resolvers;
pub mod stores;

View file

@ -4,7 +4,7 @@ use std::cmp::Ordering;
use serde::{Deserialize, Serialize};
use crate::{
use dag_resolve::{
event::{CoreContent, Event, EventId},
proto::table::{
ColumnType, IndexType, State, StateConfig, TableConfig, TableRow, Text,

View file

@ -2,7 +2,7 @@
use serde::{Deserialize, Serialize};
use crate::{
use dag_resolve::{
event::{CoreContent, Event},
proto::table::{ColumnType, IndexType, State, StateConfig, TableConfig, TableRow},
resolver::{Resolver, ResolverEffect},

View file

@ -2,7 +2,7 @@
use std::{collections::HashMap, convert::Infallible, rc::Rc, sync::RwLock};
use crate::proto::table::{ColumnValue, Paginate, State, StateConfig, Table, TableRow};
use dag_resolve::proto::table::{ColumnValue, Paginate, State, StateConfig, Table, TableRow};
#[derive(Debug, Default)]
pub struct MemoryStore {

View file

@ -2,7 +2,7 @@
use std::{collections::HashMap, path::Path, rc::Rc};
use crate::proto::table::{self, State};
use dag_resolve::proto::table::{self, State};
use rusqlite::params_from_iter;
use thiserror::Error;

View file

@ -12,7 +12,6 @@ canonical_json = "0.5.0"
ed25519 = "2.2.3"
ed25519-dalek = { version = "2.1.1", features = ["rand_core"] }
rand = "0.8.5"
rusqlite = { version = "0.30.0", features = ["bundled"] }
serde = { version = "1.0.196", features = ["derive"] }
serde_json = "1.0.113"
sha2 = "0.10.8"

View file

@ -1,7 +1,5 @@
pub mod error;
pub mod proto;
pub mod resolvers;
pub mod store;
pub use error::{Error, Result};
pub use proto::{actor, event, resolver, room};