Skip to content
This repository has been archived by the owner on Feb 7, 2023. It is now read-only.

Commit

Permalink
Add metadata typings for KV
Browse files Browse the repository at this point in the history
  • Loading branch information
GregBrimble authored and ispivey committed Aug 21, 2020
1 parent 519aebe commit 83c2a10
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,10 @@ declare interface CacheStorage {
}

type KVValue<Value> = Promise<Value | null>;
type KVValueWithMetadata<Value, Metadata> = Promise<{
value: Value | null;
metadata: Metadata | null;
}>;

interface KVNamespace {
get(key: string): KVValue<string>;
Expand All @@ -559,12 +563,31 @@ interface KVNamespace {
get(key: string, type: 'arrayBuffer'): KVValue<ArrayBuffer>;
get(key: string, type: 'stream'): KVValue<ReadableStream>;

getWithMetadata<Metadata = unknown>(key: string): KVValueWithMetadata<string, Metadata>;
getWithMetadata<Metadata = unknown>(
key: string,
type: 'text'
): KVValueWithMetadata<string, Metadata>;
getWithMetadata<ExpectedValue = unknown, Metadata = unknown>(
key: string,
type: 'json'
): KVValueWithMetadata<ExpectedValue, Metadata>;
getWithMetadata<Metadata = unknown>(
key: string,
type: 'arrayBuffer'
): KVValueWithMetadata<ArrayBuffer, Metadata>;
getWithMetadata<Metadata = unknown>(
key: string,
type: 'stream'
): KVValueWithMetadata<ReadableStream, Metadata>;

put(
key: string,
value: string | ReadableStream | ArrayBuffer | FormData,
options?: {
expiration?: string | number;
expirationTtl?: string | number;
metadata?: any;
}
): Promise<void>;

Expand All @@ -575,7 +598,7 @@ interface KVNamespace {
limit?: number;
cursor?: string;
}): Promise<{
keys: { name: string; expiration?: number }[];
keys: { name: string; expiration?: number; metadata?: unknown }[];
list_complete: boolean;
cursor: string;
}>;
Expand Down

0 comments on commit 83c2a10

Please sign in to comment.