|
|
|
|
@@ -1,5 +1,7 @@
|
|
|
|
|
// wasm-bindgen and clippy don't play well together yet
|
|
|
|
|
#![allow(clippy::all)]
|
|
|
|
|
#![deny(clippy::all)]
|
|
|
|
|
#![allow(clippy::comparison_chain, clippy::upper_case_acronyms)]
|
|
|
|
|
#![deny(unused_must_use)]
|
|
|
|
|
#![cfg(target_arch = "wasm32")]
|
|
|
|
|
#![no_std]
|
|
|
|
|
|
|
|
|
|
@@ -77,7 +79,7 @@ pub fn unmarshall(b64: String) -> APIResult<Vec<u8>> {
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn marshall(data: &Vec<u8>) -> String {
|
|
|
|
|
pub fn marshall(data: &[u8]) -> String {
|
|
|
|
|
data_encoding::BASE64URL_NOPAD.encode(data)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -114,7 +116,7 @@ where
|
|
|
|
|
F: Future<Output = APIResult<T>> + 'static,
|
|
|
|
|
T: Serialize + Debug + 'static,
|
|
|
|
|
{
|
|
|
|
|
future_to_promise(future.map(|res| res.map(|v| to_json(v)).map_err(|e| to_json(e))))
|
|
|
|
|
future_to_promise(future.map(|res| res.map(|v| to_json(v)).map_err(to_json)))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn wrap_api_future_plain<F, T>(future: F) -> Promise
|
|
|
|
|
@@ -123,14 +125,14 @@ where
|
|
|
|
|
JsValue: From<T>,
|
|
|
|
|
T: 'static,
|
|
|
|
|
{
|
|
|
|
|
future_to_promise(future.map(|res| res.map(|v| to_jsvalue(v)).map_err(|e| to_json(e))))
|
|
|
|
|
future_to_promise(future.map(|res| res.map(|v| to_jsvalue(v)).map_err(to_json)))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn wrap_api_future_void<F>(future: F) -> Promise
|
|
|
|
|
where
|
|
|
|
|
F: Future<Output = APIResult<()>> + 'static,
|
|
|
|
|
{
|
|
|
|
|
future_to_promise(future.map(|res| res.map(|_| JsValue::UNDEFINED).map_err(|e| to_json(e))))
|
|
|
|
|
future_to_promise(future.map(|res| res.map(|_| JsValue::UNDEFINED).map_err(to_json)))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////
|
|
|
|
|
@@ -338,7 +340,7 @@ pub fn release_routing_context(id: u32) -> i32 {
|
|
|
|
|
if rc.remove(&id).is_none() {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[wasm_bindgen()]
|
|
|
|
|
@@ -350,8 +352,7 @@ pub fn routing_context_with_privacy(id: u32) -> u32 {
|
|
|
|
|
let Ok(routing_context) = routing_context.clone().with_privacy() else {
|
|
|
|
|
return 0;
|
|
|
|
|
};
|
|
|
|
|
let new_id = add_routing_context(routing_context);
|
|
|
|
|
new_id
|
|
|
|
|
add_routing_context(routing_context)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[wasm_bindgen()]
|
|
|
|
|
@@ -363,11 +364,13 @@ pub fn routing_context_with_custom_privacy(id: u32, safety_selection: String) ->
|
|
|
|
|
let Some(routing_context) = rc.get(&id) else {
|
|
|
|
|
return 0;
|
|
|
|
|
};
|
|
|
|
|
let Ok(routing_context) = routing_context.clone().with_custom_privacy(safety_selection) else {
|
|
|
|
|
let Ok(routing_context) = routing_context
|
|
|
|
|
.clone()
|
|
|
|
|
.with_custom_privacy(safety_selection)
|
|
|
|
|
else {
|
|
|
|
|
return 0;
|
|
|
|
|
};
|
|
|
|
|
let new_id = add_routing_context(routing_context);
|
|
|
|
|
new_id
|
|
|
|
|
add_routing_context(routing_context)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[wasm_bindgen()]
|
|
|
|
|
@@ -379,8 +382,7 @@ pub fn routing_context_with_sequencing(id: u32, sequencing: String) -> u32 {
|
|
|
|
|
return 0;
|
|
|
|
|
};
|
|
|
|
|
let routing_context = routing_context.clone().with_sequencing(sequencing);
|
|
|
|
|
let new_id = add_routing_context(routing_context);
|
|
|
|
|
new_id
|
|
|
|
|
add_routing_context(routing_context)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[wasm_bindgen()]
|
|
|
|
|
@@ -392,7 +394,11 @@ pub fn routing_context_app_call(id: u32, target_string: String, request: String)
|
|
|
|
|
let routing_context = {
|
|
|
|
|
let rc = (*ROUTING_CONTEXTS).borrow();
|
|
|
|
|
let Some(routing_context) = rc.get(&id) else {
|
|
|
|
|
return APIResult::Err(veilid_core::VeilidAPIError::invalid_argument("routing_context_app_call", "id", id));
|
|
|
|
|
return APIResult::Err(veilid_core::VeilidAPIError::invalid_argument(
|
|
|
|
|
"routing_context_app_call",
|
|
|
|
|
"id",
|
|
|
|
|
id,
|
|
|
|
|
));
|
|
|
|
|
};
|
|
|
|
|
routing_context.clone()
|
|
|
|
|
};
|
|
|
|
|
@@ -414,7 +420,11 @@ pub fn routing_context_app_message(id: u32, target_string: String, message: Stri
|
|
|
|
|
let routing_context = {
|
|
|
|
|
let rc = (*ROUTING_CONTEXTS).borrow();
|
|
|
|
|
let Some(routing_context) = rc.get(&id) else {
|
|
|
|
|
return APIResult::Err(veilid_core::VeilidAPIError::invalid_argument("routing_context_app_message", "id", id));
|
|
|
|
|
return APIResult::Err(veilid_core::VeilidAPIError::invalid_argument(
|
|
|
|
|
"routing_context_app_message",
|
|
|
|
|
"id",
|
|
|
|
|
id,
|
|
|
|
|
));
|
|
|
|
|
};
|
|
|
|
|
routing_context.clone()
|
|
|
|
|
};
|
|
|
|
|
@@ -439,7 +449,11 @@ pub fn routing_context_create_dht_record(id: u32, schema: String, kind: u32) ->
|
|
|
|
|
let routing_context = {
|
|
|
|
|
let rc = (*ROUTING_CONTEXTS).borrow();
|
|
|
|
|
let Some(routing_context) = rc.get(&id) else {
|
|
|
|
|
return APIResult::Err(veilid_core::VeilidAPIError::invalid_argument("routing_context_create_dht_record", "id", id));
|
|
|
|
|
return APIResult::Err(veilid_core::VeilidAPIError::invalid_argument(
|
|
|
|
|
"routing_context_create_dht_record",
|
|
|
|
|
"id",
|
|
|
|
|
id,
|
|
|
|
|
));
|
|
|
|
|
};
|
|
|
|
|
routing_context.clone()
|
|
|
|
|
};
|
|
|
|
|
@@ -460,7 +474,11 @@ pub fn routing_context_open_dht_record(id: u32, key: String, writer: Option<Stri
|
|
|
|
|
let routing_context = {
|
|
|
|
|
let rc = (*ROUTING_CONTEXTS).borrow();
|
|
|
|
|
let Some(routing_context) = rc.get(&id) else {
|
|
|
|
|
return APIResult::Err(veilid_core::VeilidAPIError::invalid_argument("routing_context_open_dht_record", "id", id));
|
|
|
|
|
return APIResult::Err(veilid_core::VeilidAPIError::invalid_argument(
|
|
|
|
|
"routing_context_open_dht_record",
|
|
|
|
|
"id",
|
|
|
|
|
id,
|
|
|
|
|
));
|
|
|
|
|
};
|
|
|
|
|
routing_context.clone()
|
|
|
|
|
};
|
|
|
|
|
@@ -476,7 +494,11 @@ pub fn routing_context_close_dht_record(id: u32, key: String) -> Promise {
|
|
|
|
|
let routing_context = {
|
|
|
|
|
let rc = (*ROUTING_CONTEXTS).borrow();
|
|
|
|
|
let Some(routing_context) = rc.get(&id) else {
|
|
|
|
|
return APIResult::Err(veilid_core::VeilidAPIError::invalid_argument("routing_context_close_dht_record", "id", id));
|
|
|
|
|
return APIResult::Err(veilid_core::VeilidAPIError::invalid_argument(
|
|
|
|
|
"routing_context_close_dht_record",
|
|
|
|
|
"id",
|
|
|
|
|
id,
|
|
|
|
|
));
|
|
|
|
|
};
|
|
|
|
|
routing_context.clone()
|
|
|
|
|
};
|
|
|
|
|
@@ -492,7 +514,11 @@ pub fn routing_context_delete_dht_record(id: u32, key: String) -> Promise {
|
|
|
|
|
let routing_context = {
|
|
|
|
|
let rc = (*ROUTING_CONTEXTS).borrow();
|
|
|
|
|
let Some(routing_context) = rc.get(&id) else {
|
|
|
|
|
return APIResult::Err(veilid_core::VeilidAPIError::invalid_argument("routing_context_delete_dht_record", "id", id));
|
|
|
|
|
return APIResult::Err(veilid_core::VeilidAPIError::invalid_argument(
|
|
|
|
|
"routing_context_delete_dht_record",
|
|
|
|
|
"id",
|
|
|
|
|
id,
|
|
|
|
|
));
|
|
|
|
|
};
|
|
|
|
|
routing_context.clone()
|
|
|
|
|
};
|
|
|
|
|
@@ -513,7 +539,11 @@ pub fn routing_context_get_dht_value(
|
|
|
|
|
let routing_context = {
|
|
|
|
|
let rc = (*ROUTING_CONTEXTS).borrow();
|
|
|
|
|
let Some(routing_context) = rc.get(&id) else {
|
|
|
|
|
return APIResult::Err(veilid_core::VeilidAPIError::invalid_argument("routing_context_get_dht_value", "id", id));
|
|
|
|
|
return APIResult::Err(veilid_core::VeilidAPIError::invalid_argument(
|
|
|
|
|
"routing_context_get_dht_value",
|
|
|
|
|
"id",
|
|
|
|
|
id,
|
|
|
|
|
));
|
|
|
|
|
};
|
|
|
|
|
routing_context.clone()
|
|
|
|
|
};
|
|
|
|
|
@@ -528,14 +558,18 @@ pub fn routing_context_get_dht_value(
|
|
|
|
|
pub fn routing_context_set_dht_value(id: u32, key: String, subkey: u32, data: String) -> Promise {
|
|
|
|
|
let key: veilid_core::TypedKey = veilid_core::deserialize_json(&key).unwrap();
|
|
|
|
|
let data: Vec<u8> = data_encoding::BASE64URL_NOPAD
|
|
|
|
|
.decode(&data.as_bytes())
|
|
|
|
|
.decode(data.as_bytes())
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
wrap_api_future_json(async move {
|
|
|
|
|
let routing_context = {
|
|
|
|
|
let rc = (*ROUTING_CONTEXTS).borrow();
|
|
|
|
|
let Some(routing_context) = rc.get(&id) else {
|
|
|
|
|
return APIResult::Err(veilid_core::VeilidAPIError::invalid_argument("routing_context_set_dht_value", "id", id));
|
|
|
|
|
return APIResult::Err(veilid_core::VeilidAPIError::invalid_argument(
|
|
|
|
|
"routing_context_set_dht_value",
|
|
|
|
|
"id",
|
|
|
|
|
id,
|
|
|
|
|
));
|
|
|
|
|
};
|
|
|
|
|
routing_context.clone()
|
|
|
|
|
};
|
|
|
|
|
@@ -561,7 +595,11 @@ pub fn routing_context_watch_dht_values(
|
|
|
|
|
let routing_context = {
|
|
|
|
|
let rc = (*ROUTING_CONTEXTS).borrow();
|
|
|
|
|
let Some(routing_context) = rc.get(&id) else {
|
|
|
|
|
return APIResult::Err(veilid_core::VeilidAPIError::invalid_argument("routing_context_watch_dht_values", "id", id));
|
|
|
|
|
return APIResult::Err(veilid_core::VeilidAPIError::invalid_argument(
|
|
|
|
|
"routing_context_watch_dht_values",
|
|
|
|
|
"id",
|
|
|
|
|
id,
|
|
|
|
|
));
|
|
|
|
|
};
|
|
|
|
|
routing_context.clone()
|
|
|
|
|
};
|
|
|
|
|
@@ -582,7 +620,11 @@ pub fn routing_context_cancel_dht_watch(id: u32, key: String, subkeys: String) -
|
|
|
|
|
let routing_context = {
|
|
|
|
|
let rc = (*ROUTING_CONTEXTS).borrow();
|
|
|
|
|
let Some(routing_context) = rc.get(&id) else {
|
|
|
|
|
return APIResult::Err(veilid_core::VeilidAPIError::invalid_argument("routing_context_cancel_dht_watch", "id", id));
|
|
|
|
|
return APIResult::Err(veilid_core::VeilidAPIError::invalid_argument(
|
|
|
|
|
"routing_context_cancel_dht_watch",
|
|
|
|
|
"id",
|
|
|
|
|
id,
|
|
|
|
|
));
|
|
|
|
|
};
|
|
|
|
|
routing_context.clone()
|
|
|
|
|
};
|
|
|
|
|
@@ -696,7 +738,7 @@ pub fn release_table_db(id: u32) -> i32 {
|
|
|
|
|
if tdbs.remove(&id).is_none() {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[wasm_bindgen()]
|
|
|
|
|
@@ -721,7 +763,7 @@ pub fn table_db_get_column_count(id: u32) -> u32 {
|
|
|
|
|
let Ok(cc) = table_db.clone().get_column_count() else {
|
|
|
|
|
return 0;
|
|
|
|
|
};
|
|
|
|
|
return cc;
|
|
|
|
|
cc
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[wasm_bindgen()]
|
|
|
|
|
@@ -730,7 +772,11 @@ pub fn table_db_get_keys(id: u32, col: u32) -> Promise {
|
|
|
|
|
let table_db = {
|
|
|
|
|
let table_dbs = (*TABLE_DBS).borrow();
|
|
|
|
|
let Some(table_db) = table_dbs.get(&id) else {
|
|
|
|
|
return APIResult::Err(veilid_core::VeilidAPIError::invalid_argument("table_db_store", "id", id));
|
|
|
|
|
return APIResult::Err(veilid_core::VeilidAPIError::invalid_argument(
|
|
|
|
|
"table_db_store",
|
|
|
|
|
"id",
|
|
|
|
|
id,
|
|
|
|
|
));
|
|
|
|
|
};
|
|
|
|
|
table_db.clone()
|
|
|
|
|
};
|
|
|
|
|
@@ -761,8 +807,7 @@ pub fn table_db_transact(id: u32) -> u32 {
|
|
|
|
|
return 0;
|
|
|
|
|
};
|
|
|
|
|
let tdbt = table_db.clone().transact();
|
|
|
|
|
let tdbtid = add_table_db_transaction(tdbt);
|
|
|
|
|
return tdbtid;
|
|
|
|
|
add_table_db_transaction(tdbt)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[wasm_bindgen()]
|
|
|
|
|
@@ -771,7 +816,7 @@ pub fn release_table_db_transaction(id: u32) -> i32 {
|
|
|
|
|
if tdbts.remove(&id).is_none() {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[wasm_bindgen()]
|
|
|
|
|
@@ -780,7 +825,11 @@ pub fn table_db_transaction_commit(id: u32) -> Promise {
|
|
|
|
|
let tdbt = {
|
|
|
|
|
let tdbts = (*TABLE_DB_TRANSACTIONS).borrow();
|
|
|
|
|
let Some(tdbt) = tdbts.get(&id) else {
|
|
|
|
|
return APIResult::Err(veilid_core::VeilidAPIError::invalid_argument("table_db_transaction_commit", "id", id));
|
|
|
|
|
return APIResult::Err(veilid_core::VeilidAPIError::invalid_argument(
|
|
|
|
|
"table_db_transaction_commit",
|
|
|
|
|
"id",
|
|
|
|
|
id,
|
|
|
|
|
));
|
|
|
|
|
};
|
|
|
|
|
tdbt.clone()
|
|
|
|
|
};
|
|
|
|
|
@@ -796,7 +845,11 @@ pub fn table_db_transaction_rollback(id: u32) -> Promise {
|
|
|
|
|
let tdbt = {
|
|
|
|
|
let tdbts = (*TABLE_DB_TRANSACTIONS).borrow();
|
|
|
|
|
let Some(tdbt) = tdbts.get(&id) else {
|
|
|
|
|
return APIResult::Err(veilid_core::VeilidAPIError::invalid_argument("table_db_transaction_rollback", "id", id));
|
|
|
|
|
return APIResult::Err(veilid_core::VeilidAPIError::invalid_argument(
|
|
|
|
|
"table_db_transaction_rollback",
|
|
|
|
|
"id",
|
|
|
|
|
id,
|
|
|
|
|
));
|
|
|
|
|
};
|
|
|
|
|
tdbt.clone()
|
|
|
|
|
};
|
|
|
|
|
@@ -818,7 +871,11 @@ pub fn table_db_transaction_store(id: u32, col: u32, key: String, value: String)
|
|
|
|
|
let tdbt = {
|
|
|
|
|
let tdbts = (*TABLE_DB_TRANSACTIONS).borrow();
|
|
|
|
|
let Some(tdbt) = tdbts.get(&id) else {
|
|
|
|
|
return APIResult::Err(veilid_core::VeilidAPIError::invalid_argument("table_db_transaction_store", "id", id));
|
|
|
|
|
return APIResult::Err(veilid_core::VeilidAPIError::invalid_argument(
|
|
|
|
|
"table_db_transaction_store",
|
|
|
|
|
"id",
|
|
|
|
|
id,
|
|
|
|
|
));
|
|
|
|
|
};
|
|
|
|
|
tdbt.clone()
|
|
|
|
|
};
|
|
|
|
|
@@ -837,7 +894,11 @@ pub fn table_db_transaction_delete(id: u32, col: u32, key: String) -> Promise {
|
|
|
|
|
let tdbt = {
|
|
|
|
|
let tdbts = (*TABLE_DB_TRANSACTIONS).borrow();
|
|
|
|
|
let Some(tdbt) = tdbts.get(&id) else {
|
|
|
|
|
return APIResult::Err(veilid_core::VeilidAPIError::invalid_argument("table_db_transaction_delete", "id", id));
|
|
|
|
|
return APIResult::Err(veilid_core::VeilidAPIError::invalid_argument(
|
|
|
|
|
"table_db_transaction_delete",
|
|
|
|
|
"id",
|
|
|
|
|
id,
|
|
|
|
|
));
|
|
|
|
|
};
|
|
|
|
|
tdbt.clone()
|
|
|
|
|
};
|
|
|
|
|
@@ -859,7 +920,11 @@ pub fn table_db_store(id: u32, col: u32, key: String, value: String) -> Promise
|
|
|
|
|
let table_db = {
|
|
|
|
|
let table_dbs = (*TABLE_DBS).borrow();
|
|
|
|
|
let Some(table_db) = table_dbs.get(&id) else {
|
|
|
|
|
return APIResult::Err(veilid_core::VeilidAPIError::invalid_argument("table_db_store", "id", id));
|
|
|
|
|
return APIResult::Err(veilid_core::VeilidAPIError::invalid_argument(
|
|
|
|
|
"table_db_store",
|
|
|
|
|
"id",
|
|
|
|
|
id,
|
|
|
|
|
));
|
|
|
|
|
};
|
|
|
|
|
table_db.clone()
|
|
|
|
|
};
|
|
|
|
|
@@ -878,7 +943,11 @@ pub fn table_db_load(id: u32, col: u32, key: String) -> Promise {
|
|
|
|
|
let table_db = {
|
|
|
|
|
let table_dbs = (*TABLE_DBS).borrow();
|
|
|
|
|
let Some(table_db) = table_dbs.get(&id) else {
|
|
|
|
|
return APIResult::Err(veilid_core::VeilidAPIError::invalid_argument("table_db_load", "id", id));
|
|
|
|
|
return APIResult::Err(veilid_core::VeilidAPIError::invalid_argument(
|
|
|
|
|
"table_db_load",
|
|
|
|
|
"id",
|
|
|
|
|
id,
|
|
|
|
|
));
|
|
|
|
|
};
|
|
|
|
|
table_db.clone()
|
|
|
|
|
};
|
|
|
|
|
@@ -898,7 +967,11 @@ pub fn table_db_delete(id: u32, col: u32, key: String) -> Promise {
|
|
|
|
|
let table_db = {
|
|
|
|
|
let table_dbs = (*TABLE_DBS).borrow();
|
|
|
|
|
let Some(table_db) = table_dbs.get(&id) else {
|
|
|
|
|
return APIResult::Err(veilid_core::VeilidAPIError::invalid_argument("table_db_delete", "id", id));
|
|
|
|
|
return APIResult::Err(veilid_core::VeilidAPIError::invalid_argument(
|
|
|
|
|
"table_db_delete",
|
|
|
|
|
"id",
|
|
|
|
|
id,
|
|
|
|
|
));
|
|
|
|
|
};
|
|
|
|
|
table_db.clone()
|
|
|
|
|
};
|
|
|
|
|
|