Skip to content
Open
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
27 changes: 27 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ arrayvec = "0.7.2"
async-channel = "2.5"
async-stream = "0.3.6"
async-trait = "0.1.68"
axum = { version = "0.7", features = ["tracing", "http2"] }
axum = { version = "0.7", features = ["tracing", "http2", "macros"] }
axum-extra = { version = "0.9", features = ["typed-header"] }
base64 = "0.21.2"
bigdecimal = "0.4.7"
Expand Down Expand Up @@ -307,6 +307,7 @@ serde_json = { version = "1.0.128", features = ["raw_value"] }
serde_path_to_error = "0.1.9"
serde_with = { version = "3.3.0", features = ["base64", "hex"] }
serial_test = "2.0.0"
sfv = "0.15"
sha3 = "0.10.0"
slab = "0.4.7"
sled = "0.34.7"
Expand Down
12 changes: 7 additions & 5 deletions crates/bindings-macro/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,21 @@ pub(crate) fn expand(args: TokenStream, mut item: ItemStruct) -> syn::Result<Tok
let constraint = match values.as_deref() {
None => quote!(<#ty as ::spacetimedb::rt::EnvironmentValue>::constraint()),
Some([value]) => {
quote!(::spacetimedb::spacetimedb_lib::environment::EnvVarType::StringLiteral(#value.into()))
quote!(::spacetimedb::spacetimedb_lib::db::raw_def::v10::RawEnvVarTypeV10::StringLiteral(#value.into()))
}
Some(values) => quote!(::spacetimedb::spacetimedb_lib::environment::EnvVarType::Union(
::std::vec![#(#values.into()),*]
)),
Some(values) => quote!(
::spacetimedb::spacetimedb_lib::db::raw_def::v10::RawEnvVarTypeV10::Union(
::std::vec![#(#values.into()),*]
)
),
};
let constraint = if values.is_some() {
quote!(<#ty as ::spacetimedb::rt::StringEnvironmentValue>::with_constraint(#constraint))
} else {
constraint
};
declarations.push(
quote!(::spacetimedb::spacetimedb_lib::environment::EnvironmentDeclaration {
quote!(::spacetimedb::spacetimedb_lib::db::raw_def::v10::RawEnvironmentDeclarationV10 {
name: #name.into(),
ty: #constraint,
optional: <#ty as ::spacetimedb::rt::EnvironmentValue>::OPTIONAL,
Expand Down
12 changes: 7 additions & 5 deletions crates/bindings-macro/src/environment/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,19 @@ pub(crate) fn derive(item: DeriveInput) -> syn::Result<TokenStream> {
values.push(value);
}
let constraint = match values.as_slice() {
[value] => quote!(::spacetimedb::spacetimedb_lib::environment::EnvVarType::StringLiteral(#value.into())),
values => quote!(::spacetimedb::spacetimedb_lib::environment::EnvVarType::Union(
::std::vec![#(#values.into()),*]
)),
[value] => {
quote!(::spacetimedb::spacetimedb_lib::db::raw_def::v10::RawEnvVarTypeV10::StringLiteral(#value.into()))
}
values => quote!(
::spacetimedb::spacetimedb_lib::db::raw_def::v10::RawEnvVarTypeV10::Union(::std::vec![#(#values.into()),*])
),
};
let ident = &item.ident;
Ok(quote! {
impl ::spacetimedb::rt::EnvironmentValue for #ident {
const OPTIONAL: bool = false;

fn constraint() -> ::spacetimedb::spacetimedb_lib::environment::EnvVarType {
fn constraint() -> ::spacetimedb::spacetimedb_lib::db::raw_def::v10::RawEnvVarTypeV10 {
#constraint
}

Expand Down
13 changes: 6 additions & 7 deletions crates/bindings/src/rt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::table::IndexAlgo;
use crate::{sys, AnonymousViewContext, IterBuf, ReducerContext, ReducerResult, SpacetimeType, Table, ViewContext};
use spacetimedb_lib::bsatn::EncodeError;
use spacetimedb_lib::db::raw_def::v10::{
CaseConversionPolicy, ExplicitNames as RawExplicitNames, RawModuleDefV10Builder,
CaseConversionPolicy, ExplicitNames as RawExplicitNames, RawEnvironmentDeclarationV10, RawModuleDefV10Builder,
};
pub use spacetimedb_lib::db::raw_def::v9::Lifecycle as LifecycleReducer;
use spacetimedb_lib::db::raw_def::v9::{RawIndexAlgorithm, TableType, ViewResultHeader};
Expand Down Expand Up @@ -929,7 +929,7 @@ pub fn register_case_conversion_policy(policy: CaseConversionPolicy) {
pub trait EnvironmentValue: Sized {
const OPTIONAL: bool;

fn constraint() -> spacetimedb_lib::environment::EnvVarType;
fn constraint() -> spacetimedb_lib::db::raw_def::v10::RawEnvVarTypeV10;

/// Decode a checked host result. Errors must identify only the key, never its value.
fn from_environment(value: Option<String>, key: &str) -> Self;
Expand All @@ -947,8 +947,8 @@ pub trait RequiredEnvironmentValue: EnvironmentValue {}
impl EnvironmentValue for String {
const OPTIONAL: bool = false;

fn constraint() -> spacetimedb_lib::environment::EnvVarType {
spacetimedb_lib::environment::EnvVarType::String
fn constraint() -> spacetimedb_lib::db::raw_def::v10::RawEnvVarTypeV10 {
spacetimedb_lib::db::raw_def::v10::RawEnvVarTypeV10::String
}

fn from_environment(value: Option<String>, key: &str) -> Self {
Expand All @@ -961,7 +961,7 @@ impl RequiredEnvironmentValue for String {}
impl<T: RequiredEnvironmentValue> EnvironmentValue for Option<T> {
const OPTIONAL: bool = true;

fn constraint() -> spacetimedb_lib::environment::EnvVarType {
fn constraint() -> spacetimedb_lib::db::raw_def::v10::RawEnvVarTypeV10 {
T::constraint()
}

Expand Down Expand Up @@ -995,7 +995,7 @@ impl StringEnvironmentValue for Option<String> {}

/// Register declarative ENV metadata without reading any environment values.
#[doc(hidden)]
pub fn register_environment(declarations: fn() -> Vec<spacetimedb_lib::environment::EnvironmentDeclaration>) {
pub fn register_environment(declarations: fn() -> Vec<RawEnvironmentDeclarationV10>) {
register_describer(move |module| {
module.inner.add_environment(declarations());
});
Expand Down Expand Up @@ -1067,7 +1067,6 @@ extern "C" fn __describe_module__(description: BytesSink) {
}

// Serialize the module to bsatn.
module.inner.ensure_environment();
let module_def = module.inner.finish();
let module_def = RawModuleDef::V10(module_def);
let bytes = bsatn::to_vec(&module_def).expect("unable to serialize typespace");
Expand Down
14 changes: 8 additions & 6 deletions crates/bindings/tests/environment_enum_values.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use spacetimedb::rt::EnvironmentValue as _;
use spacetimedb::spacetimedb_lib::environment::{EnvVarType, EnvironmentDeclaration, EnvironmentSchema};
use spacetimedb::spacetimedb_lib::environment::EnvironmentSchema;
use spacetimedb_lib::db::raw_def::v10::{RawEnvVarTypeV10, RawEnvironmentDeclarationV10};
use std::collections::BTreeMap;

#[derive(Debug, PartialEq, Eq, spacetimedb::SpacetimeType, spacetimedb::EnvironmentValue)]
Expand Down Expand Up @@ -29,14 +30,15 @@ fn typed_mappings_match_exact_schema_strings_and_optional_absence() {
];
assert_eq!(
Mode::constraint(),
EnvVarType::Union(cases.iter().map(|(s, _)| s.to_string()).collect())
RawEnvVarTypeV10::Union(cases.iter().map(|(s, _)| s.to_string()).collect())
);
assert_eq!(Option::<Mode>::constraint(), Mode::constraint());
let schema = EnvironmentSchema::new(vec![EnvironmentDeclaration {
let schema = EnvironmentSchema::new(vec![RawEnvironmentDeclarationV10 {
name: "MODE".into(),
ty: Mode::constraint(),
ty: Mode::constraint().into(),
optional: false,
}])
}
.into()])
.unwrap();
for (value, variant) in cases {
schema
Expand All @@ -49,7 +51,7 @@ fn typed_mappings_match_exact_schema_strings_and_optional_absence() {
);
}
assert_eq!(Option::<Mode>::from_environment(None, "MODE"), None);
assert_eq!(Literal::constraint(), EnvVarType::StringLiteral("only".into()));
assert_eq!(Literal::constraint(), RawEnvVarTypeV10::StringLiteral("only".into()));
assert_eq!(Literal::from_environment(Some("only".into()), "VALUE"), Literal::Only);
for rejected in ["InProgress", "ready", "in progress ", "private-unmapped-value"] {
assert!(schema
Expand Down
1 change: 1 addition & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ dirs.workspace = true
duct.workspace = true
futures.workspace = true
fs-err.workspace = true
headers.workspace = true
http.workspace = true
is-terminal.workspace = true
itertools.workspace = true
Expand Down
11 changes: 1 addition & 10 deletions crates/cli/src/schema_extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,7 @@ fn inspect_blocking(extractor: PathBuf, bytes: Vec<u8>, host_type: String) -> an
}

pub(crate) fn read_program(path: &std::path::Path) -> anyhow::Result<Vec<u8>> {
use std::io::Read;
let mut bytes = Vec::new();
std::fs::File::open(path)?
.take(spacetimedb_client_api_messages::publish::MAX_MODULE_BYTES as u64 + 1)
.read_to_end(&mut bytes)?;
ensure!(
bytes.len() <= spacetimedb_client_api_messages::publish::MAX_MODULE_BYTES,
"Module exceeds publish size limit"
);
Ok(bytes)
Ok(std::fs::read(path)?)
}

const MAX_SCHEMA_BYTES: u64 = 16 * 1024 * 1024;
Expand Down
8 changes: 6 additions & 2 deletions crates/cli/src/schema_extract/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ fn inspector(script: &str) -> (tempfile::TempDir, PathBuf) {
async fn local_inspection_passes_exact_bytes_host_and_requires_success() {
use spacetimedb_lib::db::raw_def::v10::{RawModuleDefV10, RawModuleDefV10Section};
let raw = RawModuleDef::V10(RawModuleDefV10 {
sections: vec![RawModuleDefV10Section::Environment(schema().into_declarations())],
sections: vec![RawModuleDefV10Section::Environment(
schema().into_declarations().into_iter().map(Into::into).collect(),
)],
});
let json = serde_json::to_string(&SerdeWrapper(raw)).unwrap();
let (dir, extractor) = inspector(&format!(
Expand Down Expand Up @@ -118,7 +120,9 @@ async fn local_inspection_passes_exact_bytes_host_and_requires_success() {
async fn synchronous_generate_adapter_uses_same_exact_byte_protocol_inside_a_runtime() {
use spacetimedb_lib::db::raw_def::v10::{RawModuleDefV10, RawModuleDefV10Section};
let raw = RawModuleDef::V10(RawModuleDefV10 {
sections: vec![RawModuleDefV10Section::Environment(schema().into_declarations())],
sections: vec![RawModuleDefV10Section::Environment(
schema().into_declarations().into_iter().map(Into::into).collect(),
)],
});
let json = serde_json::to_string(&SerdeWrapper(raw)).unwrap();
let (_dir, extractor) = inspector(&format!(
Expand Down
Loading
Loading