1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
mod builder;
mod dev;
mod durable_objects;
mod environment;
mod kv_namespace;
mod manifest;
pub mod migrations;
mod r2_bucket;
mod route;
mod site;
pub(crate) mod target;
mod target_type;
mod triggers;

pub use builder::{ModuleRule, UploadFormat};
pub use durable_objects::{DurableObjects, DurableObjectsClass};
pub use kv_namespace::{ConfigKvNamespace, KvNamespace};
pub use manifest::Manifest;
pub use r2_bucket::{ConfigR2Bucket, R2Bucket};
pub use route::{Route, RouteConfig};
pub use site::Site;
pub use target::Target;
pub use target_type::TargetType;

use anyhow::anyhow;
use serde::{Deserialize, Serialize};
use std::str::FromStr;

#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum UsageModel {
    Bundled,
    Unbound,
}

impl FromStr for UsageModel {
    type Err = anyhow::Error;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "bundled" => Ok(UsageModel::Bundled),
            "unbound" => Ok(UsageModel::Unbound),
            _ => Err(anyhow!(
                "Invalid usage model; must be either \"bundled\" or \"unbound\""
            )),
        }
    }
}

impl AsRef<str> for UsageModel {
    fn as_ref(&self) -> &str {
        match self {
            UsageModel::Bundled => "bundled",
            UsageModel::Unbound => "unbound",
        }
    }
}

#[cfg(test)]
mod tests;