Skip to content

Commit

Permalink
Move lib::{name,recovery} to client-api-messages
Browse files Browse the repository at this point in the history
  • Loading branch information
coolreader18 committed Apr 4, 2024
1 parent 02d0428 commit 76ec551
Show file tree
Hide file tree
Showing 23 changed files with 70 additions and 94 deletions.
15 changes: 12 additions & 3 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 crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ bench = false
[dependencies]
spacetimedb-primitives.workspace = true
spacetimedb-core.workspace = true
spacetimedb-lib = { workspace = true, features = ["cli"] }
spacetimedb-lib.workspace = true
spacetimedb-standalone = { workspace = true, optional = true }
spacetimedb-client-api-messages.workspace = true

anyhow.workspace = true
base64.workspace = true
Expand Down
7 changes: 4 additions & 3 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use clap::Command;
use mimalloc::MiMalloc;
use spacetimedb_cli::*;
use spacetimedb_lib::util;

#[global_allocator]
static GLOBAL: MiMalloc = MiMalloc;
Expand All @@ -12,15 +11,17 @@ async fn main() -> Result<(), anyhow::Error> {
// Save a default version to disk
config.save();

let (cmd, subcommand_args) = util::match_subcommand_or_exit(get_command());
exec_subcommand(config, &cmd, &subcommand_args).await?;
let matches = get_command().get_matches();
let (cmd, subcommand_args) = matches.subcommand().unwrap();
exec_subcommand(config, cmd, subcommand_args).await?;

Ok(())
}

