build fixes and cleanup

This commit is contained in:
Christien Rioux 2023-08-31 22:01:00 -04:00 committed by Brandon Vandegrift
parent 779532b624
commit 9aeec3cfa8
21 changed files with 160 additions and 186 deletions

9
Cargo.lock generated
View File

@ -5396,15 +5396,6 @@ dependencies = [
"wasm-bindgen", "wasm-bindgen",
] ]
[[package]]
name = "tsify-async"
version = "0.1.0"
dependencies = [
"quote",
"serde-wasm-bindgen",
"syn 1.0.109",
]
[[package]] [[package]]
name = "tsify-macros" name = "tsify-macros"
version = "0.4.5" version = "0.4.5"

View File

@ -6,7 +6,6 @@ members = [
"veilid-cli", "veilid-cli",
"veilid-flutter/rust", "veilid-flutter/rust",
"veilid-wasm", "veilid-wasm",
"tsify-async"
] ]
exclude = ["./external"] exclude = ["./external"]

View File

@ -1,14 +0,0 @@
[package]
name = "tsify-async"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
proc-macro = true
[dependencies]
syn = "1.0"
quote = "1.0"
serde-wasm-bindgen = "0.5.0"

View File

@ -1,30 +0,0 @@
// Copied from https://github.com/madonoharu/tsify/issues/24#issuecomment-1670228789
// TODO: I think this had more to do with:
// the trait `From<veilid_core::VeilidUpdate>` is not implemented for `wasm_bindgen::JsValue`
// than it does with tsify itself... Maybe rename to something else?
use proc_macro::TokenStream;
use quote::quote;
use syn;
#[proc_macro_derive(TsifyAsync)]
pub fn tsify_async_macro_derive(input: TokenStream) -> TokenStream {
// Construct a representation of Rust code as a syntax tree
// that we can manipulate
let ast = syn::parse(input).unwrap();
// Build the trait implementation
impl_tsify_async_macro(&ast)
}
fn impl_tsify_async_macro(ast: &syn::DeriveInput) -> TokenStream {
let name = &ast.ident;
let gen = quote! {
impl From<#name> for JsValue {
fn from(value: #name) -> Self {
serde_wasm_bindgen::to_value(&value).unwrap()
}
}
};
gen.into()
}

View File

@ -140,9 +140,6 @@ lz4_flex = { version = "0.11.1", default-features = false, features = [
"safe-encode", "safe-encode",
"safe-decode", "safe-decode",
] } ] }
tsify = { version = "0.4.5", features = ["js"] }
wasm-bindgen = "^0"
serde-wasm-bindgen = "0.5.0"
# Dependencies for native builds only # Dependencies for native builds only
# Linux, Windows, Mac, iOS, Android # Linux, Windows, Mac, iOS, Android
@ -202,6 +199,8 @@ wasm-bindgen = "0.2.87"
js-sys = "0.3.64" js-sys = "0.3.64"
wasm-bindgen-futures = "0.4.37" wasm-bindgen-futures = "0.4.37"
send_wrapper = { version = "0.6.0", features = ["futures"] } send_wrapper = { version = "0.6.0", features = ["futures"] }
tsify = { version = "0.4.5", features = ["js"] }
serde-wasm-bindgen = "0.5.0"
# Network # Network
ws_stream_wasm = "0.7.4" ws_stream_wasm = "0.7.4"

View File

@ -293,17 +293,17 @@ macro_rules! byte_array_type {
byte_array_type!(CryptoKey, CRYPTO_KEY_LENGTH, CRYPTO_KEY_LENGTH_ENCODED); byte_array_type!(CryptoKey, CRYPTO_KEY_LENGTH, CRYPTO_KEY_LENGTH_ENCODED);
#[declare] #[cfg_attr(target_arch = "wasm32", declare)]
pub type PublicKey = CryptoKey; pub type PublicKey = CryptoKey;
#[declare] #[cfg_attr(target_arch = "wasm32", declare)]
pub type SecretKey = CryptoKey; pub type SecretKey = CryptoKey;
#[declare] #[cfg_attr(target_arch = "wasm32", declare)]
pub type HashDigest = CryptoKey; pub type HashDigest = CryptoKey;
#[declare] #[cfg_attr(target_arch = "wasm32", declare)]
pub type SharedSecret = CryptoKey; pub type SharedSecret = CryptoKey;
#[declare] #[cfg_attr(target_arch = "wasm32", declare)]
pub type RouteId = CryptoKey; pub type RouteId = CryptoKey;
#[declare] #[cfg_attr(target_arch = "wasm32", declare)]
pub type CryptoKeyDistance = CryptoKey; pub type CryptoKeyDistance = CryptoKey;
byte_array_type!(Signature, SIGNATURE_LENGTH, SIGNATURE_LENGTH_ENCODED); byte_array_type!(Signature, SIGNATURE_LENGTH, SIGNATURE_LENGTH_ENCODED);

View File

@ -1,6 +1,7 @@
use super::*; use super::*;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Tsify)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub struct CryptoTyped<K> pub struct CryptoTyped<K>
where where
K: Clone K: Clone

