Add a getItem function.

This commit is contained in:
Bauke 2023-06-03 12:53:54 +02:00
parent e53bea8fe4
commit e3ca7f9494
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
1 changed files with 17 additions and 0 deletions

View File

@ -119,6 +119,23 @@ export async function createItem(
return item; 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<Value<Item>> {
return createValue<Item>({
deserialize: deserializeItem,
serialize: serializeItem,
storage: storageForPrefix(itemKeyPrefix),
key,
value: undefined!,
});
}
/** /**
* Get all keys from storage that start with the {@link ItemKeyPrefix}. * Get all keys from storage that start with the {@link ItemKeyPrefix}.
* *