more json schema
This commit is contained in:
		@@ -295,4 +295,12 @@ impl VeilidAPI {
 | 
				
			|||||||
    pub async fn cancel_tunnel(&self, _tunnel_id: TunnelId) -> VeilidAPIResult<bool> {
 | 
					    pub async fn cancel_tunnel(&self, _tunnel_id: TunnelId) -> VeilidAPIResult<bool> {
 | 
				
			||||||
        panic!("unimplemented");
 | 
					        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,
 | 
					    op: RequestOp,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
 | 
				
			||||||
 | 
					#[serde(tag = "type")]
 | 
				
			||||||
 | 
					pub enum RecvMessage {
 | 
				
			||||||
 | 
					    Response(Response),
 | 
				
			||||||
 | 
					    Update(VeilidUpdate),
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
 | 
					#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
 | 
				
			||||||
pub struct Response {
 | 
					pub struct Response {
 | 
				
			||||||
    /// Operation Id (pairs with Request, or empty if unidirectional)
 | 
					    /// Operation Id (pairs with Request, or empty if unidirectional)
 | 
				
			||||||
@@ -72,6 +79,7 @@ pub enum RequestOp {
 | 
				
			|||||||
        name: String,
 | 
					        name: String,
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    TableDb(TableDbRequest),
 | 
					    TableDb(TableDbRequest),
 | 
				
			||||||
 | 
					    TableDbTransaction(TableDbTransactionRequest),
 | 
				
			||||||
    // Crypto
 | 
					    // Crypto
 | 
				
			||||||
    GetCryptoSystem {
 | 
					    GetCryptoSystem {
 | 
				
			||||||
        #[schemars(with = "String")]
 | 
					        #[schemars(with = "String")]
 | 
				
			||||||
@@ -120,9 +128,6 @@ pub struct NewPrivateRouteResult {
 | 
				
			|||||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
 | 
					#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
 | 
				
			||||||
#[serde(tag = "op")]
 | 
					#[serde(tag = "op")]
 | 
				
			||||||
pub enum ResponseOp {
 | 
					pub enum ResponseOp {
 | 
				
			||||||
    Update {
 | 
					 | 
				
			||||||
        value: VeilidUpdate,
 | 
					 | 
				
			||||||
    },
 | 
					 | 
				
			||||||
    GetState {
 | 
					    GetState {
 | 
				
			||||||
        #[serde(flatten)]
 | 
					        #[serde(flatten)]
 | 
				
			||||||
        result: ApiResult<VeilidState>,
 | 
					        result: ApiResult<VeilidState>,
 | 
				
			||||||
@@ -171,6 +176,7 @@ pub enum ResponseOp {
 | 
				
			|||||||
        result: ApiResult<bool>,
 | 
					        result: ApiResult<bool>,
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    TableDb(TableDbResponse),
 | 
					    TableDb(TableDbResponse),
 | 
				
			||||||
 | 
					    TableDbTransaction(TableDbTransactionResponse),
 | 
				
			||||||
    // Crypto
 | 
					    // Crypto
 | 
				
			||||||
    GetCryptoSystem {
 | 
					    GetCryptoSystem {
 | 
				
			||||||
        #[serde(flatten)]
 | 
					        #[serde(flatten)]
 | 
				
			||||||
@@ -250,6 +256,25 @@ pub enum ApiResultWithVecU8 {
 | 
				
			|||||||
        error: VeilidAPIError,
 | 
					        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)]
 | 
					#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
 | 
				
			||||||
#[serde(untagged)]
 | 
					#[serde(untagged)]
 | 
				
			||||||
@@ -268,7 +293,7 @@ where
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
pub fn emit_schemas(out: &mut HashMap<String, String>) {
 | 
					pub fn emit_schemas(out: &mut HashMap<String, String>) {
 | 
				
			||||||
    let schema_request = schema_for!(Request);
 | 
					    let schema_request = schema_for!(Request);
 | 
				
			||||||
    let schema_response = schema_for!(Response);
 | 
					    let schema_recv_message = schema_for!(RecvMessage);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    out.insert(
 | 
					    out.insert(
 | 
				
			||||||
        "Request".to_owned(),
 | 
					        "Request".to_owned(),
 | 
				
			||||||
@@ -276,7 +301,7 @@ pub fn emit_schemas(out: &mut HashMap<String, String>) {
 | 
				
			|||||||
    );
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    out.insert(
 | 
					    out.insert(
 | 
				
			||||||
        "Response".to_owned(),
 | 
					        "RecvMessage".to_owned(),
 | 
				
			||||||
        serde_json::to_string_pretty(&schema_response).unwrap(),
 | 
					        serde_json::to_string_pretty(&schema_recv_message).unwrap(),
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,9 +18,118 @@ pub struct TableDbResponse {
 | 
				
			|||||||
#[serde(tag = "db_op")]
 | 
					#[serde(tag = "db_op")]
 | 
				
			||||||
pub enum TableDbRequestOp {
 | 
					pub enum TableDbRequestOp {
 | 
				
			||||||
    Release,
 | 
					    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)]
 | 
					#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
 | 
				
			||||||
#[serde(tag = "db_op")]
 | 
					#[serde(tag = "db_op")]
 | 
				
			||||||
pub enum TableDbResponseOp {
 | 
					pub enum TableDbResponseOp {
 | 
				
			||||||
    Release,
 | 
					    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
 | 
					  @override
 | 
				
			||||||
  Future<bool> delete(int col, Uint8List key) {
 | 
					  Future<void> delete(int col, Uint8List key) {
 | 
				
			||||||
    final nativeEncodedKey = base64UrlNoPadEncode(key).toNativeUtf8();
 | 
					    final nativeEncodedKey = base64UrlNoPadEncode(key).toNativeUtf8();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    final recvPort = ReceivePort("veilid_table_db_transaction_delete");
 | 
					    final recvPort = ReceivePort("veilid_table_db_transaction_delete");
 | 
				
			||||||
@@ -888,7 +888,7 @@ class VeilidTableDBFFI extends VeilidTableDB {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @override
 | 
					  @override
 | 
				
			||||||
  Future<Uint8List?> delete(int col, Uint8List key) {
 | 
					  Future<Uint8List?> delete(int col, Uint8List key) async {
 | 
				
			||||||
    final nativeEncodedKey = base64UrlNoPadEncode(key).toNativeUtf8();
 | 
					    final nativeEncodedKey = base64UrlNoPadEncode(key).toNativeUtf8();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    final recvPort = ReceivePort("veilid_table_db_delete");
 | 
					    final recvPort = ReceivePort("veilid_table_db_delete");
 | 
				
			||||||
@@ -899,7 +899,11 @@ class VeilidTableDBFFI extends VeilidTableDB {
 | 
				
			|||||||
      col,
 | 
					      col,
 | 
				
			||||||
      nativeEncodedKey,
 | 
					      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
 | 
					  @override
 | 
				
			||||||
  Future<bool> delete(int col, Uint8List key) {
 | 
					  Future<void> delete(int col, Uint8List key) {
 | 
				
			||||||
    final encodedKey = base64UrlNoPadEncode(key);
 | 
					    final encodedKey = base64UrlNoPadEncode(key);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return _wrapApiPromise(js_util.callMethod(
 | 
					    return _wrapApiPromise(js_util.callMethod(
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,7 +8,7 @@ abstract class VeilidTableDBTransaction {
 | 
				
			|||||||
  Future<void> commit();
 | 
					  Future<void> commit();
 | 
				
			||||||
  Future<void> rollback();
 | 
					  Future<void> rollback();
 | 
				
			||||||
  Future<void> store(int col, Uint8List key, Uint8List value);
 | 
					  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,
 | 
					  Future<void> storeJson(int col, Uint8List key, Object? object,
 | 
				
			||||||
      {Object? Function(Object? nonEncodable)? toEncodable}) async {
 | 
					      {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()
 | 
					            tdbt.clone()
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        let out = tdbt.delete(col, &key);
 | 
					        tdbt.delete(col, &key);
 | 
				
			||||||
        APIResult::Ok(out)
 | 
					        APIRESULT_VOID
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user