This commit is contained in:
Michael Zhang 2024-06-23 22:26:54 -05:00
parent 08192e1687
commit 5ec49db2ce
23 changed files with 131 additions and 35 deletions

9
Cargo.lock generated
View file

@ -3478,9 +3478,15 @@ dependencies = [
name = "panorama-app-sdk"
version = "0.1.0"
dependencies = [
"chrono",
"panorama-app-sdk-macros",
"wee_alloc",
]
[[package]]
name = "panorama-app-sdk-macros"
version = "0.1.0"
[[package]]
name = "panorama-core"
version = "0.1.0"
@ -3514,11 +3520,13 @@ dependencies = [
"async-imap",
"axum",
"chrono",
"clap",
"csv",
"dirs 5.0.1",
"futures",
"itertools 0.13.0",
"panorama-core",
"schemars",
"serde",
"serde_json",
"sugars",
@ -3536,6 +3544,7 @@ dependencies = [
name = "panorama-journal"
version = "0.1.0"
dependencies = [
"chrono",
"panorama-app-sdk",
]

View file

@ -7,4 +7,5 @@ edition = "2021"
crate-type = ["cdylib", "rlib"]
[dependencies]
chrono = "0.4.38"
panorama-app-sdk = { path = "../../crates/panorama-app-sdk" }

View file

@ -1,4 +1,4 @@
name: journal
name: "@panorama/journal"
version: 0.1.0
panorama_version: 0.1.0
description: Note taking app
@ -6,9 +6,22 @@ description: Note taking app
# installer_path: ../../target/wasm32-unknown-unknown/wasm-release/panorama_journal.wasm
installer_path: ../../target/wasm32-unknown-unknown/wasm-debug/panorama_journal.wasm
node_types:
- name: page
- name: block
keys:
- name: page/content
type: text
- name: page/day
type: date
endpoints:
- url: /date/:date
method: GET
export_name: get_date_info
- url: /date/:date
method: GET
export_name: get_date_info
permissions:
- "@panorama/current_time"
triggers:

View file

@ -3,12 +3,7 @@
#[macro_use]
extern crate panorama_app_sdk;
use panorama_app_sdk::prelude::*;
panorama_app_sdk::init!();
#[no_mangle]
pub fn install() -> i32 {
println!("SHIET");
123
pub fn get_date_info() {
panorama_app_sdk::get_current_time();
}

View file

@ -0,0 +1,9 @@
[package]
name = "panorama-app-sdk-macros"
version = "0.1.0"
edition = "2021"
[lib]
proc-macro = true
[dependencies]

View file

@ -0,0 +1 @@

View file

@ -8,3 +8,5 @@ crate-type = ["rlib"]
[dependencies]
wee_alloc = "0.4.5"
panorama-app-sdk-macros = { path = "../panorama-app-sdk-macros" }
chrono = "0.4.38"

View file

@ -1,5 +1,7 @@
#![no_std]
use chrono::{DateTime, Utc};
pub extern crate wee_alloc;
#[macro_use]
@ -13,6 +15,10 @@ pub mod macros;
pub mod internal;
pub mod sys;
pub mod prelude {
// pub use crate::macros::println;
pub mod prelude {}
/// Returns the current time
pub fn get_current_time() -> DateTime<Utc> {
let result = unsafe { sys::_get_current_time() };
DateTime::from_timestamp_nanos(result)
}

View file

@ -11,4 +11,7 @@ extern "C" {
// callback: *mut RegisterCallback,
callback_data: *mut c_void,
);
/// Returns the current time in nanoseconds
pub fn _get_current_time() -> i64;
}

View file

@ -1,6 +1,7 @@
use std::io::{stdout, Write};
use anyhow::Result;
use chrono::{DateTime, Utc};
use wasmtime::{Caller, InstancePre, Linker, Memory};
pub struct WasmtimeModule {
@ -41,5 +42,10 @@ impl WasmtimeInstanceEnv {
println!("Called print: {}", s);
}
pub fn get_current_time(_: Caller<'_, Self>) -> i64 {
let now = Utc::now();
now.timestamp_nanos_opt().unwrap()
}
pub fn register_endpoint(mut caller: Caller<'_, Self>) {}
}

View file

@ -2,6 +2,7 @@ macro_rules! abi_funcs {
($macro_name:ident) => {
// TODO: Why is this "env"? How do i use another name
$macro_name! {
"env"::get_current_time,
"env"::print,
"env"::register_endpoint,
}

View file

@ -4,21 +4,21 @@ use schemars::JsonSchema;
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct AppManifest {
name: String,
version: Option<String>,
panorama_version: Option<String>,
description: Option<String>,
installer_path: PathBuf,
pub name: String,
pub version: Option<String>,
pub panorama_version: Option<String>,
pub description: Option<String>,
pub installer_path: PathBuf,
endpoints: Vec<AppManifestEndpoint>,
triggers: Vec<AppManifestTriggers>,
pub endpoints: Vec<AppManifestEndpoint>,
pub triggers: Vec<AppManifestTriggers>,
}
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct AppManifestEndpoint {
url: String,
method: String,
export_name: String,
pub url: String,
pub method: String,
pub export_name: String,
}
#[derive(Debug, Serialize, Deserialize, JsonSchema)]

View file

@ -49,6 +49,14 @@ pub struct AppState {
pub tantivy_field_map: BiMap<String, Field>,
pub app_wasm_modules: HashMap<String, Module>,
// TODO: Compile this into a more efficient thing than just iter
pub app_routes: HashMap<String, Vec<AppRoute>>,
}
#[derive(Clone)]
pub struct AppRoute {
route: String,
handler_name: String,
}
impl AppState {
@ -82,6 +90,8 @@ impl AppState {
db,
tantivy_index,
tantivy_field_map,
app_wasm_modules: Default::default(),
app_routes: Default::default(),
};
state.init().await?;
@ -105,4 +115,6 @@ impl AppState {
Ok(())
}
pub fn handle_app_route() {}
}

View file

@ -18,6 +18,8 @@ pub async fn test_state() -> Result<AppState> {
db,
tantivy_index,
tantivy_field_map,
app_routes: Default::default(),
app_wasm_modules: Default::default(),
};
Ok(state)

View file

@ -9,12 +9,14 @@ edition = "2021"
anyhow = "1.0.86"
axum = "0.7.5"
chrono = { version = "0.4.38", features = ["serde"] }
clap = { version = "4.5.7", features = ["derive"] }
# cozo = { version = "0.7.6", features = ["storage-rocksdb"] }
csv = "1.3.0"
dirs = "5.0.1"
futures = "0.3.30"
itertools = "0.13.0"
panorama-core = { path = "../panorama-core" }
schemars = "0.8.21"
serde = { version = "1.0.202", features = ["derive"] }
serde_json = "1.0.117"
sugars = "3.0.1"

View file

@ -0,0 +1,15 @@
use axum::{
routing::{method_routing, MethodFilter},
Router,
};
use panorama_core::AppState;
use utoipa::OpenApi;
#[derive(OpenApi)]
#[openapi(paths(), components(schemas()))]
pub(super) struct AppsApi;
pub(super) fn router() -> Router<AppState> {
Router::new()
// .route("/app/:id/*path", method_routing::any(handler))
}

View file

@ -1,7 +1,7 @@
use axum::{Router};
use axum::Router;
use utoipa::OpenApi;
use crate::{AppState};
use crate::AppState;
/// Node API
#[derive(OpenApi)]

View file

@ -7,6 +7,7 @@ extern crate serde_json;
#[macro_use]
extern crate sugars;
pub mod apps;
mod error;
mod journal;
pub mod mail;

View file

@ -1,5 +1,3 @@
// pub async fn get_mail_config(
// State(state): State<AppState>,
// ) -> AppResult<Json<Value>> {

View file

@ -1,10 +1,32 @@
use anyhow::Result;
use clap::{Parser, Subcommand};
use panorama_core::state::apps::manifest::AppManifest;
use schemars::schema_for;
#[derive(Debug, Parser)]
struct Opt {
#[clap(subcommand)]
command: Option<Command>,
}
#[derive(Debug, Subcommand)]
enum Command {
GenerateConfigSchema,
}
#[tokio::main]
async fn main() -> Result<()> {
let opt = Opt::parse();
tracing_subscriber::fmt::init();
panorama_daemon::run().await?;
match opt.command {
Some(Command::GenerateConfigSchema) => {
let schema = schema_for!(AppManifest);
println!("{}", serde_json::to_string_pretty(&schema).unwrap());
}
None => panorama_daemon::run().await?,
}
Ok(())
}

View file

@ -1,10 +1,7 @@
use axum::Router;
use utoipa::OpenApi;
use axum::{
Router,
};
use utoipa::{OpenApi};
use crate::{AppState};
use crate::AppState;
/// Node API
#[derive(OpenApi)]

1
docs/.gitignore vendored
View file

@ -1 +1,2 @@
book
src/generated

View file

@ -16,7 +16,7 @@ After this rolls out, most of the built-in panorama apps will also be converted
To develop a custom app, you will need to provide:
-
App metadata. This contains:
App metadata in a `manifest.yml`. This contains:
- App display name.
- Version + License.