Setup for TypeScript type gen for WASM using Tsify
- Includes breaking changes to the WASM API surface, since it now accepts objects instead of stringified JSON.
This commit is contained in:
@@ -105,9 +105,21 @@ macro_rules! apibail_already_initialized {
|
||||
}
|
||||
|
||||
#[derive(
|
||||
ThisError, Clone, Debug, PartialOrd, PartialEq, Eq, Ord, Serialize, Deserialize, JsonSchema,
|
||||
ThisError,
|
||||
Clone,
|
||||
Debug,
|
||||
PartialOrd,
|
||||
PartialEq,
|
||||
Eq,
|
||||
Ord,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
JsonSchema,
|
||||
Tsify,
|
||||
TsifyAsync,
|
||||
)]
|
||||
#[serde(tag = "kind")]
|
||||
#[tsify(into_wasm_abi)]
|
||||
pub enum VeilidAPIError {
|
||||
#[error("Not initialized")]
|
||||
NotInitialized,
|
||||
@@ -213,6 +225,7 @@ impl VeilidAPIError {
|
||||
}
|
||||
}
|
||||
|
||||
#[declare]
|
||||
pub type VeilidAPIResult<T> = Result<T, VeilidAPIError>;
|
||||
|
||||
impl From<std::io::Error> for VeilidAPIError {
|
||||
|
||||
@@ -6,7 +6,18 @@ use super::*;
|
||||
/// Supports serializing to string for JSON as well, since JSON can't handle 64-bit numbers to Javascript
|
||||
|
||||
#[derive(
|
||||
Clone, Default, PartialEq, Eq, PartialOrd, Ord, Copy, Hash, Serialize, Deserialize, JsonSchema,
|
||||
Clone,
|
||||
Default,
|
||||
PartialEq,
|
||||
Eq,
|
||||
PartialOrd,
|
||||
Ord,
|
||||
Copy,
|
||||
Hash,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
JsonSchema,
|
||||
Tsify,
|
||||
)]
|
||||
#[repr(C, align(8))]
|
||||
#[serde(transparent)]
|
||||
@@ -117,13 +128,17 @@ impl AlignedU64 {
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// Microseconds since epoch
|
||||
#[declare]
|
||||
pub type Timestamp = AlignedU64;
|
||||
pub fn get_aligned_timestamp() -> Timestamp {
|
||||
get_timestamp().into()
|
||||
}
|
||||
/// Microseconds duration
|
||||
#[declare]
|
||||
pub type TimestampDuration = AlignedU64;
|
||||
/// Request/Response matching id
|
||||
#[declare]
|
||||
pub type OperationId = AlignedU64;
|
||||
/// Number of bytes
|
||||
#[declare]
|
||||
pub type ByteCount = AlignedU64;
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
use super::*;
|
||||
|
||||
/// Direct statement blob passed to hosting application for processing
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify)]
|
||||
pub struct VeilidAppMessage {
|
||||
#[serde(with = "as_human_opt_string")]
|
||||
#[schemars(with = "Option<String>")]
|
||||
#[tsify(optional)]
|
||||
sender: Option<TypedKey>,
|
||||
|
||||
#[serde(with = "as_human_base64")]
|
||||
@@ -29,10 +30,11 @@ impl VeilidAppMessage {
|
||||
}
|
||||
|
||||
/// Direct question blob passed to hosting application for processing to send an eventual AppReply
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify)]
|
||||
pub struct VeilidAppCall {
|
||||
#[serde(with = "as_human_opt_string")]
|
||||
#[schemars(with = "Option<String>")]
|
||||
#[tsify(optional)]
|
||||
sender: Option<TypedKey>,
|
||||
|
||||
#[serde(with = "as_human_base64")]
|
||||
|
||||
@@ -11,6 +11,8 @@ pub use value_data::*;
|
||||
pub use value_subkey_range_set::*;
|
||||
|
||||
/// Value subkey
|
||||
#[declare]
|
||||
pub type ValueSubkey = u32;
|
||||
/// Value sequence number
|
||||
#[declare]
|
||||
pub type ValueSeqNum = u32;
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
use super::*;
|
||||
use veilid_api::VeilidAPIResult;
|
||||
|
||||
#[derive(Clone, Default, PartialOrd, PartialEq, Eq, Ord, Serialize, Deserialize, JsonSchema)]
|
||||
#[derive(
|
||||
Clone, Default, PartialOrd, PartialEq, Eq, Ord, Serialize, Deserialize, JsonSchema, Tsify,
|
||||
)]
|
||||
pub struct ValueData {
|
||||
/// An increasing sequence number to time-order the DHT record changes
|
||||
seq: ValueSeqNum,
|
||||
|
||||
@@ -2,7 +2,18 @@ use super::*;
|
||||
|
||||
/// FOURCC code
|
||||
#[derive(
|
||||
Copy, Default, Clone, Hash, PartialOrd, Ord, PartialEq, Eq, Serialize, Deserialize, JsonSchema,
|
||||
Copy,
|
||||
Default,
|
||||
Clone,
|
||||
Hash,
|
||||
PartialOrd,
|
||||
Ord,
|
||||
PartialEq,
|
||||
Eq,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
JsonSchema,
|
||||
Tsify,
|
||||
)]
|
||||
#[serde(try_from = "String")]
|
||||
#[serde(into = "String")]
|
||||
|
||||
@@ -2,8 +2,9 @@ use super::*;
|
||||
|
||||
/// Log level for VeilidCore
|
||||
#[derive(
|
||||
Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Copy, Serialize, Deserialize, JsonSchema,
|
||||
Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Copy, Serialize, Deserialize, JsonSchema, Tsify,
|
||||
)]
|
||||
#[tsify(namespace)]
|
||||
pub enum VeilidLogLevel {
|
||||
Error = 1,
|
||||
Warn = 2,
|
||||
@@ -79,9 +80,10 @@ impl fmt::Display for VeilidLogLevel {
|
||||
}
|
||||
}
|
||||
/// A VeilidCore log message with optional backtrace
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify)]
|
||||
pub struct VeilidLog {
|
||||
pub log_level: VeilidLogLevel,
|
||||
pub message: String,
|
||||
#[tsify(optional)]
|
||||
pub backtrace: Option<String>,
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
use super::*;
|
||||
|
||||
/// Attachment abstraction for network 'signal strength'
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize, JsonSchema)]
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize, JsonSchema, Tsify)]
|
||||
#[tsify(namespace, from_wasm_abi, into_wasm_abi)]
|
||||
pub enum AttachmentState {
|
||||
Detached = 0,
|
||||
Attaching = 1,
|
||||
@@ -47,14 +48,14 @@ impl TryFrom<String> for AttachmentState {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify)]
|
||||
pub struct VeilidStateAttachment {
|
||||
pub state: AttachmentState,
|
||||
pub public_internet_ready: bool,
|
||||
pub local_network_ready: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify)]
|
||||
pub struct PeerTableData {
|
||||
#[schemars(with = "Vec<String>")]
|
||||
pub node_ids: Vec<TypedKey>,
|
||||
@@ -62,7 +63,7 @@ pub struct PeerTableData {
|
||||
pub peer_stats: PeerStats,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify)]
|
||||
pub struct VeilidStateNetwork {
|
||||
pub started: bool,
|
||||
pub bps_down: ByteCount,
|
||||
@@ -70,7 +71,7 @@ pub struct VeilidStateNetwork {
|
||||
pub peers: Vec<PeerTableData>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify)]
|
||||
pub struct VeilidRouteChange {
|
||||
#[schemars(with = "Vec<String>")]
|
||||
pub dead_routes: Vec<RouteId>,
|
||||
@@ -78,12 +79,12 @@ pub struct VeilidRouteChange {
|
||||
pub dead_remote_routes: Vec<RouteId>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify)]
|
||||
pub struct VeilidStateConfig {
|
||||
pub config: VeilidConfigInner,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify)]
|
||||
pub struct VeilidValueChange {
|
||||
#[schemars(with = "String")]
|
||||
pub key: TypedKey,
|
||||
@@ -92,8 +93,9 @@ pub struct VeilidValueChange {
|
||||
pub value: ValueData,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify, TsifyAsync)]
|
||||
#[serde(tag = "kind")]
|
||||
#[tsify(into_wasm_abi)]
|
||||
pub enum VeilidUpdate {
|
||||
Log(VeilidLog),
|
||||
AppMessage(VeilidAppMessage),
|
||||
@@ -106,7 +108,8 @@ pub enum VeilidUpdate {
|
||||
Shutdown,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Tsify, TsifyAsync)]
|
||||
#[tsify(into_wasm_abi)]
|
||||
pub struct VeilidState {
|
||||
pub attachment: VeilidStateAttachment,
|
||||
pub network: VeilidStateNetwork,
|
||||
|
||||
Reference in New Issue
Block a user