View File

@ -1,8 +1,7 @@
use super::*; use super::*;
#[derive( #[derive(Clone, Debug, Serialize, Deserialize, PartialOrd, Ord, PartialEq, Eq, Hash, Default)]
Clone, Debug, Serialize, Deserialize, PartialOrd, Ord, PartialEq, Eq, Hash, Default, Tsify, #[cfg_attr(target_arch = "wasm32", derive(Tsify))]
)]
#[serde(from = "Vec<CryptoTyped<K>>", into = "Vec<CryptoTyped<K>>")] #[serde(from = "Vec<CryptoTyped<K>>", into = "Vec<CryptoTyped<K>>")]
// TODO: figure out hot to TS type this as `string`, since it's converted to string via the JSON API. // TODO: figure out hot to TS type this as `string`, since it's converted to string via the JSON API.
pub struct CryptoTypedGroup<K = PublicKey> pub struct CryptoTypedGroup<K = PublicKey>

View File

@ -6,7 +6,7 @@ use core::fmt;
use core::hash::Hash; use core::hash::Hash;
/// Cryptography version fourcc code /// Cryptography version fourcc code
#[declare] #[cfg_attr(target_arch = "wasm32", declare)]
pub type CryptoKind = FourCC; pub type CryptoKind = FourCC;
/// Sort best crypto kinds first /// Sort best crypto kinds first
@ -52,24 +52,24 @@ pub use crypto_typed::*;
pub use crypto_typed_group::*; pub use crypto_typed_group::*;
pub use keypair::*; pub use keypair::*;
#[declare] #[cfg_attr(target_arch = "wasm32", declare)]
pub type TypedKey = CryptoTyped<PublicKey>; pub type TypedKey = CryptoTyped<PublicKey>;
#[declare] #[cfg_attr(target_arch = "wasm32", declare)]
pub type TypedSecret = CryptoTyped<SecretKey>; pub type TypedSecret = CryptoTyped<SecretKey>;
#[declare] #[cfg_attr(target_arch = "wasm32", declare)]
pub type TypedKeyPair = CryptoTyped<KeyPair>; pub type TypedKeyPair = CryptoTyped<KeyPair>;
#[declare] #[cfg_attr(target_arch = "wasm32", declare)]
pub type TypedSignature = CryptoTyped<Signature>; pub type TypedSignature = CryptoTyped<Signature>;
#[declare] #[cfg_attr(target_arch = "wasm32", declare)]
pub type TypedSharedSecret = CryptoTyped<SharedSecret>; pub type TypedSharedSecret = CryptoTyped<SharedSecret>;
#[declare] #[cfg_attr(target_arch = "wasm32", declare)]
pub type TypedKeyGroup = CryptoTypedGroup<PublicKey>; pub type TypedKeyGroup = CryptoTypedGroup<PublicKey>;
#[declare] #[cfg_attr(target_arch = "wasm32", declare)]
pub type TypedSecretGroup = CryptoTypedGroup<SecretKey>; pub type TypedSecretGroup = CryptoTypedGroup<SecretKey>;
#[declare] #[cfg_attr(target_arch = "wasm32", declare)]
pub type TypedKeyPairGroup = CryptoTypedGroup<KeyPair>; pub type TypedKeyPairGroup = CryptoTypedGroup<KeyPair>;
#[declare] #[cfg_attr(target_arch = "wasm32", declare)]
pub type TypedSignatureGroup = CryptoTypedGroup<Signature>; pub type TypedSignatureGroup = CryptoTypedGroup<Signature>;
#[declare] #[cfg_attr(target_arch = "wasm32", declare)]
pub type TypedSharedSecretGroup = CryptoTypedGroup<SharedSecret>; pub type TypedSharedSecretGroup = CryptoTypedGroup<SharedSecret>;

View File

