inspectOpfsDatabase function

Future<SqliteOpfsDatabase?> inspectOpfsDatabase({
  1. required Uri opfsWorker,
  2. required Uri sqlite3Wasm,
  3. required String storageName,
})

Opens the OPFS database storageName as it is, without the Web Lock, the schema steps or the IndexedDB import of sqliteWebOpener: to look at a database that nothing else has open (tests, debugging). Returns null when the browser has no synchronous OPFS access in workers.

Implementation

Future<SqliteOpfsDatabase?> inspectOpfsDatabase({
  required Uri opfsWorker,
  required Uri sqlite3Wasm,
  required String storageName,
}) async {
  final _OpfsWorker? connection = _OpfsWorker.start(
    Uri.base.resolveUri(opfsWorker),
  );
  if (connection == null) {
    return null;
  }
  try {
    final JSObject loaded =
        (await connection.call(
              'load',
              JSObject()
                ..['wasm'] = Uri.base.resolveUri(sqlite3Wasm).toString().toJS
                ..['path'] = storageName.toJS
                ..['waitMs'] = _opfsHandleTimeout.inMilliseconds.toJS,
            ))!
            as JSObject;
    if (!(loaded['supported']! as JSBoolean).toDart) {
      connection.terminate();
      return null;
    }
    await connection.call('open');
    return SqliteOpfsDatabase._(connection, storageName, () async {});
  } catch (_) {
    connection.terminate();
    rethrow;
  }
}