fn get_command() -> Command {
Command::new("spacetime")
.args_conflicts_with_subcommands(true)
.arg_required_else_help(true)
.subcommand_required(true)
.subcommands(get_subcommands())
.help_expected(true)
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/subcommands/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use clap::ArgMatches;
use clap::{Arg, Command};
use reqwest::Url;

use spacetimedb_lib::name::{DnsLookupResponse, InsertDomainResult, RegisterTldResult};
use spacetimedb_client_api_messages::name::{DnsLookupResponse, InsertDomainResult, RegisterTldResult};

pub fn cli() -> Command {
Command::new("dns")
Expand Down
3 changes: 2 additions & 1 deletion crates/cli/src/subcommands/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ use email_address::EmailAddress;
use reqwest::{StatusCode, Url};
use serde::Deserialize;
use spacetimedb::auth::identity::decode_token;
use spacetimedb_lib::{recovery::RecoveryCodeResponse, Identity};
use spacetimedb_client_api_messages::recovery::RecoveryCodeResponse;
use spacetimedb_lib::Identity;
use tabled::{
settings::{object::Columns, Alignment, Modify, Style},
Table, Tabled,
Expand Down
4 changes: 2 additions & 2 deletions crates/cli/src/subcommands/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use clap::Arg;
use clap::ArgAction::SetTrue;
use clap::ArgMatches;
use reqwest::{StatusCode, Url};
use spacetimedb_lib::name::PublishOp;
use spacetimedb_lib::name::{is_address, parse_domain_name, PublishResult};
use spacetimedb_client_api_messages::name::PublishOp;
use spacetimedb_client_api_messages::name::{is_address, parse_domain_name, PublishResult};
use std::fs;
use std::path::PathBuf;

Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::Context;
use base64::{engine::general_purpose::STANDARD as BASE_64_STD, Engine as _};
use reqwest::RequestBuilder;
use serde::Deserialize;
use spacetimedb_lib::name::{DnsLookupResponse, RegisterTldResult, ReverseDNSResponse};
use spacetimedb_client_api_messages::name::{DnsLookupResponse, RegisterTldResult, ReverseDNSResponse};
use spacetimedb_lib::{Address, AlgebraicType, Identity};
use std::collections::HashMap;
use std::io::Write;
Expand Down
12 changes: 12 additions & 0 deletions crates/client-api-messages/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,20 @@ license-file = "LICENSE"
description = "Types for the SpacetimeDB client API messages"

[dependencies]
spacetimedb-lib = { workspace = true, features = ["serde"] }
spacetimedb-sats.workspace = true

chrono = { workspace = true, features = ["serde"] }
prost.workspace = true
serde = { workspace = true, features = ["derive"] }
strum.workspace = true
thiserror.workspace = true

[build-dependencies]
prost-build.workspace = true

[dev-dependencies]
hex.workspace = true
itertools.workspace = true
proptest.workspace = true
serde_json.workspace = true
3 changes: 3 additions & 0 deletions crates/client-api-messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
#![allow(clippy::four_forward_slashes)]

include!(concat!(env!("OUT_DIR"), "/protobuf.rs"));

pub mod name;
pub mod recovery;
33 changes: 10 additions & 23 deletions crates/lib/src/name.rs → crates/client-api-messages/src/name.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use spacetimedb_sats::{impl_deserialize, impl_serialize, impl_st};
use std::{borrow::Borrow, fmt, ops::Deref, str::FromStr};

use crate::Address;
use spacetimedb_lib::Address;

#[cfg(test)]
mod tests;

#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub enum InsertDomainResult {
Success {
domain: DomainName,
Expand Down Expand Up @@ -39,19 +38,14 @@ pub enum InsertDomainResult {
OtherError(String),
}

#[derive(Clone, Copy, Debug)]
#[cfg_attr(
feature = "serde",
derive(serde::Serialize, serde::Deserialize),
serde(rename_all = "lowercase")
)]
#[derive(Clone, Copy, Debug, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum PublishOp {
Created,
Updated,
}

#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub enum PublishResult {
Success {
/// `Some` if publish was given a domain name to operate on, `None`
Expand Down Expand Up @@ -88,8 +82,7 @@ pub enum PublishResult {
PermissionDenied { domain: DomainName },
}

#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub enum DnsLookupResponse {
/// The lookup was successful and the domain and address are returned.
Success { domain: DomainName, address: Address },
Expand All @@ -98,8 +91,7 @@ pub enum DnsLookupResponse {
Failure { domain: DomainName },
}

#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub enum RegisterTldResult {
Success {
domain: Tld,
Expand All @@ -115,8 +107,7 @@ pub enum RegisterTldResult {
// TODO(jdetter): Insufficient funds error here
}

#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub enum SetDefaultDomainResult {
Success {
domain: DomainName,
Expand All @@ -139,8 +130,7 @@ pub enum SetDefaultDomainResult {
///
/// Note that the SpacetimeDB DNS registry may apply additional restrictions on
/// what TLDs can be registered.
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize)]
pub struct Tld(String);

impl Tld {
Expand Down Expand Up @@ -187,7 +177,6 @@ impl_deserialize!([] Tld, de => {
Ok(Self(s))
});

#[cfg(feature = "serde")]
impl<'de> serde::Deserialize<'de> for Tld {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
Expand Down Expand Up @@ -363,7 +352,6 @@ impl_deserialize!([] DomainName, de => {
parse_domain_name(s).map_err(spacetimedb_sats::de::Error::custom)
});

#[cfg(feature = "serde")]
mod serde_impls {
use super::*;

Expand Down Expand Up @@ -435,8 +423,7 @@ mod serde_impls {
}
}

#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct ReverseDNSResponse {
pub names: Vec<DomainName>,
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use chrono::serde::ts_seconds;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};

use crate::Identity;
use spacetimedb_lib::Identity;

#[derive(Deserialize, Serialize, Clone)]
pub struct RecoveryCode {
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 @@ -6,6 +6,7 @@ license-file = "LICENSE"
description = "The HTTP API for SpacetimeDB"

[dependencies]
spacetimedb-client-api-messages.workspace = true
spacetimedb-core.workspace = true
spacetimedb-lib = { workspace = true, features = ["serde"] }

Expand Down
4 changes: 2 additions & 2 deletions crates/client-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use spacetimedb::identity::Identity;
use spacetimedb::messages::control_db::{Database, DatabaseInstance, IdentityEmail, Node};
use spacetimedb::module_host_context::ModuleHostContext;
use spacetimedb::sendgrid_controller::SendGridController;
use spacetimedb_lib::name::{DomainName, InsertDomainResult, RegisterTldResult, Tld};
use spacetimedb_lib::recovery::RecoveryCode;
use spacetimedb_client_api_messages::name::{DomainName, InsertDomainResult, RegisterTldResult, Tld};
use spacetimedb_client_api_messages::recovery::RecoveryCode;

pub mod auth;
pub mod routes;
Expand Down
4 changes: 2 additions & 2 deletions crates/client-api/src/routes/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ use spacetimedb::identity::Identity;
use spacetimedb::json::client_api::StmtResultJson;
use spacetimedb::messages::control_db::{Database, DatabaseInstance};
use spacetimedb::sql::execute::execute;
use spacetimedb_client_api_messages::name::{self, DnsLookupResponse, DomainName, PublishOp, PublishResult};
use spacetimedb_client_api_messages::recovery::{RecoveryCode, RecoveryCodeResponse};
use spacetimedb_lib::address::AddressForUrl;
use spacetimedb_lib::identity::AuthCtx;
use spacetimedb_lib::name::{self, DnsLookupResponse, DomainName, PublishOp, PublishResult};
use spacetimedb_lib::recovery::{RecoveryCode, RecoveryCodeResponse};
use spacetimedb_lib::sats::WithTypespace;
use std::collections::HashMap;
use std::convert::From;
Expand Down
2 changes: 1 addition & 1 deletion crates/client-api/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use bytestring::ByteString;
use http::{HeaderName, HeaderValue, StatusCode};

use spacetimedb::address::Address;
use spacetimedb_client_api_messages::name::DomainName;
use spacetimedb_lib::address::AddressForUrl;
use spacetimedb_lib::name::DomainName;

use crate::routes::database::DomainParsingRejection;
use crate::{log_and_500, ControlStateReadAccess};
Expand Down
8 changes: 2 additions & 6 deletions crates/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ required-features = ["serde"]

[features]
default = ["serde", "metrics"]
serde = ["dep:serde", "spacetimedb-sats/serde", "dep:serde_with", "chrono/serde"]
cli = ["clap"]
serde = ["dep:serde", "spacetimedb-sats/serde"]
# Allows using `Arbitrary` impls defined in this crate.
proptest = ["dep:proptest", "dep:proptest-derive"]
metrics = ["dep:spacetimedb-metrics", "spacetimedb-sats/metrics"]
Expand All @@ -30,14 +29,11 @@ spacetimedb-metrics = { workspace = true, optional = true }

anyhow.workspace = true
bitflags.workspace = true
chrono = { workspace = true, optional = true }
clap = {workspace = true, optional = true }
derive_more.workspace = true
enum-as-inner.workspace = true
hex.workspace = true
itertools.workspace = true
serde = { workspace = true, optional = true, features = ["derive"] }
serde_with = {workspace = true, optional = true }
serde = { workspace = true, optional = true }
thiserror.workspace = true

# For the 'proptest' feature.
Expand Down
5 changes: 0 additions & 5 deletions crates/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use spacetimedb_sats::{impl_serialize, WithTypespace};
pub mod address;
pub mod filter;
pub mod identity;
pub mod name;
pub mod operator;
pub mod type_def {
pub use spacetimedb_sats::{AlgebraicType, ProductType, ProductTypeElement, SumType};
Expand All @@ -15,10 +14,6 @@ pub mod type_value {
}

pub mod error;
#[cfg(feature = "serde")]
pub mod recovery;
#[cfg(feature = "cli")]
pub mod util;
pub mod version;

pub use address::Address;
Expand Down
Loading

0 comments on commit 76ec551

Please sign in to comment.