@ -56,6 +56,7 @@ mod table_store;
mod veilid_api; mod veilid_api;
mod veilid_config; mod veilid_config;
mod veilid_layer_filter; mod veilid_layer_filter;
mod wasm_helpers;
pub use self::api_tracing_layer::ApiTracingLayer; pub use self::api_tracing_layer::ApiTracingLayer;
pub use self::core_context::{api_startup, api_startup_json, UpdateCallback}; pub use self::core_context::{api_startup, api_startup_json, UpdateCallback};
@ -126,7 +127,5 @@ use serde::*;
use stop_token::*; use stop_token::*;
use thiserror::Error as ThisError; use thiserror::Error as ThisError;
use tracing::*; use tracing::*;
use tsify::*;
use tsify_async::*;
use veilid_tools::*; use veilid_tools::*;
use wasm_bindgen::prelude::*; use wasm_helpers::*;

View File

@ -105,21 +105,10 @@ macro_rules! apibail_already_initialized {
} }
#[derive( #[derive(
ThisError, ThisError, Clone, Debug, PartialOrd, PartialEq, Eq, Ord, Serialize, Deserialize, JsonSchema,
Clone,
Debug,
PartialOrd,
PartialEq,
Eq,
Ord,
Serialize,
Deserialize,
JsonSchema,
Tsify,
TsifyAsync,
)] )]
#[cfg_attr(target_arch = "wasm32", derive(Tsify), tsify(into_wasm_abi))]
#[serde(tag = "kind")] #[serde(tag = "kind")]
#[tsify(into_wasm_abi)]
pub enum VeilidAPIError { pub enum VeilidAPIError {
#[error("Not initialized")] #[error("Not initialized")]
NotInitialized, NotInitialized,
@ -157,6 +146,7 @@ pub enum VeilidAPIError {
#[error("Generic: {message}")] #[error("Generic: {message}")]
Generic { message: String }, Generic { message: String },
} }
from_impl_to_jsvalue!(VeilidAPIError);
impl VeilidAPIError { impl VeilidAPIError {
pub fn not_initialized() -> Self { pub fn not_initialized() -> Self {
@ -225,7 +215,7 @@ impl VeilidAPIError {
} }
} }
#[declare] #[cfg_attr(target_arch = "wasm32", declare)]
pub type VeilidAPIResult<T> = Result<T, VeilidAPIError>; pub type VeilidAPIResult<T> = Result<T, VeilidAPIError>;
impl From<std::io::Error> for VeilidAPIError { impl From<std::io::Error> for VeilidAPIError {

View File

@ -6,19 +6,9 @@ use super::*;
/// Supports serializing to string for JSON as well, since JSON can't handle 64-bit numbers to Javascript /// Supports serializing to string for JSON as well, since JSON can't handle 64-bit numbers to Javascript
#[derive( #[derive(
Clone, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Copy, Hash, Serialize, Deserialize, JsonSchema,
Default,
PartialEq,
Eq,
PartialOrd,
Ord,
Copy,
Hash,
Serialize,
Deserialize,
JsonSchema,
Tsify,
)] )]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[repr(C, align(8))] #[repr(C, align(8))]
#[serde(transparent)] #[serde(transparent)]
pub struct AlignedU64( pub struct AlignedU64(
@ -128,17 +118,17 @@ impl AlignedU64 {
///////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////
/// Microseconds since epoch /// Microseconds since epoch
#[declare] #[cfg_attr(target_arch = "wasm32", declare)]
pub type Timestamp = AlignedU64; pub type Timestamp = AlignedU64;
pub fn get_aligned_timestamp() -> Timestamp { pub fn get_aligned_timestamp() -> Timestamp {
get_timestamp().into() get_timestamp().into()
} }
/// Microseconds duration /// Microseconds duration
#[declare] #[cfg_attr(target_arch = "wasm32", declare)]
pub type TimestampDuration = AlignedU64; pub type TimestampDuration = AlignedU64;
/// Request/Response matching id /// Request/Response matching id
#[declare] #[cfg_attr(target_arch = "wasm32", declare)]
pub type OperationId = AlignedU64; pub type OperationId = AlignedU64;
/// Number of bytes /// Number of bytes
#[declare] #[cfg_attr(target_arch = "wasm32", declare)]
pub type ByteCount = AlignedU64; pub type ByteCount = AlignedU64;

View File

@ -1,11 +1,12 @@
use super::*; use super::*;
/// Direct statement blob passed to hosting application for processing /// Direct statement blob passed to hosting application for processing
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify)] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub struct VeilidAppMessage { pub struct VeilidAppMessage {
#[serde(with = "as_human_opt_string")] #[serde(with = "as_human_opt_string")]
#[schemars(with = "Option<String>")] #[schemars(with = "Option<String>")]
#[tsify(optional)] #[cfg_attr(target_arch = "wasm32", tsify(optional))]
sender: Option<TypedKey>, sender: Option<TypedKey>,
#[serde(with = "as_human_base64")] #[serde(with = "as_human_base64")]
@ -30,11 +31,12 @@ impl VeilidAppMessage {
} }
/// Direct question blob passed to hosting application for processing to send an eventual AppReply /// Direct question blob passed to hosting application for processing to send an eventual AppReply
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify)] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub struct VeilidAppCall { pub struct VeilidAppCall {
#[serde(with = "as_human_opt_string")] #[serde(with = "as_human_opt_string")]
#[schemars(with = "Option<String>")] #[schemars(with = "Option<String>")]
#[tsify(optional)] #[cfg_attr(target_arch = "wasm32", tsify(optional))]
sender: Option<TypedKey>, sender: Option<TypedKey>,
#[serde(with = "as_human_base64")] #[serde(with = "as_human_base64")]

View File

@ -11,8 +11,8 @@ pub use value_data::*;
pub use value_subkey_range_set::*; pub use value_subkey_range_set::*;
/// Value subkey /// Value subkey
#[declare] #[cfg_attr(target_arch = "wasm32", declare)]
pub type ValueSubkey = u32; pub type ValueSubkey = u32;
/// Value sequence number /// Value sequence number
#[declare] #[cfg_attr(target_arch = "wasm32", declare)]
pub type ValueSeqNum = u32; pub type ValueSeqNum = u32;

View File

@ -1,9 +1,8 @@
use super::*; use super::*;
use veilid_api::VeilidAPIResult; use veilid_api::VeilidAPIResult;
#[derive( #[derive(Clone, Default, PartialOrd, PartialEq, Eq, Ord, Serialize, Deserialize, JsonSchema)]
Clone, Default, PartialOrd, PartialEq, Eq, Ord, Serialize, Deserialize, JsonSchema, Tsify, #[cfg_attr(target_arch = "wasm32", derive(Tsify))]
)]
pub struct ValueData { pub struct ValueData {
/// An increasing sequence number to time-order the DHT record changes /// An increasing sequence number to time-order the DHT record changes
seq: ValueSeqNum, seq: ValueSeqNum,

View File

@ -2,19 +2,9 @@ use super::*;
/// FOURCC code /// FOURCC code
#[derive( #[derive(
Copy, Copy, Default, Clone, Hash, PartialOrd, Ord, PartialEq, Eq, Serialize, Deserialize, JsonSchema,
Default,
Clone,
Hash,
PartialOrd,
Ord,
PartialEq,
Eq,
Serialize,
Deserialize,
JsonSchema,
Tsify,
)] )]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[serde(try_from = "String")] #[serde(try_from = "String")]
#[serde(into = "String")] #[serde(into = "String")]
pub struct FourCC(pub [u8; 4]); pub struct FourCC(pub [u8; 4]);

