From e3ca7f94949b2bbb8f83927acfed4bef43b25cd1 Mon Sep 17 00:00:00 2001 From: Bauke Date: Sat, 3 Jun 2023 12:53:54 +0200 Subject: [PATCH] Add a getItem function. --- source/item/item.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/source/item/item.ts b/source/item/item.ts index 0ebf6f6..5a1a668 100644 --- a/source/item/item.ts +++ b/source/item/item.ts @@ -119,6 +119,23 @@ export async function createItem( return item; } +/** + * Get the item for a given key and {@link ItemKeyPrefix}. Note that this + * function assumes that the item definitely exists. + */ +export async function getItem( + key: string, + itemKeyPrefix: ItemKeyPrefix, +): Promise> { + return createValue({ + deserialize: deserializeItem, + serialize: serializeItem, + storage: storageForPrefix(itemKeyPrefix), + key, + value: undefined!, + }); +} + /** * Get all keys from storage that start with the {@link ItemKeyPrefix}. *