getKeys method

  1. @override
Future<List<String>> getKeys()
override

Implementation

@override
Future<List<String>> getKeys() async {
  final database = await _database;
  final idsTransaction = database.transaction(_recordStore, idbModeReadOnly);
  final recordIds = await idsTransaction
      .objectStore(_recordStore)
      .getAllKeys();
  await idsTransaction.completed;
  final keys = <String>{};
  final matchingIds = recordIds.where(
    (id) => id.toString().startsWith(_namespacePrefix),
  );
  final transaction = database.transaction(_recordStore, idbModeReadOnly);
  final store = transaction.objectStore(_recordStore);
  final records = await Future.wait<dynamic>(
    matchingIds.map<Future<dynamic>>(store.getObject),
  );
  await transaction.completed;
  for (final raw in records) {
    if (raw is! String) {
      throw const FormatException('IndexedDB record is not a string');
    }
    keys.add(codec.decode(raw, allowLegacy: false).key);
  }
  return keys.toList()..sort();
}