From 9c22799d2140a5fc1156f639217a3f69d137f038 Mon Sep 17 00:00:00 2001 From: mjgu Date: Wed, 4 Feb 2026 14:50:21 +0900 Subject: [PATCH] feature: add get method with limit parameter to FileDictionaryStorage feature: add get method with limit parameter to DictionaryStorage protocol --- Source/AppleStorage/DictionaryStorage.swift | 1 + .../Implement/FileDictionaryStorage.swift | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/Source/AppleStorage/DictionaryStorage.swift b/Source/AppleStorage/DictionaryStorage.swift index 4789568c..2a07de30 100644 --- a/Source/AppleStorage/DictionaryStorage.swift +++ b/Source/AppleStorage/DictionaryStorage.swift @@ -15,5 +15,6 @@ public protocol DictionaryStorage: Storage { func delete(key: Key) -> Promise func clear() -> Promise func get(key: Key) -> Promise + func get(limit: Limit) -> Promise<[Value], Error> func save() -> Promise } diff --git a/Source/AppleStorage/Implement/FileDictionaryStorage.swift b/Source/AppleStorage/Implement/FileDictionaryStorage.swift index 01052cdc..b3891e78 100644 --- a/Source/AppleStorage/Implement/FileDictionaryStorage.swift +++ b/Source/AppleStorage/Implement/FileDictionaryStorage.swift @@ -72,6 +72,21 @@ extension FileDictionaryStorage { } } } + + public func get(limit: Limit) -> Promise<[Value], Error> { + execute { context in + context.values.capture { values in + let array = Array(values.values) + switch limit { + case .unlimited: + return array + case .count(let limit): + return Array(array.prefix(limit)) + } + } + } + } + public func save() -> Promise { execute { context in @@ -167,3 +182,4 @@ struct FileDictionaryStorageContext { // Must not be modified. Write new ItemVersion and write migration logic instead. typealias FileDictionaryStorageItemVersion1 = [Key: Value] +