From bfca0dfbd72dbc4f728444e1c179c1e67ab0402c Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Tue, 18 Jun 2024 16:49:49 -0500 Subject: [PATCH] update --- Cargo.lock | 201 ++++++++++++++++++++++ apps/journal/manifest.yml | 4 + apps/journal/register.rn | 3 + crates/panorama-core/Cargo.toml | 1 + crates/panorama-core/build.rs | 1 + crates/panorama-core/src/state/apps.rs | 53 +++++- crates/panorama-core/src/state/journal.rs | 23 --- crates/panorama-daemon/src/lib.rs | 2 + 8 files changed, 262 insertions(+), 26 deletions(-) create mode 100644 apps/journal/manifest.yml create mode 100644 apps/journal/register.rn diff --git a/Cargo.lock b/Cargo.lock index 414e929..5dc7c04 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -806,6 +806,16 @@ dependencies = [ "objc", ] +[[package]] +name = "codespan-reporting" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" +dependencies = [ + "termcolor", + "unicode-width", +] + [[package]] name = "colorchoice" version = "1.0.1" @@ -944,6 +954,12 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "critical-section" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7059fff8937831a9ae6f0fe4d658ffabf58f2ca96aa9dec1c889f936f705f216" + [[package]] name = "crossbeam-channel" version = "0.5.13" @@ -2843,6 +2859,45 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2195bf6aa996a481483b29d62a7663eed3fe39600c460e323f8ff41e90bdd89b" +[[package]] +name = "musli" +version = "0.0.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c21124dd24833900879114414b877f2136f4b7b7a3b49756ecc5c36eca332bb" +dependencies = [ + "musli-macros", +] + +[[package]] +name = "musli-common" +version = "0.0.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "178446623aa62978aa0f894b2081bc11ea77c2119ccfe35be428ab9ddb495dfc" +dependencies = [ + "musli", +] + +[[package]] +name = "musli-macros" +version = "0.0.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f1ab0e4ac2721bc4fa3528a6a2640c1c30c36c820f8c85159252fbf6c2fac24" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", +] + +[[package]] +name = "musli-storage" +version = "0.0.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2fc1f80b166f611c462e1344220e9b3a9ad37c885e43039d5d2e6887445937c" +dependencies = [ + "musli", + "musli-common", +] + [[package]] name = "ndk" version = "0.7.0" @@ -2916,6 +2971,30 @@ dependencies = [ "winapi", ] +[[package]] +name = "num" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35bd024e8b2ff75562e5f34e7f4905839deb4b22955ef5e73d2fea1b9813cb23" +dependencies = [ + "num-bigint", + "num-complex", + "num-integer", + "num-iter", + "num-rational", + "num-traits", +] + +[[package]] +name = "num-bigint" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c165a9ab64cf766f73521c0dd2cfdff64f488b8f0b3e621face3462d3db536d7" +dependencies = [ + "num-integer", + "num-traits", +] + [[package]] name = "num-bigint-dig" version = "0.8.4" @@ -2933,6 +3012,15 @@ dependencies = [ "zeroize", ] +[[package]] +name = "num-complex" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495" +dependencies = [ + "num-traits", +] + [[package]] name = "num-conv" version = "0.1.0" @@ -2959,6 +3047,17 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-rational" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824" +dependencies = [ + "num-bigint", + "num-integer", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.19" @@ -3162,6 +3261,10 @@ name = "once_cell" version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +dependencies = [ + "critical-section", + "portable-atomic", +] [[package]] name = "oneshot" @@ -3284,6 +3387,7 @@ dependencies = [ "futures", "itertools 0.13.0", "miette", + "rune", "serde", "serde_json", "sqlx", @@ -3628,6 +3732,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "portable-atomic" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7170ef9988bc169ba16dd36a7fa041e5c4cbeb6a35b76d4c03daded371eae7c0" + [[package]] name = "powerfmt" version = "0.2.0" @@ -4019,6 +4129,78 @@ dependencies = [ "zeroize", ] +[[package]] +name = "rune" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37f1ad3981e4bf4d336b913b33cab141192f7ce196b6faf3f489ce454e94c55f" +dependencies = [ + "anyhow", + "codespan-reporting", + "futures-core", + "futures-util", + "itoa 1.0.11", + "musli", + "musli-storage", + "num", + "once_cell", + "pin-project", + "rune-alloc", + "rune-core", + "rune-macros", + "ryu", + "serde", + "tracing", +] + +[[package]] +name = "rune-alloc" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd786d0d250e5768210ab54b57841e5fc48e2c96a2b7e43104dabe47348ee221" +dependencies = [ + "ahash", + "pin-project", + "rune-alloc-macros", + "serde", +] + +[[package]] +name = "rune-alloc-macros" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb6a9c787416444401172f875c1361c9b78d21fecf10206e9a996693ee2d1023" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", +] + +[[package]] +name = "rune-core" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22249f328286279daf0f991dd04c09c30c8b7fda12fbb20391e3c041ba2dad22" +dependencies = [ + "byteorder", + "musli", + "rune-alloc", + "serde", + "twox-hash", +] + +[[package]] +name = "rune-macros" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32d7decd5a5f44e2e351f03f4d7dc6beab0c656baefd70528bfc375c1ab49b8d" +dependencies = [ + "proc-macro2", + "quote", + "rune-core", + "syn 2.0.66", +] + [[package]] name = "rust-embed" version = "8.4.0" @@ -5557,6 +5739,15 @@ dependencies = [ "utf-8", ] +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + [[package]] name = "terminal_size" version = "0.1.17" @@ -5917,6 +6108,16 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" +[[package]] +name = "twox-hash" +version = "1.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" +dependencies = [ + "cfg-if", + "static_assertions", +] + [[package]] name = "typenum" version = "1.17.0" diff --git a/apps/journal/manifest.yml b/apps/journal/manifest.yml new file mode 100644 index 0000000..df4ef0b --- /dev/null +++ b/apps/journal/manifest.yml @@ -0,0 +1,4 @@ +name: journal +version: 0.1.0 +panorama_version: 0.1.0 +description: Note taking app \ No newline at end of file diff --git a/apps/journal/register.rn b/apps/journal/register.rn new file mode 100644 index 0000000..fc1028a --- /dev/null +++ b/apps/journal/register.rn @@ -0,0 +1,3 @@ +pub fn main() { + let y = 1 + 2; +} \ No newline at end of file diff --git a/crates/panorama-core/Cargo.toml b/crates/panorama-core/Cargo.toml index a9f9511..00764a2 100644 --- a/crates/panorama-core/Cargo.toml +++ b/crates/panorama-core/Cargo.toml @@ -10,6 +10,7 @@ chrono = { version = "0.4.38", features = ["serde"] } futures = "0.3.30" itertools = "0.13.0" miette = { version = "5.5.0", features = ["fancy", "backtrace"] } +rune = "0.13.2" serde = { version = "1.0.203", features = ["derive"] } serde_json = "1.0.117" sqlx = { version = "0.7.4", features = ["runtime-tokio", "tls-rustls", "macros", "sqlite", "uuid", "chrono", "regexp"] } diff --git a/crates/panorama-core/build.rs b/crates/panorama-core/build.rs index 48ee2e3..c40aa8f 100644 --- a/crates/panorama-core/build.rs +++ b/crates/panorama-core/build.rs @@ -1,3 +1,4 @@ fn main() { + println!("cargo:rerun-if-changed=../../apps"); println!("cargo:rerun-if-changed=migrations"); } diff --git a/crates/panorama-core/src/state/apps.rs b/crates/panorama-core/src/state/apps.rs index ddf4238..3b710e5 100644 --- a/crates/panorama-core/src/state/apps.rs +++ b/crates/panorama-core/src/state/apps.rs @@ -1,9 +1,16 @@ use std::{ - fs, + fs::{self, File}, + io::Read, path::{Path, PathBuf}, + sync::Arc, }; use miette::{IntoDiagnostic, Result}; +use rune::{ + prepare, + termcolor::{ColorChoice, StandardStream}, + Context, Diagnostics, Hash, Module, Source, Sources, Vm, +}; use crate::AppState; @@ -29,7 +36,7 @@ impl AppState { } for path in found { - self.install_app_from_path(path).await?; + self.install_app_from_path(path).await; } Ok(()) @@ -38,8 +45,48 @@ impl AppState { async fn install_app_from_path(&self, path: impl AsRef) -> Result<()> { let app_path = path.as_ref(); let manifest_path = app_path.join("manifest.yml"); + let register_path = app_path.join("register.rn"); - // Install tables + let register_script = { + let mut file = File::open(register_path).into_diagnostic()?; + let mut string = String::new(); + file.read_to_string(&mut string).into_diagnostic()?; + string + }; + + let mut sources = Sources::new(); + sources + .insert(Source::new("register.rn", register_script).into_diagnostic()?) + .into_diagnostic()?; + + let mut diagnostics = Diagnostics::new(); + let register_script_unit = prepare(&mut sources) + .with_diagnostics(&mut diagnostics) + .build(); + if !diagnostics.is_empty() { + let mut writer = StandardStream::stderr(ColorChoice::Always); + diagnostics.emit(&mut writer, &sources).into_diagnostic()?; + } + let register_script_unit = + Arc::new(register_script_unit.into_diagnostic()?); + + let module = Module::new(); + // let mut ctx = Context::new(); + let mut ctx = Context::with_default_modules().into_diagnostic()?; + ctx.install(module).into_diagnostic()?; + + let rt_ctx = ctx.runtime().into_diagnostic()?; + let ctx_arc = Arc::new(rt_ctx); + let mut vm = Vm::new(ctx_arc, register_script_unit); + + let main = Hash::type_hash(["main"]); + let result = vm + .execute(main, ()) + .into_diagnostic()? + .complete() + .into_result() + .into_diagnostic()?; + println!("Executed. {result:?}"); Ok(()) } diff --git a/crates/panorama-core/src/state/journal.rs b/crates/panorama-core/src/state/journal.rs index eed3447..4ebddd5 100644 --- a/crates/panorama-core/src/state/journal.rs +++ b/crates/panorama-core/src/state/journal.rs @@ -42,29 +42,6 @@ impl AppState { ) .await?; - // self.db.run_script( - // " - // { - // ?[id, type] <- [[$node_id, 'panorama/journal/page']] - // :put node { id, type } - // } - // { - // ?[node_id, title, content] <- [[$node_id, $title, '']] - // :put journal { node_id => title, content } - // } - // { - // ?[day, node_id] <- [[$day, $node_id]] - // :put journal_day { day => node_id } - // } - // ", - // btmap! { - // "node_id".to_owned() => node_id.clone().into(), - // "day".to_owned() => today.clone().into(), - // "title".to_owned() => today.clone().into(), - // }, - // ScriptMutability::Mutable, - // )?; - return Ok(node_info.node_id); } diff --git a/crates/panorama-daemon/src/lib.rs b/crates/panorama-daemon/src/lib.rs index 4df6f09..29aa689 100644 --- a/crates/panorama-daemon/src/lib.rs +++ b/crates/panorama-daemon/src/lib.rs @@ -43,6 +43,8 @@ pub async fn run() -> Result<()> { let state = AppState::new(&panorama_dir).await?; + state.install_apps_from_search_paths().await?; + let cors_layer = CorsLayer::new() .allow_methods([Method::GET, Method::POST, Method::PUT]) .allow_headers(cors::Any)