Skip to content
This repository was archived by the owner on Aug 3, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/commands/kv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ mod tests {
build: None,
wasm_modules: None,
usage_model: None,
compatibility_date: None,
compatibility_flags: Vec::new(),
};
assert!(kv::get_namespace_id(&target_with_dup_kv_bindings, "").is_err());
}
Expand Down
5 changes: 5 additions & 0 deletions src/settings/toml/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ pub struct Manifest {
pub durable_objects: Option<DurableObjects>,
#[serde(default, with = "string_empty_as_none")]
pub usage_model: Option<UsageModel>,
pub compatibility_date: Option<String>,
#[serde(default)]
pub compatibility_flags: Vec<String>,
}

impl Manifest {
Expand Down Expand Up @@ -352,6 +355,8 @@ impl Manifest {
text_blobs: self.text_blobs.clone(), // Inherited
usage_model: self.usage_model, // Top level
wasm_modules: self.wasm_modules.clone(),
compatibility_date: self.compatibility_date.clone(),
compatibility_flags: self.compatibility_flags.clone(),
};

let environment = self.get_environment(environment_name)?;
Expand Down
2 changes: 2 additions & 0 deletions src/settings/toml/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ pub struct Target {
pub text_blobs: Option<HashMap<String, PathBuf>>,
pub usage_model: Option<UsageModel>,
pub wasm_modules: Option<HashMap<String, PathBuf>>,
pub compatibility_date: Option<String>,
pub compatibility_flags: Vec<String>,
}

impl Target {
Expand Down
2 changes: 2 additions & 0 deletions src/sites/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ mod tests {
text_blobs: None,
usage_model: None,
wasm_modules: None,
compatibility_date: None,
compatibility_flags: Vec::new(),
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/upload/form/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub fn build(
session_config: Option<serde_json::Value>,
) -> Result<Form> {
let target_type = &target.target_type;
let compatibility_date = target.compatibility_date.clone();
let compatibility_flags = target.compatibility_flags.clone();
let kv_namespaces = &target.kv_namespaces;
let durable_object_classes = target
.durable_objects
Expand Down Expand Up @@ -85,6 +87,8 @@ pub fn build(

let assets = ServiceWorkerAssets::new(
script_path,
compatibility_date,
compatibility_flags,
wasm_modules,
kv_namespaces.to_vec(),
durable_object_classes,
Expand All @@ -105,6 +109,8 @@ pub fn build(

let assets = ServiceWorkerAssets::new(
script_path,
compatibility_date,
compatibility_flags,
wasm_modules,
kv_namespaces.to_vec(),
durable_object_classes,
Expand All @@ -123,6 +129,8 @@ pub fn build(

let module_config = ModuleConfig::new(main, dir, rules);
let assets = ModulesAssets::new(
compatibility_date,
compatibility_flags,
module_config.get_modules()?,
kv_namespaces.to_vec(),
durable_object_classes,
Expand All @@ -142,6 +150,8 @@ pub fn build(

let assets = ServiceWorkerAssets::new(
script_path,
compatibility_date,
compatibility_flags,
wasm_modules,
kv_namespaces.to_vec(),
durable_object_classes,
Expand Down Expand Up @@ -170,6 +180,8 @@ pub fn build(

let assets = ServiceWorkerAssets::new(
script_path,
compatibility_date,
compatibility_flags,
wasm_modules,
kv_namespaces.to_vec(),
durable_object_classes,
Expand Down
6 changes: 6 additions & 0 deletions src/upload/form/modules_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ struct Metadata {
pub bindings: Vec<Binding>,
pub migrations: Option<ApiMigration>,
pub usage_model: Option<UsageModel>,
#[serde(skip_serializing_if = "Option::is_none")]
pub compatibility_date: Option<String>,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub compatibility_flags: Vec<String>,
}

pub fn build_form(
Expand Down Expand Up @@ -53,6 +57,8 @@ fn add_metadata(mut form: Form, assets: &ModulesAssets) -> Result<Form> {
bindings: assets.bindings(),
migrations: assets.migration.clone(),
usage_model: assets.usage_model,
compatibility_date: assets.compatibility_date.clone(),
compatibility_flags: assets.compatibility_flags.clone(),
Comment on lines +60 to +61

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to your change, but it bugs me that there are so many spurious clones here, Metadata could hold references instead of owned values. build_form should take an owned value too since it's always used with &owned_assets and clones the fields.

});

let metadata = Part::text(metadata_json.to_string())
Expand Down
14 changes: 14 additions & 0 deletions src/upload/form/project_assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ use std::collections::{HashMap, HashSet};
pub struct ServiceWorkerAssets {
script_name: String,
script_path: PathBuf,
pub compatibility_date: Option<String>,
pub compatibility_flags: Vec<String>,
pub wasm_modules: Vec<WasmModule>,
pub kv_namespaces: Vec<KvNamespace>,
pub durable_object_classes: Vec<DurableObjectsClass>,
Expand All @@ -31,8 +33,11 @@ pub struct ServiceWorkerAssets {
}

impl ServiceWorkerAssets {
#[allow(clippy::too_many_arguments)] // TODO: refactor?
pub fn new(
script_path: PathBuf,
compatibility_date: Option<String>,
compatibility_flags: Vec<String>,
wasm_modules: Vec<WasmModule>,
kv_namespaces: Vec<KvNamespace>,
durable_object_classes: Vec<DurableObjectsClass>,
Expand All @@ -46,6 +51,8 @@ impl ServiceWorkerAssets {
Ok(Self {
script_name,
script_path,
compatibility_date,
compatibility_flags,
wasm_modules,
kv_namespaces,
durable_object_classes,
Expand Down Expand Up @@ -330,6 +337,8 @@ fn build_type_matchers(rules: Vec<ModuleRule>) -> Result<Vec<ModuleMatcher>> {
}

pub struct ModulesAssets {
pub compatibility_date: Option<String>,
pub compatibility_flags: Vec<String>,
pub manifest: ModuleManifest,
pub kv_namespaces: Vec<KvNamespace>,
pub durable_object_classes: Vec<DurableObjectsClass>,
Expand All @@ -339,7 +348,10 @@ pub struct ModulesAssets {
}

impl ModulesAssets {
#[allow(clippy::too_many_arguments)] // TODO: refactor?
pub fn new(
compatibility_date: Option<String>,
compatibility_flags: Vec<String>,
manifest: ModuleManifest,
kv_namespaces: Vec<KvNamespace>,
durable_object_classes: Vec<DurableObjectsClass>,
Expand All @@ -348,6 +360,8 @@ impl ModulesAssets {
usage_model: Option<UsageModel>,
) -> Result<Self> {
Ok(Self {
compatibility_date,
compatibility_flags,
manifest,
kv_namespaces,
durable_object_classes,
Expand Down
6 changes: 6 additions & 0 deletions src/upload/form/service_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ struct Metadata {
pub body_part: String,
pub bindings: Vec<Binding>,
pub usage_model: Option<UsageModel>,
#[serde(skip_serializing_if = "Option::is_none")]
pub compatibility_date: Option<String>,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub compatibility_flags: Vec<String>,
}

pub fn build_form(
Expand Down Expand Up @@ -56,6 +60,8 @@ fn add_metadata(mut form: Form, assets: &ServiceWorkerAssets) -> Result<Form> {
body_part: assets.script_name(),
bindings: assets.bindings(),
usage_model: assets.usage_model,
compatibility_date: assets.compatibility_date.clone(),
compatibility_flags: assets.compatibility_flags.clone(),
});

let metadata = Part::text(metadata_json.to_string())
Expand Down