From 9a80984b715a38f2f076cce0da19d29e1dae1cba Mon Sep 17 00:00:00 2001 From: provokateurin Date: Wed, 7 Aug 2024 18:44:35 +0200 Subject: [PATCH] feat(neon_framework): Add keys() methods for Persistence and SettingsStore Signed-off-by: provokateurin --- packages/neon_framework/lib/src/storage/persistence.dart | 6 ++++++ packages/neon_framework/lib/src/storage/settings_store.dart | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/packages/neon_framework/lib/src/storage/persistence.dart b/packages/neon_framework/lib/src/storage/persistence.dart index e42bc218477..1a1311c17f8 100644 --- a/packages/neon_framework/lib/src/storage/persistence.dart +++ b/packages/neon_framework/lib/src/storage/persistence.dart @@ -7,6 +7,9 @@ abstract interface class Persistence { /// Whether a value exists at the given [key]. FutureOr containsKey(String key); + /// Returns all keys in the persistent storage. + FutureOr> keys(); + /// Clears all values from persistent storage. FutureOr clear(); @@ -53,6 +56,9 @@ abstract class CachedPersistence implements Persistence { /// when the app is restarted. void setCache(String key, T value) => cache[key] = value; + @override + List keys() => cache.keys.toList(); + @override bool containsKey(String key) => cache.containsKey(key); diff --git a/packages/neon_framework/lib/src/storage/settings_store.dart b/packages/neon_framework/lib/src/storage/settings_store.dart index 0297904a439..42fe1f4ad69 100644 --- a/packages/neon_framework/lib/src/storage/settings_store.dart +++ b/packages/neon_framework/lib/src/storage/settings_store.dart @@ -32,6 +32,9 @@ abstract interface class SettingsStore { /// Removes an entry from persistent storage. Future remove(String key); + + /// Returns all keys in the persistent storage. + List keys(); } /// Default implementation of the [SettingsStore] backed by the given [persistence]. @@ -62,4 +65,7 @@ final class DefaultSettingsStore implements SettingsStore { @override Future setBool(String key, bool value) => persistence.setValue(key, value); + + @override + List keys() => persistence.keys(); }