js/ffi work

This commit is contained in:
John Smith 2023-01-04 14:51:13 -05:00
parent bfc27fa024
commit b773064012
3 changed files with 20 additions and 20 deletions

View File

@ -1859,6 +1859,12 @@ abstract class VeilidTableDBTransaction {
return store(col, key,
utf8.encoder.convert(jsonEncode(object, toEncodable: toEncodable)));
}
Future<void> storeStringJson(int col, String key, Object? object,
{Object? Function(Object? nonEncodable)? toEncodable}) {
return storeJson(col, utf8.encoder.convert(key), object,
toEncodable: toEncodable);
}
}
abstract class VeilidTableDB {
@ -1877,8 +1883,8 @@ abstract class VeilidTableDB {
Future<void> storeStringJson(int col, String key, Object? object,
{Object? Function(Object? nonEncodable)? toEncodable}) {
return storeJson(col, utf8.encoder.convert(key),
utf8.encoder.convert(jsonEncode(object, toEncodable: toEncodable)));
return storeJson(col, utf8.encoder.convert(key), object,
toEncodable: toEncodable);
}
Future<Object?> loadJson(int col, Uint8List key,

View File

@ -96,14 +96,14 @@ class VeilidTableDBTransactionJS extends VeilidTableDBTransaction {
@override
Future<void> commit() {
return _wrapApiPromise(js_util
.callMethod(wasm, "veilid_table_db_transaction_commit", [_tdbt.id]));
return _wrapApiPromise(
js_util.callMethod(wasm, "table_db_transaction_commit", [_tdbt.id]));
}
@override
Future<void> rollback() {
return _wrapApiPromise(js_util
.callMethod(wasm, "veilid_table_db_transaction_rollback", [_tdbt.id]));
return _wrapApiPromise(
js_util.callMethod(wasm, "table_db_transaction_rollback", [_tdbt.id]));
}
@override
@ -111,10 +111,8 @@ class VeilidTableDBTransactionJS extends VeilidTableDBTransaction {
final encodedKey = base64UrlEncode(key);
final encodedValue = base64UrlEncode(value);
return _wrapApiPromise(js_util.callMethod(
wasm,
"veilid_table_db_transaction_store",
[_tdbt.id, encodedKey, encodedValue]));
return _wrapApiPromise(js_util.callMethod(wasm,
"table_db_transaction_store", [_tdbt.id, encodedKey, encodedValue]));
}
@override
@ -122,7 +120,7 @@ class VeilidTableDBTransactionJS extends VeilidTableDBTransaction {
final encodedKey = base64UrlEncode(key);
return _wrapApiPromise(js_util.callMethod(
wasm, "veilid_table_db_transaction_delete", [_tdbt.id, encodedKey]));
wasm, "table_db_transaction_delete", [_tdbt.id, encodedKey]));
}
}
@ -172,15 +170,15 @@ class VeilidTableDBJS extends VeilidTableDB {
final encodedValue = base64UrlEncode(value);
return _wrapApiPromise(js_util.callMethod(
wasm, "veilid_table_db_store", [_tdb.id, encodedKey, encodedValue]));
wasm, "table_db_store", [_tdb.id, encodedKey, encodedValue]));
}
@override
Future<Uint8List?> load(int col, Uint8List key) async {
final encodedKey = base64UrlEncode(key);
String? out = await _wrapApiPromise(js_util
.callMethod(wasm, "veilid_table_db_store", [_tdb.id, encodedKey]));
String? out = await _wrapApiPromise(
js_util.callMethod(wasm, "table_db_load", [_tdb.id, encodedKey]));
if (out == null) {
return null;
}
@ -191,8 +189,8 @@ class VeilidTableDBJS extends VeilidTableDB {
Future<bool> delete(int col, Uint8List key) {
final encodedKey = base64UrlEncode(key);
return _wrapApiPromise(js_util
.callMethod(wasm, "veilid_table_db_delete", [_tdb.id, encodedKey]));
return _wrapApiPromise(
js_util.callMethod(wasm, "table_db_delete", [_tdb.id, encodedKey]));
}
}
@ -307,10 +305,8 @@ class VeilidJS implements Veilid {
@override
Future<VeilidTableDB> openTableDB(String name, int columnCount) async {
print('shit');
int id = await _wrapApiPromise(
js_util.callMethod(wasm, "open_table_db", [name, columnCount]));
print('qwerqwer');
return VeilidTableDBJS._(_TDB(id, this));
}

View File

@ -492,7 +492,6 @@ fn add_table_db(table_db: veilid_core::TableDB) -> u32 {
next_id += 1;
}
tdbs.insert(next_id, table_db);
console_log(&format!("tdb added: {}", next_id));
next_id
}
@ -512,7 +511,6 @@ pub fn open_table_db(name: String, column_count: u32) -> Promise {
#[wasm_bindgen()]
pub fn release_table_db(id: u32) -> i32 {
console_log(&format!("tdb released: {}", id));
let mut tdbs = (*TABLE_DBS).borrow_mut();
if tdbs.remove(&id).is_none() {
return 0;