Skip to content
Draft
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
20 changes: 13 additions & 7 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ derive_more = "0.99"
dialoguer = { version = "0.11", default-features = false }
dirs = "5.0.1"
duct = "0.13.5"
ecow = "0.2.6"
either = "1.9"
email_address = "0.2.4"
enum-as-inner = "0.6"
Expand Down Expand Up @@ -220,6 +219,7 @@ jsonwebtoken = { package = "spacetimedb-jsonwebtoken", version = "9.3.0" }
junction = "1"
jwks = { package = "spacetimedb-jwks", version = "0.1.3" }
lazy_static = "1.4.0"
lean_string = "0.5.1"
log = "0.4.17"
memchr = "2"
mimalloc = "0.1.39"
Expand Down
2 changes: 1 addition & 1 deletion crates/bench/benches/special.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ fn serialize_benchmarks<
});

let mut table_schema = TableSchema::from_product_type(T::product_type());
table_schema.table_name = TableName::new_from_str(name);
table_schema.table_name = TableName::for_test(name);
let mut table = spacetimedb_table::table::Table::new(
Arc::new(table_schema),
spacetimedb_table::indexes::SquashedOffset::COMMITTED_STATE,
Expand Down
2 changes: 1 addition & 1 deletion crates/bench/benches/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn create_table_footprint(db: &RelationalDB) -> Result<TableId, DBError> {
fn insert_op(table_id: TableId, table_name: &str, row: ProductValue) -> DatabaseTableUpdate {
DatabaseTableUpdate {
table_id,
table_name: TableName::new_from_str(table_name),
table_name: TableName::for_test(table_name),
inserts: [row].into(),
deletes: [].into(),
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bench/src/schemas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ pub fn table_name<T: BenchTable>(style: IndexStrategy) -> TableName {
let prefix = style.name();
let name = T::name();

TableName::new_from_str(&format!("{prefix}_{name}"))
TableName::for_test(&format!("{prefix}_{name}"))
}

// ---------- data synthesis ----------
Expand Down
2 changes: 1 addition & 1 deletion crates/bench/src/spacetime_raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl BenchDatabase for SpacetimeRaw {
let mut table_schema = TableSchema::from_product_type(T::product_type());
table_schema.table_name = name.clone();
let table_id = self.db.create_table(tx, table_schema)?;
self.db.rename_table(tx, table_id, &name)?;
self.db.rename_table(tx, table_id, name)?;
match index_strategy {
IndexStrategy::Unique0 => {
self.db.create_index(
Expand Down
2 changes: 1 addition & 1 deletion crates/bench/src/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl BenchDatabase for SQLite {
value: AlgebraicValue,
) -> ResultBench<()> {
let statement = memo_query(BenchName::Filter, table_id, || {
let column: Box<str> = T::product_type().elements[col_id.into().idx()].name.take().unwrap();
let column = T::product_type().elements[col_id.into().idx()].name.clone().unwrap();
format!("SELECT * FROM {table_id} WHERE {column} = ?")
});

Expand Down
2 changes: 1 addition & 1 deletion crates/bindings/src/rt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ pub fn register_table<T: Table>() {
for &col in T::UNIQUE_COLUMNS {
table = table.with_unique_constraint(col);
}
for &index in T::INDEXES {
for index in T::INDEXES {
table = table.with_index(index.algo.into(), index.accessor_name);
}
if let Some(primary_key) = T::PRIMARY_KEY {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: crates/bindings/tests/deps.rs
expression: "cargo tree -p spacetimedb -e no-dev --color never --target wasm32-unknown-unknown -f {lib}"
---
total crates: 70
total crates: 73
spacetimedb
├── anyhow
├── bytemuck
Expand Down Expand Up @@ -106,6 +106,11 @@ spacetimedb
│ │ │ └── serde_core
│ │ ├── hex
│ │ ├── itertools (*)
│ │ ├── lean_string
│ │ │ ├── castaway
│ │ │ │ └── rustversion
│ │ │ ├── itoa
│ │ │ └── ryu
│ │ ├── second_stack
│ │ ├── sha3
│ │ │ ├── digest
Expand Down
3 changes: 2 additions & 1 deletion crates/cli/src/subcommands/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::util::UNSTABLE_WARNING;
use anyhow::{bail, Context, Error};
use clap::{Arg, ArgMatches};
use convert_case::{Case, Casing};
use core::ops::Deref;
use itertools::Itertools;
use spacetimedb_lib::sats::{self, AlgebraicType, Typespace};
use spacetimedb_lib::{Identity, ProductTypeElement};
Expand Down Expand Up @@ -198,7 +199,7 @@ impl std::fmt::Display for CallSignature<'_> {
}
comma = true;
if let Some(name) = arg.name() {
write!(f, "{}: ", name.to_case(Case::Snake))?;
write!(f, "{}: ", name.deref().to_case(Case::Snake))?;
}
write_type::write_type(typespace, f, &arg.algebraic_type)?;
}
Expand Down
13 changes: 6 additions & 7 deletions crates/cli/src/subcommands/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,12 @@ fn build_table<E>(
rows: impl Iterator<Item = Result<ProductValue, E>>,
) -> Result<tabled::Table, E> {
let mut builder = tabled::builder::Builder::default();
builder.set_header(
schema
.elements
.iter()
.enumerate()
.map(|(i, e)| e.name.clone().unwrap_or_else(|| format!("column {i}").into())),
);
builder.set_header(schema.elements.iter().enumerate().map(|(i, e)| {
e.name
.as_ref()
.map(|n| n.to_string())
.unwrap_or_else(|| format!("column {i}"))
}));

let ty = Typespace::EMPTY.with_type(schema);
for row in rows {
Expand Down
17 changes: 9 additions & 8 deletions crates/client-api-messages/src/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use spacetimedb_primitives::TableId;
use spacetimedb_sats::{
de::{Deserialize, Error},
impl_deserialize, impl_serialize, impl_st,
raw_identifier::RawIdentifier,
ser::Serialize,
AlgebraicType, SpacetimeType,
};
Expand Down Expand Up @@ -151,7 +152,7 @@ impl<Args> ClientMessage<Args> {
#[sats(crate = spacetimedb_lib)]
pub struct CallReducer<Args> {
/// The name of the reducer to call.
pub reducer: Box<str>,
pub reducer: RawIdentifier,
/// The arguments to the reducer.
///
/// In the wire format, this will be a [`Bytes`], BSATN or JSON encoded according to the reducer's argument schema
Expand Down Expand Up @@ -312,7 +313,7 @@ pub struct OneOffQuery {
/// Parametric over the argument type to enable [`ClientMessage::map_args`].
pub struct CallProcedure<Args> {
/// The name of the procedure to call.
pub procedure: Box<str>,
pub procedure: RawIdentifier,
/// The arguments to the procedure.
///
/// In the wire format, this will be a [`Bytes`], BSATN or JSON encoded according to the reducer's argument schema
Expand Down Expand Up @@ -384,7 +385,7 @@ pub struct SubscribeRows<F: WebsocketFormat> {
/// The table ID of the query.
pub table_id: TableId,
/// The table name of the query.
pub table_name: Box<str>,
pub table_name: RawIdentifier,
/// The BSATN row values.
pub table_rows: TableUpdate<F>,
}
Expand Down Expand Up @@ -588,7 +589,7 @@ pub struct ReducerCallInfo<F: WebsocketFormat> {
/// We should consider not sending this at all and instead
/// having a startup message where the name <-> id bindings
/// are established between the host and the client.
pub reducer_name: Box<str>,
pub reducer_name: RawIdentifier,
/// The numerical id of the reducer that was called.
pub reducer_id: u32,
/// The arguments to the reducer, encoded as BSATN or JSON according to the reducer's argument schema
Expand Down Expand Up @@ -653,7 +654,7 @@ pub struct TableUpdate<F: WebsocketFormat> {
///
/// NOTE(centril, 1.0): we might want to remove this and instead
/// tell clients about changes to table_name <-> table_id mappings.
pub table_name: Box<str>,
pub table_name: RawIdentifier,
/// The sum total of rows in `self.updates`,
pub num_rows: u64,
/// The actual insert and delete updates for this table.
Expand All @@ -668,7 +669,7 @@ pub struct SingleQueryUpdate<F: WebsocketFormat> {
}

impl<F: WebsocketFormat> TableUpdate<F> {
pub fn new(table_id: TableId, table_name: Box<str>, update: SingleQueryUpdate<F>) -> Self {
pub fn new(table_id: TableId, table_name: RawIdentifier, update: SingleQueryUpdate<F>) -> Self {
Self {
table_id,
table_name,
Expand All @@ -677,7 +678,7 @@ impl<F: WebsocketFormat> TableUpdate<F> {
}
}

pub fn empty(table_id: TableId, table_name: Box<str>) -> Self {
pub fn empty(table_id: TableId, table_name: RawIdentifier) -> Self {
Self {
table_id,
table_name,
Expand Down Expand Up @@ -746,7 +747,7 @@ pub struct OneOffQueryResponse<F: WebsocketFormat> {
#[sats(crate = spacetimedb_lib)]
pub struct OneOffTable<F: WebsocketFormat> {
/// The name of the table.
pub table_name: Box<str>,
pub table_name: RawIdentifier,
/// The set of rows which matched the query, encoded as BSATN or JSON according to the table's schema
/// and the client's requested protocol.
///
Expand Down
1 change: 1 addition & 0 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ spacetimedb-lib = { path = "../lib", features = ["proptest", "test"] }
spacetimedb-sats = { path = "../sats", features = ["proptest"] }
spacetimedb-commitlog = { path = "../commitlog", features = ["test"] }
spacetimedb-datastore = { path = "../datastore/", features = ["test"] }
spacetimedb-vm = { workspace = true, features = ["test"]}

criterion.workspace = true
# Also as dev-dependencies for use in _this_ crate's tests.
Expand Down
9 changes: 7 additions & 2 deletions crates/core/src/client/message_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use spacetimedb_datastore::execution_context::WorkloadType;
use spacetimedb_lib::de::serde::DeserializeWrapper;
use spacetimedb_lib::identity::RequestId;
use spacetimedb_lib::{bsatn, ConnectionId, Timestamp};
use spacetimedb_sats::raw_identifier::RawIdentifier;
use spacetimedb_schema::identifier::Identifier;
use spacetimedb_schema::reducer_name::ReducerName;
use std::borrow::Cow;
use std::sync::Arc;
Expand Down Expand Up @@ -164,7 +166,7 @@ pub async fn handle(client: &ClientConnection, message: DataMessage, timer: Inst
#[derive(thiserror::Error, Debug)]
#[error("error executing message (reducer: {reducer:?}) (err: {err:#})")]
pub struct MessageExecutionError {
pub reducer: Option<Box<str>>,
pub reducer: Option<RawIdentifier>,
pub reducer_id: Option<ReducerId>,
pub caller_identity: Identity,
pub caller_connection_id: Option<ConnectionId>,
Expand All @@ -174,12 +176,15 @@ pub struct MessageExecutionError {

impl MessageExecutionError {
fn into_event(self) -> ModuleEvent {
let reducer = RawIdentifier::new(self.reducer.as_deref().unwrap_or("<none>"));
let reducer = ReducerName::new(Identifier::new(reducer).unwrap());

ModuleEvent {
timestamp: Timestamp::now(),
caller_identity: self.caller_identity,
caller_connection_id: self.caller_connection_id,
function_call: ModuleFunctionCall {
reducer: ReducerName::new_from_str(&self.reducer.unwrap_or_else(|| "<none>".into())),
reducer: Some(reducer),
reducer_id: self.reducer_id.unwrap_or(u32::MAX.into()),
args: Default::default(),
},
Expand Down
16 changes: 10 additions & 6 deletions crates/core/src/client/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::subscription::row_list_builder_pool::BsatnRowListBuilderPool;
use crate::subscription::websocket_building::{brotli_compress, decide_compression, gzip_compress};
use bytes::{BufMut, Bytes, BytesMut};
use bytestring::ByteString;
use core::ops::Deref;
use derive_more::From;
use spacetimedb_client_api_messages::websocket::{
BsatnFormat, Compression, FormatSwitch, JsonFormat, OneOffTable, RowListLen, WebsocketFormat,
Expand Down Expand Up @@ -283,7 +282,12 @@ impl ToProtocol for TransactionUpdateMessage {
status,
caller_identity: event.caller_identity,
reducer_call: ws::ReducerCallInfo {
reducer_name: event.function_call.reducer.deref().into(),
reducer_name: event
.function_call
.reducer
.clone()
.map(Into::into)
.unwrap_or_else(|| "".into()),
reducer_id: event.function_call.reducer_id.into(),
args,
request_id,
Expand Down Expand Up @@ -451,7 +455,7 @@ impl ToProtocol for SubscriptionMessage {
query_id,
rows: ws::SubscribeRows {
table_id: result.table_id,
table_name: result.table_name.to_boxed_str(),
table_name: result.table_name.into(),
table_rows,
},
}
Expand All @@ -464,7 +468,7 @@ impl ToProtocol for SubscriptionMessage {
query_id,
rows: ws::SubscribeRows {
table_id: result.table_id,
table_name: result.table_name.to_boxed_str(),
table_name: result.table_name.into(),
table_rows,
},
}
Expand All @@ -482,7 +486,7 @@ impl ToProtocol for SubscriptionMessage {
query_id,
rows: ws::SubscribeRows {
table_id: result.table_id,
table_name: result.table_name.to_boxed_str(),
table_name: result.table_name.into(),
table_rows,
},
}
Expand All @@ -495,7 +499,7 @@ impl ToProtocol for SubscriptionMessage {
query_id,
rows: ws::SubscribeRows {
table_id: result.table_id,
table_name: result.table_name.to_boxed_str(),
table_name: result.table_name.into(),
table_rows,
},
}
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/db/durability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ impl DurabilityWorkerActor {

pub fn do_durability(durability: &Durability, reducer_context: Option<ReducerContext>, tx_data: &TxData) {
if tx_data.tx_offset().is_none() {
let name = reducer_context.as_ref().map(|rcx| &*rcx.name);
let name = reducer_context.as_ref().map(|rcx| &rcx.name);
debug_assert!(
!tx_data.has_rows_or_connect_disconnect(name),
"tx_data has no rows but has connect/disconnect: `{name:?}`"
Expand Down Expand Up @@ -318,7 +318,7 @@ mod tests {
let mut txdata = TxData::default();
txdata.set_tx_offset(i);
// Ensure the transaction is non-empty.
txdata.set_inserts_for_table(4000.into(), &TableName::new_from_str("foo"), [product![42u8]].into());
txdata.set_inserts_for_table(4000.into(), &TableName::for_test("foo"), [product![42u8]].into());

worker.request_durability(None, &Arc::new(txdata));
}
Expand Down
Loading
Loading