pub mod apps;
pub mod auth;
pub mod cli;
pub mod config;
pub mod create_modals;
pub mod entities;
pub mod error;
pub mod export;
pub mod forms;
pub mod handlers;
pub mod jwt;
pub mod keys;
pub mod layers;
pub mod middleware;
pub mod migrations;
pub mod null_text;
pub mod password;
pub mod phone;
pub mod routes;
pub mod seed;
pub mod session;
pub mod state;
pub mod templates;
#[cfg(test)]
mod tests;
use frunk::{HCons, HNil, hlist::HList};
use crate::plugin_install::define_plugin_install;
use crate::{
app::{App, MountedApp},
capability::{CapStore, define_passthrough_cap},
config::{ConfigCap, ConfigTag},
db::{DbCap, DbTag},
hooks::{AttachState, RunSeed},
traits::{
add::{AddCapability, CapTagAbsent},
get::{GetByCapTag, GetByTag},
},
};
use config::{UsersConfig, UsersConfigTag};
use state::UsersState;
pub struct UsersTag;
define_passthrough_cap!(UsersStateCap, UsersTag, UsersState);
define_plugin_install! {
plugin: UsersTag;
steps: [
apps(apps::Hook),
export(export::ExportHook),
migrations(migrations::Hook),
templates(templates::Hook),
slots(templates::SlotsHook),
config(UsersConfigTag, UsersConfig),
http(routes::Hook),
state(StateHook),
seeds(SeedsHook),
commands(cli::Hook),
]
}
#[derive(Clone, Copy, Default)]
pub struct StateHook;
impl<L, DbIdx, CfgIdx, Configs, UsersCfgIdx, TagProof>
AttachState<L, (DbIdx, CfgIdx, Configs, UsersCfgIdx, TagProof)> for StateHook
where
L: GetByCapTag<DbTag, DbIdx, Value = DbCap>,
L: GetByCapTag<ConfigTag, CfgIdx, Value = ConfigCap<HNil, Configs>>,
Configs: GetByTag<UsersConfigTag, UsersCfgIdx, Value = UsersConfig>,
L: HList + CapTagAbsent<UsersTag, TagProof>,
{
type Output = HCons<UsersStateCap, L>;
fn attach_state(app: App<L>) -> App<Self::Output> {
let conn = app.get_capability::<DbTag, DbIdx>().items.conn.clone();
let config = <Configs as GetByTag<UsersConfigTag, UsersCfgIdx>>::get_by_tag(
&app.get_capability::<ConfigTag, CfgIdx>().items,
)
.clone();
app.add_capability(CapStore::with_items(UsersState::new(conn, config)))
}
}
#[derive(Clone, Copy, Default)]
pub struct SeedsHook;
#[async_trait::async_trait]
impl<M, UsersIdx> RunSeed<M, UsersIdx> for SeedsHook
where
M: GetByTag<UsersTag, UsersIdx, Value = UsersState> + Sync,
{
async fn run_seed(app: &MountedApp<M>) -> anyhow::Result<()> {
seed::seed(app.get_capability_output::<UsersTag, UsersIdx>()).await?;
Ok(())
}
}