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
37 changes: 36 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ criterion = { version = "0.4.0", features = ["async", "async_tokio", "html_repor
crossbeam-channel = "0.5"
cursive = "0.20"
decorum = { version = "0.3.1", default-features = false, features = ["std"] }
derive_more = "0.99.17"
dirs = "5.0.1"
duct = "0.13.5"
email_address = "0.2.4"
Expand Down
1 change: 1 addition & 0 deletions crates/bindings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ spacetimedb-bindings-sys = { path = "../bindings-sys", version = "0.6.1" }
spacetimedb-lib = { path = "../lib", default-features = false, version = "0.6.1"}
spacetimedb-bindings-macro = { path = "../bindings-macro", version = "0.6.1"}

derive_more.workspace = true
log.workspace = true
once_cell.workspace = true
scoped-tls.workspace = true
Expand Down
7 changes: 1 addition & 6 deletions crates/bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,16 +394,11 @@ pub struct IndexDef<'a> {
}

/// A table iterator which yields values of the `TableType` corresponding to the table.
#[derive(derive_more::From)]
pub struct TableIter<T: TableType> {
iter: TableTypeTableIter<T>,
}

impl<T: TableType> From<TableTypeTableIter<T>> for TableIter<T> {
fn from(iter: TableTypeTableIter<T>) -> Self {
Self { iter }
}
}

impl<T: TableType> Iterator for TableIter<T> {
type Item = T;

Expand Down
1 change: 1 addition & 0 deletions crates/client-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ bytes = "1"
bytestring = "1"
tokio-tungstenite = "0.18.0"
itoa = "1.0.9"
derive_more = "0.99.17"
58 changes: 22 additions & 36 deletions crates/client-api/src/routes/database.rs
Original file line number Diff line number Diff line change
@@ -1,46 +1,47 @@
use std::collections::HashMap;
use std::sync::Arc;

use axum::body::Bytes;
use axum::extract::{DefaultBodyLimit, FromRef, Path, Query, State};
use axum::response::{ErrorResponse, IntoResponse};
use axum::{headers, TypedHeader};
use chrono::Utc;
use futures::StreamExt;
use http::StatusCode;
use rand::Rng;
use serde::Deserialize;
use serde_json::{json, Value};
use spacetimedb::address::Address;
use spacetimedb::auth::identity::encode_token;
use spacetimedb::database_logger::DatabaseLogger;
use spacetimedb::host::DescribedEntityType;
use spacetimedb::host::EntityDef;
use spacetimedb::host::ReducerArgs;
use spacetimedb::host::ReducerCallError;
use spacetimedb::host::ReducerOutcome;
use spacetimedb::host::UpdateDatabaseSuccess;
use spacetimedb_lib::name;
use spacetimedb_lib::name::DomainName;
use spacetimedb_lib::name::DomainParsingError;
use spacetimedb_lib::name::PublishOp;
use spacetimedb::identity::Identity;
use spacetimedb::json::client_api::StmtResultJson;
use spacetimedb::messages::control_db::{Database, DatabaseInstance, HostType};
use spacetimedb::sql::execute::execute;
use spacetimedb_lib::identity::AuthCtx;
use spacetimedb_lib::name::{
self, DnsLookupResponse, DomainName, DomainParsingError, InsertDomainResult, PublishOp, PublishResult,
};
use spacetimedb_lib::recovery::{RecoveryCode, RecoveryCodeResponse};
use spacetimedb_lib::sats::WithTypespace;
use std::collections::HashMap;
use std::convert::From;
use std::sync::Arc;

use super::identity::IdentityForUrl;
use crate::auth::{
SpacetimeAuth, SpacetimeAuthHeader, SpacetimeEnergyUsed, SpacetimeExecutionDurationMicros, SpacetimeIdentity,
SpacetimeIdentityToken,
};
use spacetimedb::address::Address;
use spacetimedb::database_logger::DatabaseLogger;
use spacetimedb::host::DescribedEntityType;
use spacetimedb::identity::Identity;
use spacetimedb::json::client_api::StmtResultJson;
use spacetimedb::messages::control_db::{Database, DatabaseInstance, HostType};

use super::identity::IdentityForUrl;
use crate::util::{ByteStringBody, NameOrAddress};
use crate::{log_and_500, ControlCtx, ControlNodeDelegate, WorkerCtx};

#[derive(derive_more::From)]
pub(crate) struct DomainParsingRejection(pub(crate) DomainParsingError);
impl From<DomainParsingError> for DomainParsingRejection {
fn from(e: DomainParsingError) -> Self {
DomainParsingRejection(e)
}
}

impl IntoResponse for DomainParsingRejection {
fn into_response(self) -> axum::response::Response {
(StatusCode::BAD_REQUEST, "Unable to parse domain name").into_response()
Expand Down Expand Up @@ -147,28 +148,13 @@ fn reducer_outcome_response(identity: &Identity, reducer: &str, outcome: Reducer
}
}

#[derive(Debug)]
#[derive(Debug, derive_more::From)]
pub enum DBCallErr {
HandlerError(ErrorResponse),
NoSuchDatabase,
InstanceNotScheduled,
}

use chrono::Utc;
use rand::Rng;
use spacetimedb::auth::identity::encode_token;
use spacetimedb::sql::execute::execute;
use spacetimedb_lib::identity::AuthCtx;
use spacetimedb_lib::name::{DnsLookupResponse, InsertDomainResult, PublishResult};
use spacetimedb_lib::recovery::{RecoveryCode, RecoveryCodeResponse};
use std::convert::From;

impl From<ErrorResponse> for DBCallErr {
fn from(error: ErrorResponse) -> Self {
DBCallErr::HandlerError(error)
}
}

pub struct DatabaseInformation {
database_instance: DatabaseInstance,
auth: SpacetimeAuth,
Expand Down
8 changes: 1 addition & 7 deletions crates/client-api/src/routes/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,9 @@ pub async fn get_identity(
/// This newtype around `Identity` implements `Deserialize`
/// directly from the inner identity bytes,
/// without the enclosing `ProductValue` wrapper.
#[derive(derive_more::Into)]
pub struct IdentityForUrl(Identity);

impl From<IdentityForUrl> for Identity {
/// Consumes `self` returning the backing `Identity`.
fn from(IdentityForUrl(id): IdentityForUrl) -> Identity {
id
}
}

impl<'de> serde::Deserialize<'de> for IdentityForUrl {
fn deserialize<D: serde::Deserializer<'de>>(de: D) -> Result<Self, D::Error> {
<_>::deserialize(de).map(|DeserializeWrapper(b)| IdentityForUrl(Identity::from_byte_array(b)))
Expand Down
1 change: 1 addition & 0 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ bytes.workspace = true
bytestring.workspace = true
clap.workspace = true
crossbeam-channel.workspace = true
derive_more.workspace = true
dirs.workspace = true
email_address.workspace = true
flate2.workspace = true
Expand Down
15 changes: 2 additions & 13 deletions crates/core/src/client/client_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::ops::Deref;
use crate::host::{ModuleHost, NoSuchModule, ReducerArgs, ReducerCallError, ReducerCallResult};
use crate::protobuf::client_api::Subscribe;
use crate::worker_metrics::{CONNECTED_CLIENTS, WEBSOCKET_SENT, WEBSOCKET_SENT_MSG_SIZE};
use derive_more::From;
use futures::prelude::*;
use tokio::sync::mpsc;

Expand Down Expand Up @@ -68,7 +69,7 @@ impl Deref for ClientConnection {
}
}

#[derive(Debug)]
#[derive(Debug, From)]
pub enum DataMessage {
Text(String),
Binary(Vec<u8>),
Expand All @@ -88,18 +89,6 @@ impl DataMessage {
}
}

impl From<String> for DataMessage {
fn from(text: String) -> Self {
DataMessage::Text(text)
}
}

impl From<Vec<u8>> for DataMessage {
fn from(bin: Vec<u8>) -> Self {
DataMessage::Binary(bin)
}
}

impl ClientConnection {
/// Returns an error if ModuleHost closed
pub async fn spawn<F, Fut>(
Expand Down
23 changes: 10 additions & 13 deletions crates/core/src/db/datastore/locking_tx_datastore/mod.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
mod btree_index;
mod sequence;
mod table;

use self::{
btree_index::{BTreeIndex, BTreeIndexRangeIter},
sequence::Sequence,
table::Table,
};
use std::{
collections::{BTreeMap, BTreeSet, HashMap},
ops::RangeBounds,
sync::Arc,
vec,
};

use super::{
system_tables::{
StColumnRow, StIndexRow, StSequenceRow, StTableRow, INDEX_ID_SEQUENCE_ID, SEQUENCE_ID_SEQUENCE_ID,
Expand Down Expand Up @@ -41,6 +35,8 @@ use crate::{
},
error::{DBError, IndexError, TableError},
};

use derive_more::Into;
use parking_lot::{lock_api::ArcMutexGuard, Mutex, RawMutex};
use spacetimedb_lib::{
auth::{StAccess, StTableType},
Expand All @@ -51,6 +47,12 @@ use spacetimedb_lib::{
use spacetimedb_sats::{
AlgebraicType, AlgebraicValue, BuiltinType, BuiltinValue, ProductType, ProductTypeElement, ProductValue,
};
use std::{
collections::{BTreeMap, BTreeSet, HashMap},
ops::RangeBounds,
sync::Arc,
vec,
};
use thiserror::Error;

#[derive(Error, Debug, PartialEq, Eq)]
Expand All @@ -77,16 +79,11 @@ pub enum SequenceError {

const SEQUENCE_PREALLOCATION_AMOUNT: i128 = 4_096;

#[derive(Into)]
pub struct Data {
data: ProductValue,
}

impl From<Data> for ProductValue {
fn from(data: Data) -> Self {
data.data
}
}

impl traits::Data for Data {
fn view(&self) -> &ProductValue {
&self.data
Expand Down
6 changes: 6 additions & 0 deletions crates/core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ impl DBError {
}
}

impl From<DBError> for ErrorVm {
fn from(err: DBError) -> Self {
ErrorVm::Other(err.into())
}
}

impl From<InvalidFieldError> for DBError {
fn from(value: InvalidFieldError) -> Self {
LibError::from(value).into()
Expand Down
Loading