pub mod state {
use crate::assets::storage::types::state::{AssetsStable, ContentChunksStable};
use crate::db::types::state::{DbHeapState, DbRuntimeState, DbStable};
use crate::memory::internal::init_stable_state;
use candid::CandidType;
use junobuild_auth::state::types::state::AuthenticationHeapState;
use junobuild_cdn::proposals::ProposalsStable;
use junobuild_cdn::storage::{ProposalAssetsStable, ProposalContentChunksStable};
use junobuild_shared::types::state::AccessKeys;
use junobuild_storage::types::state::StorageHeapState;
use rand::rngs::StdRng;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
pub struct State {
#[serde(skip, default = "init_stable_state")]
pub stable: StableState,
pub heap: HeapState,
#[serde(skip, default)]
pub runtime: RuntimeState,
}
pub struct StableState {
pub db: DbStable,
pub assets: AssetsStable,
pub content_chunks: ContentChunksStable,
pub proposals_assets: ProposalAssetsStable,
pub proposals_content_chunks: ProposalContentChunksStable,
pub proposals: ProposalsStable,
}
#[derive(Default, CandidType, Serialize, Deserialize, Clone)]
pub struct HeapState {
pub controllers: AccessKeys,
pub db: DbHeapState,
pub storage: StorageHeapState,
pub authentication: Option<AuthenticationHeapState>,
}
#[derive(Default, Clone)]
pub struct RuntimeState {
pub rng: Option<StdRng>, pub db: DbRuntimeState,
}
#[derive(CandidType, Deserialize, Serialize, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum CollectionType {
Db,
Storage,
}
}
pub mod interface {
use crate::automation::types::AuthenticationAutomationError;
use crate::db::types::config::DbConfig;
use crate::Doc;
use candid::CandidType;
use junobuild_auth::automation::types::PreparedAutomation;
use junobuild_auth::delegation::types::{
GetDelegationError, OpenIdGetDelegationArgs, OpenIdPrepareDelegationArgs,
PrepareDelegationError, PreparedDelegation, SignedDelegation,
};
use junobuild_auth::state::types::automation::AutomationConfig;
use junobuild_auth::state::types::config::AuthenticationConfig;
use junobuild_cdn::proposals::ProposalId;
use junobuild_storage::types::config::StorageConfig;
use junobuild_storage::types::interface::{CertifyAssetsCursor, CertifyAssetsStrategy};
use serde::{Deserialize, Serialize};
#[derive(CandidType, Deserialize)]
pub struct Config {
pub storage: StorageConfig,
pub db: Option<DbConfig>,
pub authentication: Option<AuthenticationConfig>,
pub automation: Option<AutomationConfig>,
}
#[derive(CandidType, Serialize, Deserialize, Clone)]
pub struct DeleteProposalAssets {
pub proposal_ids: Vec<ProposalId>,
}
#[derive(CandidType, Serialize, Deserialize)]
pub enum AuthenticationArgs {
OpenId(OpenIdPrepareDelegationArgs),
}
pub type AuthenticationResult = Result<Authentication, AuthenticationError>;
#[derive(CandidType, Serialize, Deserialize)]
pub struct Authentication {
pub delegation: PreparedDelegation,
pub doc: Doc,
}
#[derive(CandidType, Serialize, Deserialize)]
pub enum AuthenticationError {
PrepareDelegation(PrepareDelegationError),
RegisterUser(String),
}
#[derive(CandidType, Serialize, Deserialize)]
pub enum GetDelegationArgs {
OpenId(OpenIdGetDelegationArgs),
}
#[derive(CandidType, Serialize, Deserialize)]
pub enum AuthenticateResultResponse {
Ok(Authentication),
Err(AuthenticationError),
}
#[derive(CandidType, Serialize, Deserialize)]
pub enum GetDelegationResultResponse {
Ok(SignedDelegation),
Err(GetDelegationError),
}
#[derive(CandidType, Serialize, Deserialize)]
pub enum AuthenticateAutomationResultResponse {
Ok(PreparedAutomation),
Err(AuthenticationAutomationError),
}
#[derive(CandidType, Serialize, Deserialize)]
pub struct CertifyAssetsArgs {
pub cursor: CertifyAssetsCursor,
pub chunk_size: Option<u32>,
pub strategy: CertifyAssetsStrategy,
}
#[derive(CandidType, Serialize, Deserialize)]
pub struct CertifyAssetsResult {
pub next_cursor: Option<CertifyAssetsCursor>,
}
}
pub mod store {
use junobuild_auth::state::types::config::AuthenticationConfig;
use junobuild_collections::types::core::CollectionKey;
use junobuild_collections::types::rules::Rule;
use junobuild_shared::types::state::{AccessKeys, UserId};
pub struct StoreContext<'a> {
pub caller: UserId,
pub controllers: &'a AccessKeys,
pub collection: &'a CollectionKey,
}
pub struct AssertContext<'a> {
pub rule: &'a Rule,
pub auth_config: &'a Option<AuthenticationConfig>,
}
}
pub mod hooks {
use crate::db::types::state::{DocAssertDelete, DocAssertSet, DocContext, DocUpsert};
use crate::Doc;
use candid::{CandidType, Deserialize};
use junobuild_shared::types::state::UserId;
use junobuild_storage::types::store::{Asset, AssetAssertUpload};
#[derive(CandidType, Deserialize, Clone)]
pub struct HookContext<T> {
pub caller: UserId,
pub data: T,
}
pub type OnSetDocContext = HookContext<DocContext<DocUpsert>>;
pub type OnSetManyDocsContext = HookContext<Vec<DocContext<DocUpsert>>>;
pub type OnDeleteDocContext = HookContext<DocContext<Option<Doc>>>;
pub type OnDeleteManyDocsContext = HookContext<Vec<DocContext<Option<Doc>>>>;
pub type OnDeleteFilteredDocsContext = HookContext<Vec<DocContext<Option<Doc>>>>;
pub type OnUploadAssetContext = HookContext<Asset>;
pub type OnDeleteAssetContext = HookContext<Option<Asset>>;
pub type OnDeleteManyAssetsContext = HookContext<Vec<Option<Asset>>>;
pub type OnDeleteFilteredAssetsContext = HookContext<Vec<Option<Asset>>>;
pub type AssertSetDocContext = HookContext<DocContext<DocAssertSet>>;
pub type AssertDeleteDocContext = HookContext<DocContext<DocAssertDelete>>;
pub type AssertUploadAssetContext = HookContext<AssetAssertUpload>;
pub type AssertDeleteAssetContext = HookContext<Asset>;
}