Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions crates/cli/src/subcommands/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,19 @@ pub fn cli() -> clap::Command {
.short('b')
.conflicts_with("project_path")
.conflicts_with("build_options")
.conflicts_with("js_file")
.help("The system path (absolute or relative) to the compiled wasm binary we should publish, instead of building the project."),
)
.arg(
Arg::new("js_file")
.value_parser(clap::value_parser!(PathBuf))
.long("js-path")
.short('j')
.conflicts_with("project_path")
.conflicts_with("build_options")
.conflicts_with("wasm_file")
.help("UNSTABLE: The system path (absolute or relative) to the javascript file we should publish, instead of building the project."),
)
.arg(
Arg::new("num_replicas")
.value_parser(clap::value_parser!(u8))
Expand Down Expand Up @@ -90,6 +101,7 @@ pub async fn exec(mut config: Config, args: &ArgMatches) -> Result<(), anyhow::E
let force = args.get_flag("force");
let anon_identity = args.get_flag("anon_identity");
let wasm_file = args.get_one::<PathBuf>("wasm_file");
let js_file = args.get_one::<PathBuf>("js_file");
let database_host = config.get_host_url(server)?;
let build_options = args.get_one::<String>("build_options").unwrap();
let num_replicas = args.get_one::<u8>("num_replicas");
Expand All @@ -108,13 +120,19 @@ pub async fn exec(mut config: Config, args: &ArgMatches) -> Result<(), anyhow::E
));
}

let path_to_wasm = if let Some(path) = wasm_file {
println!("Skipping build. Instead we are publishing {}", path.display());
path.clone()
// Decide program file path and read program.
// Optionally build the program.
let (path_to_program, host_type) = if let Some(path) = wasm_file {
println!("(WASM) Skipping build. Instead we are publishing {}", path.display());
(path.clone(), "Wasm")
} else if let Some(path) = js_file {
println!("(JS) Skipping build. Instead we are publishing {}", path.display());
(path.clone(), "Js")
} else {
build::exec_with_argstring(config.clone(), path_to_project, build_options).await?
let path = build::exec_with_argstring(config.clone(), path_to_project, build_options).await?;
(path, "Wasm")
};
let program_bytes = fs::read(path_to_wasm)?;
let program_bytes = fs::read(path_to_program)?;

let server_address = {
let url = Url::parse(&database_host)?;
Expand Down Expand Up @@ -191,6 +209,9 @@ pub async fn exec(mut config: Config, args: &ArgMatches) -> Result<(), anyhow::E

builder = add_auth_header_opt(builder, &auth_header);

// Set the host type.
builder = builder.query(&[("host_type", host_type)]);

let res = builder.body(program_bytes).send().await?;
if res.status() == StatusCode::UNAUTHORIZED && !anon_identity {
// If we're not in the `anon_identity` case, then we have already forced the user to log in above (using `get_auth_header`), so this should be safe to unwrap.
Expand Down
3 changes: 3 additions & 0 deletions crates/client-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,6 @@ toml.workspace = true

[lints]
workspace = true

[features]
unstable = []
17 changes: 16 additions & 1 deletion crates/client-api/src/routes/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,8 @@ pub struct PublishDatabaseQueryParams {
token: Option<spacetimedb_lib::Hash>,
#[serde(default)]
policy: MigrationPolicy,
#[serde(default)]
host_type: HostType,
}

use spacetimedb_client_api_messages::http::SqlStmtResult;
Expand Down Expand Up @@ -537,10 +539,23 @@ pub async fn publish<S: NodeDelegate + ControlStateDelegate>(
num_replicas,
token,
policy,
host_type,
}): Query<PublishDatabaseQueryParams>,
Extension(auth): Extension<SpacetimeAuth>,
body: Bytes,
) -> axum::response::Result<axum::Json<PublishResult>> {
// Feature gate V8 modules.
// The host must've been compiled with the `unstable` feature.
// TODO(v8): ungate this when V8 is ready to ship.
#[cfg(not(feature = "unstable"))]
if host_type == HostType::Js {
return Err((
StatusCode::BAD_REQUEST,
"JS host type requires a host with unstable features",
)
.into());
}

// You should not be able to publish to a database that you do not own
// so, unless you are the owner, this will fail.

Expand Down Expand Up @@ -645,7 +660,7 @@ pub async fn publish<S: NodeDelegate + ControlStateDelegate>(
database_identity,
program_bytes: body.into(),
num_replicas,
host_type: HostType::Wasm,
host_type,
},
policy,
)
Expand Down
4 changes: 0 additions & 4 deletions crates/core/src/host/v8/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ impl ModuleRuntime for V8RuntimeInner {
mcc.program.hash,
);

if true {
return Err::<JsModule, _>(anyhow::anyhow!("v8_todo"));
}

// TODO(v8): determine min required ABI by module and check that it's supported?

// TODO(v8): validate function signatures like in WASM? Is that possible with V8?
Expand Down
5 changes: 4 additions & 1 deletion crates/core/src/messages/control_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,12 @@ pub struct NodeStatus {
/// SEE: <https://kubernetes.io/docs/reference/kubernetes-api/cluster-resources/node-v1/#NodeStatus>
pub state: String,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
#[derive(
Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Default, Serialize, Deserialize, serde::Deserialize,
)]
#[repr(i32)]
pub enum HostType {
#[default]
Wasm = 0,
Js = 1,
}
Expand Down
1 change: 1 addition & 0 deletions crates/standalone/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ required-features = [] # Features required to build this target (N/A for lib)
[features]
# Perfmaps for profiling modules
perfmap = ["spacetimedb-core/perfmap"]
unstable = ["spacetimedb-client-api/unstable"]

[dependencies]
spacetimedb-client-api-messages.workspace = true
Expand Down
1 change: 1 addition & 0 deletions docs/docs/cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ Run `spacetime help publish` for more detailed information.

Default value: `.`
* `-b`, `--bin-path <WASM_FILE>` — The system path (absolute or relative) to the compiled wasm binary we should publish, instead of building the project.
* `-j`, `--js-path <JS_FILE>` — UNSTABLE: The system path (absolute or relative) to the javascript file we should publish, instead of building the project.
* `--break-clients` — Allow breaking changes when publishing to an existing database identity. This will break existing clients.
* `--anonymous` — Perform this action with an anonymous identity
* `-s`, `--server <SERVER>` — The nickname, domain name or URL of the server to host the database.
Expand Down
Loading