View File

@ -2,9 +2,9 @@ use super::*;
/// Log level for VeilidCore /// Log level for VeilidCore
#[derive( #[derive(
Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Copy, Serialize, Deserialize, JsonSchema, Tsify, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Copy, Serialize, Deserialize, JsonSchema,
)] )]
#[tsify(namespace)] #[cfg_attr(target_arch = "wasm32", derive(Tsify), tsify(namespace))]
pub enum VeilidLogLevel { pub enum VeilidLogLevel {
Error = 1, Error = 1,
Warn = 2, Warn = 2,
@ -80,10 +80,11 @@ impl fmt::Display for VeilidLogLevel {
} }
} }
/// A VeilidCore log message with optional backtrace /// A VeilidCore log message with optional backtrace
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify)] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub struct VeilidLog { pub struct VeilidLog {
pub log_level: VeilidLogLevel, pub log_level: VeilidLogLevel,
pub message: String, pub message: String,
#[tsify(optional)] #[cfg_attr(target_arch = "wasm32", tsify(optional))]
pub backtrace: Option<String>, pub backtrace: Option<String>,
} }

View File

@ -1,8 +1,12 @@
use super::*; use super::*;
/// Attachment abstraction for network 'signal strength' /// Attachment abstraction for network 'signal strength'
#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize, JsonSchema, Tsify)] #[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize, JsonSchema)]
#[tsify(namespace, from_wasm_abi, into_wasm_abi)] #[cfg_attr(
target_arch = "wasm32",
derive(Tsify),
tsify(namespace, from_wasm_abi, into_wasm_abi)
)]
pub enum AttachmentState { pub enum AttachmentState {
Detached = 0, Detached = 0,
Attaching = 1, Attaching = 1,
@ -48,14 +52,16 @@ impl TryFrom<String> for AttachmentState {
} }
} }
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify)] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub struct VeilidStateAttachment { pub struct VeilidStateAttachment {
pub state: AttachmentState, pub state: AttachmentState,
pub public_internet_ready: bool, pub public_internet_ready: bool,
pub local_network_ready: bool, pub local_network_ready: bool,
} }
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify)] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub struct PeerTableData { pub struct PeerTableData {
#[schemars(with = "Vec<String>")] #[schemars(with = "Vec<String>")]
pub node_ids: Vec<TypedKey>, pub node_ids: Vec<TypedKey>,
@ -63,7 +69,8 @@ pub struct PeerTableData {
pub peer_stats: PeerStats, pub peer_stats: PeerStats,
} }
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify)] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub struct VeilidStateNetwork { pub struct VeilidStateNetwork {
pub started: bool, pub started: bool,
pub bps_down: ByteCount, pub bps_down: ByteCount,
@ -71,7 +78,8 @@ pub struct VeilidStateNetwork {
pub peers: Vec<PeerTableData>, pub peers: Vec<PeerTableData>,
} }
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify)] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub struct VeilidRouteChange { pub struct VeilidRouteChange {
#[schemars(with = "Vec<String>")] #[schemars(with = "Vec<String>")]
pub dead_routes: Vec<RouteId>, pub dead_routes: Vec<RouteId>,
@ -79,12 +87,14 @@ pub struct VeilidRouteChange {
pub dead_remote_routes: Vec<RouteId>, pub dead_remote_routes: Vec<RouteId>,
} }
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify)] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub struct VeilidStateConfig { pub struct VeilidStateConfig {
pub config: VeilidConfigInner, pub config: VeilidConfigInner,
} }
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify)] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub struct VeilidValueChange { pub struct VeilidValueChange {
#[schemars(with = "String")] #[schemars(with = "String")]
pub key: TypedKey, pub key: TypedKey,
@ -93,9 +103,9 @@ pub struct VeilidValueChange {
pub value: ValueData, pub value: ValueData,
} }
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify, TsifyAsync)] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify), tsify(into_wasm_abi))]
#[serde(tag = "kind")] #[serde(tag = "kind")]
#[tsify(into_wasm_abi)]
pub enum VeilidUpdate { pub enum VeilidUpdate {
Log(VeilidLog), Log(VeilidLog),
AppMessage(VeilidAppMessage), AppMessage(VeilidAppMessage),
@ -107,11 +117,13 @@ pub enum VeilidUpdate {
ValueChange(VeilidValueChange), ValueChange(VeilidValueChange),
Shutdown, Shutdown,
} }
from_impl_to_jsvalue!(VeilidUpdate);
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify, TsifyAsync)] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[tsify(into_wasm_abi)] #[cfg_attr(target_arch = "wasm32", derive(Tsify), tsify(into_wasm_abi))]
pub struct VeilidState { pub struct VeilidState {
pub attachment: VeilidStateAttachment, pub attachment: VeilidStateAttachment,
pub network: VeilidStateNetwork, pub network: VeilidStateNetwork,
pub config: VeilidStateConfig, pub config: VeilidStateConfig,
} }
from_impl_to_jsvalue!(VeilidState);

