getKeys method

  1. @override
Future<Stream<String>> getKeys({
  1. String? regex,
})
override

Streams the keys, optionally filtered by regex. The returned Future completes once the backend has accepted the request — setup failures (store not open, invalid regex) reject the Future eagerly rather than surfacing mid-stream; the Stream then yields the matching keys.

Implementation

@override
Future<Stream<String>> getKeys({String? regex}) async {
  // Eager validation: a bad regex rejects the Future, not the Stream.
  final re = RegExp(regex ?? '.*');
  final now = _nowMillis();
  final rows = _db.raw.select(
      'SELECT atkey FROM at_data WHERE (available_at IS NULL OR available_at <= ?) '
      'AND (expires_at IS NULL OR expires_at > ?);',
      [now, now]);
  final matched =
      rows.map((r) => r['atkey'] as String).where(re.hasMatch).toList();
  return Stream.fromIterable(matched);
}