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

View File

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

View File

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