View File

@ -1,9 +1,9 @@
use crate::*; use crate::*;
//////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////
#[declare] #[cfg_attr(target_arch = "wasm32", declare)]
pub type ConfigCallbackReturn = VeilidAPIResult<Box<dyn core::any::Any + Send>>; pub type ConfigCallbackReturn = VeilidAPIResult<Box<dyn core::any::Any + Send>>;
#[declare] #[cfg_attr(target_arch = "wasm32", declare)]
pub type ConfigCallback = Arc<dyn Fn(String) -> ConfigCallbackReturn + Send + Sync>; pub type ConfigCallback = Arc<dyn Fn(String) -> ConfigCallbackReturn + Send + Sync>;
/// Enable and configure HTTPS access to the Veilid node /// Enable and configure HTTPS access to the Veilid node
@ -16,12 +16,13 @@ pub type ConfigCallback = Arc<dyn Fn(String) -> ConfigCallbackReturn + Send + Sy
/// url: 'https://localhost:5150' /// url: 'https://localhost:5150'
/// ``` /// ```
/// ///
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify)] #[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub struct VeilidConfigHTTPS { pub struct VeilidConfigHTTPS {
pub enabled: bool, pub enabled: bool,
pub listen_address: String, pub listen_address: String,
pub path: String, pub path: String,
#[tsify(optional)] #[cfg_attr(target_arch = "wasm32", tsify(optional))]
pub url: Option<String>, // Fixed URL is not optional for TLS-based protocols and is dynamically validated pub url: Option<String>, // Fixed URL is not optional for TLS-based protocols and is dynamically validated
} }
@ -35,12 +36,13 @@ pub struct VeilidConfigHTTPS {
/// url: 'https://localhost:5150' /// url: 'https://localhost:5150'
/// ``` /// ```
/// ///
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify)] #[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub struct VeilidConfigHTTP { pub struct VeilidConfigHTTP {
pub enabled: bool, pub enabled: bool,
pub listen_address: String, pub listen_address: String,
pub path: String, pub path: String,
#[tsify(optional)] #[cfg_attr(target_arch = "wasm32", tsify(optional))]
pub url: Option<String>, pub url: Option<String>,
} }
@ -50,7 +52,8 @@ pub struct VeilidConfigHTTP {
/// ///
/// To be implemented... /// To be implemented...
/// ///
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify)] #[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub struct VeilidConfigApplication { pub struct VeilidConfigApplication {
pub https: VeilidConfigHTTPS, pub https: VeilidConfigHTTPS,
pub http: VeilidConfigHTTP, pub http: VeilidConfigHTTP,
@ -66,12 +69,13 @@ pub struct VeilidConfigApplication {
/// public_address: '' /// public_address: ''
/// ``` /// ```
/// ///
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify)] #[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub struct VeilidConfigUDP { pub struct VeilidConfigUDP {
pub enabled: bool, pub enabled: bool,
pub socket_pool_size: u32, pub socket_pool_size: u32,
pub listen_address: String, pub listen_address: String,
#[tsify(optional)] #[cfg_attr(target_arch = "wasm32", tsify(optional))]
pub public_address: Option<String>, pub public_address: Option<String>,
} }
@ -85,13 +89,14 @@ pub struct VeilidConfigUDP {
/// listen_address: ':5150' /// listen_address: ':5150'
/// public_address: '' /// public_address: ''
/// ///
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify)] #[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub struct VeilidConfigTCP { pub struct VeilidConfigTCP {
pub connect: bool, pub connect: bool,
pub listen: bool, pub listen: bool,
pub max_connections: u32, pub max_connections: u32,
pub listen_address: String, pub listen_address: String,
#[tsify(optional)] #[cfg_attr(target_arch = "wasm32", tsify(optional))]
pub public_address: Option<String>, pub public_address: Option<String>,
} }
@ -106,7 +111,8 @@ pub struct VeilidConfigTCP {
/// path: 'ws' /// path: 'ws'
/// url: 'ws://localhost:5150/ws' /// url: 'ws://localhost:5150/ws'
/// ///
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify)] #[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub struct VeilidConfigWS { pub struct VeilidConfigWS {
pub connect: bool, pub connect: bool,
@ -114,7 +120,7 @@ pub struct VeilidConfigWS {
pub max_connections: u32, pub max_connections: u32,
pub listen_address: String, pub listen_address: String,
pub path: String, pub path: String,
#[tsify(optional)] #[cfg_attr(target_arch = "wasm32", tsify(optional))]
pub url: Option<String>, pub url: Option<String>,
} }
@ -129,7 +135,8 @@ pub struct VeilidConfigWS {
/// path: 'ws' /// path: 'ws'
/// url: '' /// url: ''
/// ///
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify)] #[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub struct VeilidConfigWSS { pub struct VeilidConfigWSS {
pub connect: bool, pub connect: bool,
@ -137,7 +144,7 @@ pub struct VeilidConfigWSS {
pub max_connections: u32, pub max_connections: u32,
pub listen_address: String, pub listen_address: String,
pub path: String, pub path: String,
#[tsify(optional)] #[cfg_attr(target_arch = "wasm32", tsify(optional))]
pub url: Option<String>, // Fixed URL is not optional for TLS-based protocols and is dynamically validated pub url: Option<String>, // Fixed URL is not optional for TLS-based protocols and is dynamically validated
} }
@ -148,7 +155,8 @@ pub struct VeilidConfigWSS {
/// All protocols are available by default, and the Veilid node will /// All protocols are available by default, and the Veilid node will
/// sort out which protocol is used for each peer connection. /// sort out which protocol is used for each peer connection.
/// ///
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify)] #[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub struct VeilidConfigProtocol { pub struct VeilidConfigProtocol {
pub udp: VeilidConfigUDP, pub udp: VeilidConfigUDP,
@ -165,7 +173,8 @@ pub struct VeilidConfigProtocol {
/// private_key_path: /path/to/private/key /// private_key_path: /path/to/private/key
/// connection_initial_timeout_ms: 2000 /// connection_initial_timeout_ms: 2000
/// ///
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify)] #[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub struct VeilidConfigTLS { pub struct VeilidConfigTLS {
pub certificate_path: String, pub certificate_path: String,
pub private_key_path: String, pub private_key_path: String,
@ -174,7 +183,8 @@ pub struct VeilidConfigTLS {
/// Configure the Distributed Hash Table (DHT) /// Configure the Distributed Hash Table (DHT)
/// ///
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify)] #[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub struct VeilidConfigDHT { pub struct VeilidConfigDHT {
pub max_find_node_count: u32, pub max_find_node_count: u32,
pub resolve_node_timeout_ms: u32, pub resolve_node_timeout_ms: u32,
@ -199,13 +209,14 @@ pub struct VeilidConfigDHT {
/// Configure RPC /// Configure RPC
/// ///
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify)] #[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub struct VeilidConfigRPC { pub struct VeilidConfigRPC {
pub concurrency: u32, pub concurrency: u32,
pub queue_size: u32, pub queue_size: u32,
#[tsify(optional)] #[cfg_attr(target_arch = "wasm32", tsify(optional))]
pub max_timestamp_behind_ms: Option<u32>, pub max_timestamp_behind_ms: Option<u32>,
#[tsify(optional)] #[cfg_attr(target_arch = "wasm32", tsify(optional))]
pub max_timestamp_ahead_ms: Option<u32>, pub max_timestamp_ahead_ms: Option<u32>,
pub timeout_ms: u32, pub timeout_ms: u32,
pub max_route_hop_count: u8, pub max_route_hop_count: u8,
@ -214,7 +225,8 @@ pub struct VeilidConfigRPC {
/// Configure the network routing table /// Configure the network routing table
/// ///
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify)] #[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub struct VeilidConfigRoutingTable { pub struct VeilidConfigRoutingTable {
#[schemars(with = "Vec<String>")] #[schemars(with = "Vec<String>")]
pub node_id: TypedKeyGroup, pub node_id: TypedKeyGroup,
@ -230,7 +242,8 @@ pub struct VeilidConfigRoutingTable {
// xxx pub enable_local_network: bool, // xxx pub enable_local_network: bool,
} }
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify)] #[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub struct VeilidConfigNetwork { pub struct VeilidConfigNetwork {
pub connection_initial_timeout_ms: u32, pub connection_initial_timeout_ms: u32,
pub connection_inactivity_timeout_ms: u32, pub connection_inactivity_timeout_ms: u32,
@ -241,7 +254,7 @@ pub struct VeilidConfigNetwork {
pub client_whitelist_timeout_ms: u32, pub client_whitelist_timeout_ms: u32,
pub reverse_connection_receipt_time_ms: u32, pub reverse_connection_receipt_time_ms: u32,
pub hole_punch_receipt_time_ms: u32, pub hole_punch_receipt_time_ms: u32,
#[tsify(optional)] #[cfg_attr(target_arch = "wasm32", tsify(optional))]
pub network_key_password: Option<String>, pub network_key_password: Option<String>,
pub routing_table: VeilidConfigRoutingTable, pub routing_table: VeilidConfigRoutingTable,
pub rpc: VeilidConfigRPC, pub rpc: VeilidConfigRPC,
@ -254,36 +267,41 @@ pub struct VeilidConfigNetwork {
pub protocol: VeilidConfigProtocol, pub protocol: VeilidConfigProtocol,
} }
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify)] #[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub struct VeilidConfigTableStore { pub struct VeilidConfigTableStore {
pub directory: String, pub directory: String,
pub delete: bool, pub delete: bool,
} }
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify)] #[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub struct VeilidConfigBlockStore { pub struct VeilidConfigBlockStore {
pub directory: String, pub directory: String,
pub delete: bool, pub delete: bool,
} }
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify)] #[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub struct VeilidConfigProtectedStore { pub struct VeilidConfigProtectedStore {
pub allow_insecure_fallback: bool, pub allow_insecure_fallback: bool,
pub always_use_insecure_storage: bool, pub always_use_insecure_storage: bool,
pub directory: String, pub directory: String,
pub delete: bool, pub delete: bool,
pub device_encryption_key_password: String, pub device_encryption_key_password: String,
#[tsify(optional)] #[cfg_attr(target_arch = "wasm32", tsify(optional))]
pub new_device_encryption_key_password: Option<String>, pub new_device_encryption_key_password: Option<String>,
} }
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify)] #[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub struct VeilidConfigCapabilities { pub struct VeilidConfigCapabilities {
pub disable: Vec<FourCC>, pub disable: Vec<FourCC>,
} }
#[derive(Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize, JsonSchema, Tsify)] #[derive(Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize, JsonSchema)]
#[tsify(namespace, from_wasm_abi)] #[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(target_arch = "wasm32", tsify(namespace, from_wasm_abi))]
pub enum VeilidConfigLogLevel { pub enum VeilidConfigLogLevel {
Off, Off,
Error, Error,
@ -370,7 +388,8 @@ impl fmt::Display for VeilidConfigLogLevel {
} }
} }
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify)] #[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub struct VeilidConfigInner { pub struct VeilidConfigInner {
pub program_name: String, pub program_name: String,
pub namespace: String, pub namespace: String,

