Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
feat: add namespace_id
Browse files Browse the repository at this point in the history
  • Loading branch information
xtuc committed Jul 1, 2019
1 parent 175f1b3 commit 34a6b22
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/commands/build/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub mod wranglerjs;

use crate::settings::project::ProjectType;
use crate::settings::project::{Project, ProjectType};
use crate::{commands, install};
use binary_install::Cache;
use std::env;
Expand Down
7 changes: 5 additions & 2 deletions src/commands/build/wranglerjs/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ fn create_metadata(
bindings.push(metadata::Bindings {
binding_type: "kv_namespace".to_string(),
name: namespace.local_binding.clone(),
namespace_id: namespace.namespace_id.clone(),
part: None,
});
}
Expand All @@ -140,6 +141,7 @@ fn create_metadata(
bindings.push(metadata::Bindings {
binding_type: "wasm_module".to_string(),
name: bundle.get_wasm_binding(),
namespace_id: None,
part: Some(bundle.get_wasm_binding()),
})
}
Expand Down Expand Up @@ -240,7 +242,7 @@ mod tests {

assert_eq!(
contents,
r#"{"body_part":"script","bindings":[{"name":"wasmprogram","type":"wasm_module","part":"wasmprogram"}]}"#
r#"{"body_part":"script","bindings":[{"name":"wasmprogram","type":"wasm_module","part":"wasmprogram","namespace_id":null}]}"#
);

cleanup(out);
Expand All @@ -260,14 +262,15 @@ mod tests {
let kv_namespaces = vec![KvNamespace {
local_binding: "bindings".to_string(),
name: "name".to_string(),
namespace_id: None,
}];

bundle.write(&wranglerjs_output, kv_namespaces).unwrap();
assert!(Path::new(&bundle.metadata_path()).exists());
let contents =
fs::read_to_string(&bundle.metadata_path()).expect("could not read metadata");

assert_eq!(contents, r#"{"body_part":"script","bindings":[{"name":"bindings","type":"kv_namespace","part":null}]}"#);
assert_eq!(contents, r#"{"body_part":"script","bindings":[{"name":"bindings","type":"kv_namespace","part":null,"namespace_id":null}]}"#);

cleanup(out);
}
Expand Down
1 change: 1 addition & 0 deletions src/commands/build/wranglerjs/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub struct Bindings {
#[serde(rename = "type")]
pub binding_type: String,
pub part: Option<String>,
pub namespace_id: Option<String>,
}

#[derive(Serialize, Debug)]
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ fn main() -> Result<(), failure::Error> {
let project = settings::project::Project::new()?;

if matches.subcommand_matches("build").is_some() {
commands::build(&cache, &project.project_type)?;
commands::build(&cache, &project)?;
}

if let Some(matches) = matches.subcommand_matches("preview") {
Expand All @@ -215,7 +215,7 @@ fn main() -> Result<(), failure::Error> {
None => None,
};

commands::build(&cache, &project.project_type)?;
commands::build(&cache, &project)?;
commands::preview(method, body)?;
}
} else if matches.subcommand_matches("whoami").is_some() {
Expand All @@ -240,7 +240,7 @@ fn main() -> Result<(), failure::Error> {
1 => true,
_ => false,
};
commands::build(&cache, &project.project_type)?;
commands::build(&cache, &project)?;
commands::publish(&user, &project, release)?;
}

Expand Down
1 change: 1 addition & 0 deletions src/settings/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use serde::{Deserialize, Serialize};
pub struct KvNamespace {
pub local_binding: String,
pub name: String,
pub namespace_id: Option<String>,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
Expand Down

0 comments on commit 34a6b22

Please sign in to comment.