From 73b11d76856a5da8e1c337c00921f7c46b028601 Mon Sep 17 00:00:00 2001 From: Dillon Nys Date: Thu, 7 Mar 2024 12:43:14 -0800 Subject: [PATCH] Align memstorage interface --- packages/celest_core/lib/src/storage/memory_storage.dart | 6 ++++-- packages/celest_core/lib/src/storage/storage.dart | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/celest_core/lib/src/storage/memory_storage.dart b/packages/celest_core/lib/src/storage/memory_storage.dart index ece77fb6..887b8771 100644 --- a/packages/celest_core/lib/src/storage/memory_storage.dart +++ b/packages/celest_core/lib/src/storage/memory_storage.dart @@ -4,12 +4,14 @@ import 'package:celest_core/src/storage/storage.dart'; /// An in-memory implementation of [Storage] and [SecureStorage]. final class MemoryStorage implements Storage, SecureStorage { MemoryStorage({ - required this.scope, - }); + String? scope, + }) : scope = scope ?? _defaultScope; final _storage = {}; final String scope; + static const _defaultScope = 'dev.celest.cli'; + @override void clear() => _storage.removeWhere((key, _) => key.startsWith('$scope/')); diff --git a/packages/celest_core/lib/src/storage/storage.dart b/packages/celest_core/lib/src/storage/storage.dart index 7bc64447..ff0d5de3 100644 --- a/packages/celest_core/lib/src/storage/storage.dart +++ b/packages/celest_core/lib/src/storage/storage.dart @@ -1,7 +1,9 @@ import 'package:celest_core/src/storage/local/local_storage.dart'; +import 'package:celest_core/src/storage/memory_storage.dart'; import 'package:celest_core/src/storage/secure/secure_storage.dart'; abstract interface class Storage { + factory Storage.memory({String? scope}) = MemoryStorage; factory Storage.local({String? scope}) = LocalStorage; factory Storage.secure({String? scope}) = SecureStorage;