more json schema
This commit is contained in:
parent
06081df22a
commit
0e52c1fb0a
@ -295,4 +295,12 @@ impl VeilidAPI {
|
||||
pub async fn cancel_tunnel(&self, _tunnel_id: TunnelId) -> VeilidAPIResult<bool> {
|
||||
panic!("unimplemented");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
// JSON API
|
||||
|
||||
#[instrument(level = "debug", skip(self))]
|
||||
pub async fn json_request(&self, request: json_api::Request) -> json_api::Response {
|
||||
panic!("unimplemented");
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,13 @@ pub struct Request {
|
||||
op: RequestOp,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
#[serde(tag = "type")]
|
||||
pub enum RecvMessage {
|
||||
Response(Response),
|
||||
Update(VeilidUpdate),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct Response {
|
||||
/// Operation Id (pairs with Request, or empty if unidirectional)
|
||||
@ -72,6 +79,7 @@ pub enum RequestOp {
|
||||
name: String,
|
||||
},
|
||||
TableDb(TableDbRequest),
|
||||
TableDbTransaction(TableDbTransactionRequest),
|
||||
// Crypto
|
||||
GetCryptoSystem {
|
||||
#[schemars(with = "String")]
|
||||
@ -120,9 +128,6 @@ pub struct NewPrivateRouteResult {
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
#[serde(tag = "op")]
|
||||
pub enum ResponseOp {
|
||||
Update {
|
||||
value: VeilidUpdate,
|
||||
},
|
||||
GetState {
|
||||
#[serde(flatten)]
|
||||
result: ApiResult<VeilidState>,
|
||||
@ -171,6 +176,7 @@ pub enum ResponseOp {
|
||||
result: ApiResult<bool>,
|
||||
},
|
||||
TableDb(TableDbResponse),
|
||||
TableDbTransaction(TableDbTransactionResponse),
|
||||
// Crypto
|
||||
GetCryptoSystem {
|
||||
#[serde(flatten)]
|
||||
@ -250,6 +256,25 @@ pub enum ApiResultWithVecU8 {
|
||||
error: VeilidAPIError,
|
||||
},
|
||||
}
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
#[serde(transparent)]
|
||||
pub struct VecU8 {
|
||||
#[serde(with = "json_as_base64")]
|
||||
#[schemars(with = "String")]
|
||||
value: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
#[serde(untagged)]
|
||||
pub enum ApiResultWithVecVecU8 {
|
||||
Ok {
|
||||
#[schemars(with = "Vec<String>")]
|
||||
value: Vec<VecU8>,
|
||||
},
|
||||
Err {
|
||||
error: VeilidAPIError,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
#[serde(untagged)]
|
||||
@ -268,7 +293,7 @@ where
|
||||
|
||||
pub fn emit_schemas(out: &mut HashMap<String, String>) {
|
||||
let schema_request = schema_for!(Request);
|
||||
let schema_response = schema_for!(Response);
|
||||
let schema_recv_message = schema_for!(RecvMessage);
|
||||
|
||||
out.insert(
|
||||
"Request".to_owned(),
|
||||
@ -276,7 +301,7 @@ pub fn emit_schemas(out: &mut HashMap<String, String>) {
|
||||
);
|
||||
|
||||
out.insert(
|
||||
"Response".to_owned(),
|
||||
serde_json::to_string_pretty(&schema_response).unwrap(),
|
||||
"RecvMessage".to_owned(),
|
||||
serde_json::to_string_pretty(&schema_recv_message).unwrap(),
|
||||
);
|
||||
}
|
||||
|
@ -18,9 +18,118 @@ pub struct TableDbResponse {
|
||||
#[serde(tag = "db_op")]
|
||||
pub enum TableDbRequestOp {
|
||||
Release,
|
||||
GetColumnCount,
|
||||
GetKeys {
|
||||
col: i32,
|
||||
},
|
||||
Transact,
|
||||
Store {
|
||||
col: i32,
|
||||
#[serde(with = "json_as_base64")]
|
||||
#[schemars(with = "String")]
|
||||
key: Vec<u8>,
|
||||
#[serde(with = "json_as_base64")]
|
||||
#[schemars(with = "String")]
|
||||
value: Vec<u8>,
|
||||
},
|
||||
Load {
|
||||
col: i32,
|
||||
#[serde(with = "json_as_base64")]
|
||||
#[schemars(with = "String")]
|
||||
key: Vec<u8>,
|
||||
},
|
||||
Delete {
|
||||
col: i32,
|
||||
#[serde(with = "json_as_base64")]
|
||||
#[schemars(with = "String")]
|
||||
key: Vec<u8>,
|
||||
},
|
||||
}
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
#[serde(tag = "db_op")]
|
||||
pub enum TableDbResponseOp {
|
||||
Release,
|
||||
GetColumnCount {
|
||||
value: i32,
|
||||
},
|
||||
GetKeys {
|
||||
#[serde(flatten)]
|
||||
#[schemars(with = "ApiResult<Vec<String>>")]
|
||||
result: ApiResultWithVecVecU8,
|
||||
},
|
||||
Transact {
|
||||
value: String,
|
||||
},
|
||||
Store {
|
||||
#[serde(flatten)]
|
||||
result: ApiResult<()>,
|
||||
},
|
||||
Load {
|
||||
#[serde(flatten)]
|
||||
#[schemars(with = "ApiResult<Option<String>>")]
|
||||
result: ApiResult<Option<VecU8>>,
|
||||
},
|
||||
Delete {
|
||||
#[serde(flatten)]
|
||||
#[schemars(with = "ApiResult<Option<String>>")]
|
||||
result: ApiResult<Option<VecU8>>,
|
||||
},
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct TableDbTransactionRequest {
|
||||
tx_id: String,
|
||||
#[serde(flatten)]
|
||||
tx_op: TableDbTransactionRequestOp,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct TableDbTransactionResponse {
|
||||
tx_id: String,
|
||||
#[serde(flatten)]
|
||||
tx_op: TableDbTransactionResponseOp,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
#[serde(tag = "tx_op")]
|
||||
pub enum TableDbTransactionRequestOp {
|
||||
Commit,
|
||||
Rollback,
|
||||
Store {
|
||||
col: i32,
|
||||
#[serde(with = "json_as_base64")]
|
||||
#[schemars(with = "String")]
|
||||
key: Vec<u8>,
|
||||
#[serde(with = "json_as_base64")]
|
||||
#[schemars(with = "String")]
|
||||
value: Vec<u8>,
|
||||
},
|
||||
Delete {
|
||||
col: i32,
|
||||
#[serde(with = "json_as_base64")]
|
||||
#[schemars(with = "String")]
|
||||
key: Vec<u8>,
|
||||
},
|
||||
}
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
#[serde(tag = "tx_op")]
|
||||
pub enum TableDbTransactionResponseOp {
|
||||
Commit {
|
||||
#[serde(flatten)]
|
||||
result: ApiResult<()>,
|
||||
},
|
||||
Rollback {
|
||||
#[serde(flatten)]
|
||||
result: ApiResult<()>,
|
||||
},
|
||||
Store {
|
||||
#[serde(flatten)]
|
||||
result: ApiResult<()>,
|
||||
},
|
||||
Delete {
|
||||
#[serde(flatten)]
|
||||
result: ApiResult<()>,
|
||||
},
|
||||
}
|
||||
|
@ -797,7 +797,7 @@ class VeilidTableDBTransactionFFI extends VeilidTableDBTransaction {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> delete(int col, Uint8List key) {
|
||||
Future<void> delete(int col, Uint8List key) {
|
||||
final nativeEncodedKey = base64UrlNoPadEncode(key).toNativeUtf8();
|
||||
|
||||
final recvPort = ReceivePort("veilid_table_db_transaction_delete");
|
||||
@ -888,7 +888,7 @@ class VeilidTableDBFFI extends VeilidTableDB {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Uint8List?> delete(int col, Uint8List key) {
|
||||
Future<Uint8List?> delete(int col, Uint8List key) async {
|
||||
final nativeEncodedKey = base64UrlNoPadEncode(key).toNativeUtf8();
|
||||
|
||||
final recvPort = ReceivePort("veilid_table_db_delete");
|
||||
@ -899,7 +899,11 @@ class VeilidTableDBFFI extends VeilidTableDB {
|
||||
col,
|
||||
nativeEncodedKey,
|
||||
);
|
||||
return processFuturePlain(recvPort.first);
|
||||
String? out = await processFuturePlain(recvPort.first);
|
||||
if (out == null) {
|
||||
return null;
|
||||
}
|
||||
return base64UrlNoPadDecode(out);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -368,7 +368,7 @@ class VeilidTableDBTransactionJS extends VeilidTableDBTransaction {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> delete(int col, Uint8List key) {
|
||||
Future<void> delete(int col, Uint8List key) {
|
||||
final encodedKey = base64UrlNoPadEncode(key);
|
||||
|
||||
return _wrapApiPromise(js_util.callMethod(
|
||||
|
@ -8,7 +8,7 @@ abstract class VeilidTableDBTransaction {
|
||||
Future<void> commit();
|
||||
Future<void> rollback();
|
||||
Future<void> store(int col, Uint8List key, Uint8List value);
|
||||
Future<bool> delete(int col, Uint8List key);
|
||||
Future<void> delete(int col, Uint8List key);
|
||||
|
||||
Future<void> storeJson(int col, Uint8List key, Object? object,
|
||||
{Object? Function(Object? nonEncodable)? toEncodable}) async {
|
||||
|
@ -908,8 +908,8 @@ pub extern "C" fn table_db_transaction_delete(port: i64, id: u32, col: u32, key:
|
||||
tdbt.clone()
|
||||
};
|
||||
|
||||
let out = tdbt.delete(col, &key);
|
||||
APIResult::Ok(out)
|
||||
tdbt.delete(col, &key);
|
||||
APIRESULT_VOID
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user