Skip to main content

junobuild_cdn/
strategies.rs

1use crate::proposals::{Proposal, ProposalsStable};
2use crate::storage::{ProposalAssetsStable, ProposalContentChunksStable};
3use junobuild_collections::types::core::CollectionKey;
4use junobuild_collections::types::rules::{Rule, Rules};
5use junobuild_shared::types::domain::CustomDomains;
6use junobuild_storage::types::config::StorageConfig;
7use junobuild_storage::types::state::FullPath;
8use junobuild_storage::types::store::{Asset, AssetEncoding};
9
10pub trait CdnHeapStrategy {
11    fn with_config<R>(&self, f: impl FnOnce(&StorageConfig) -> R) -> R;
12    fn with_config_mut<R>(&self, f: impl FnOnce(&mut StorageConfig) -> R) -> R;
13
14    fn with_rules<R>(&self, f: impl FnOnce(&Rules) -> R) -> R;
15
16    fn with_domains<R>(&self, f: impl FnOnce(&CustomDomains) -> R) -> R;
17    fn with_domains_mut<R>(&self, f: impl FnOnce(&mut CustomDomains) -> R) -> R;
18}
19
20pub trait CdnStableStrategy {
21    fn with_assets<R>(&self, f: impl FnOnce(&ProposalAssetsStable) -> R) -> R;
22    fn with_assets_mut<R>(&self, f: impl FnOnce(&mut ProposalAssetsStable) -> R) -> R;
23
24    fn with_content_chunks<R>(&self, f: impl FnOnce(&ProposalContentChunksStable) -> R) -> R;
25    fn with_content_chunks_mut<R>(
26        &self,
27        f: impl FnOnce(&mut ProposalContentChunksStable) -> R,
28    ) -> R;
29
30    fn with_proposals<R>(&self, f: impl FnOnce(&ProposalsStable) -> R) -> R;
31    fn with_proposals_mut<R>(&self, f: impl FnOnce(&mut ProposalsStable) -> R) -> R;
32}
33
34pub trait CdnWorkflowStrategy {
35    fn pre_commit_assets(&self, proposal: &Proposal) -> Result<(), String>;
36    fn post_commit_assets(&self, proposal: &Proposal) -> Result<(), String>;
37}
38
39pub trait CdnCommitAssetsStrategy {
40    fn insert_asset(
41        &self,
42        collection: &CollectionKey,
43        full_path: &FullPath,
44        asset: &Asset,
45        rule: &Rule,
46    );
47
48    fn insert_asset_encoding(
49        &self,
50        full_path: &FullPath,
51        encoding_type: &str,
52        encoding: &AssetEncoding,
53        asset: &mut Asset,
54        rule: &Rule,
55    );
56
57    fn delete_assets(&self, collection: &CollectionKey) -> Result<(), String>;
58}