View File

@ -0,0 +1,21 @@
cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
pub use tsify::*;
pub use wasm_bindgen::prelude::*;
macro_rules! from_impl_to_jsvalue {
($name: ident) => {
impl From<$name> for JsValue {
fn from(value: $name) -> Self {
serde_wasm_bindgen::to_value(&value).unwrap()
}
}
}
}
} else {
macro_rules! from_impl_to_jsvalue {
($name: ident) => {}
}
}
}
pub(crate) use from_impl_to_jsvalue;

View File

@ -115,7 +115,8 @@ where
///////////////////////////////////////// /////////////////////////////////////////
// WASM-specific // WASM-specific
#[derive(Debug, Deserialize, Serialize, Tsify)] #[derive(Debug, Deserialize, Serialize)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub struct VeilidWASMConfigLoggingPerformance { pub struct VeilidWASMConfigLoggingPerformance {
pub enabled: bool, pub enabled: bool,
pub level: veilid_core::VeilidConfigLogLevel, pub level: veilid_core::VeilidConfigLogLevel,
@ -123,25 +124,29 @@ pub struct VeilidWASMConfigLoggingPerformance {
pub logs_in_console: bool, pub logs_in_console: bool,
} }
#[derive(Debug, Deserialize, Serialize, Tsify)] #[derive(Debug, Deserialize, Serialize)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub struct VeilidWASMConfigLoggingAPI { pub struct VeilidWASMConfigLoggingAPI {
pub enabled: bool, pub enabled: bool,
pub level: veilid_core::VeilidConfigLogLevel, pub level: veilid_core::VeilidConfigLogLevel,
} }
#[derive(Debug, Deserialize, Serialize, Tsify)] #[derive(Debug, Deserialize, Serialize)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub struct VeilidWASMConfigLogging { pub struct VeilidWASMConfigLogging {
pub performance: VeilidWASMConfigLoggingPerformance, pub performance: VeilidWASMConfigLoggingPerformance,
pub api: VeilidWASMConfigLoggingAPI, pub api: VeilidWASMConfigLoggingAPI,
} }
#[derive(Debug, Deserialize, Serialize, Tsify)] #[derive(Debug, Deserialize, Serialize)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[tsify(from_wasm_abi)] #[tsify(from_wasm_abi)]
pub struct VeilidWASMConfig { pub struct VeilidWASMConfig {
pub logging: VeilidWASMConfigLogging, pub logging: VeilidWASMConfigLogging,
} }
#[derive(Debug, Deserialize, Serialize, Tsify)] #[derive(Debug, Deserialize, Serialize)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub struct VeilidRouteBlob { pub struct VeilidRouteBlob {
pub route_id: veilid_core::RouteId, pub route_id: veilid_core::RouteId,
#[serde(with = "veilid_core::as_human_base64")] #[serde(with = "veilid_core::as_human_base64")]
@ -1463,7 +1468,8 @@ pub fn veilid_version_string() -> String {
veilid_core::veilid_version_string() veilid_core::veilid_version_string()
} }
#[derive(Serialize, Tsify)] #[derive(Serialize)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[tsify(into_wasm_abi)] #[tsify(into_wasm_abi)]
pub struct VeilidVersion { pub struct VeilidVersion {
pub major: u32, pub major: u32,