@@ -19,6 +19,7 @@ interface NamedStoreOptions extends BaseStoreOptions {
19
19
}
20
20
21
21
export type StoreOptions = DeployStoreOptions | NamedStoreOptions
22
+ type Key < T > = T extends string ? ( T extends '' | `/${string } ` ? never : T ) : never
22
23
23
24
export interface GetWithMetadataOptions {
24
25
etag ?: string
@@ -257,7 +258,10 @@ export class Store {
257
258
)
258
259
}
259
260
260
- async set ( key : string , data : BlobInput , { metadata } : SetOptions = { } ) {
261
+ async set ( key : `Key must not be empty and must not start with /`, data : BlobInput , opts ?: SetOptions ) : Promise < void >
262
+ async set < K > ( key : Key < K > , data : BlobInput ) : Promise < void >
263
+ async set < K > ( key : Key < K > , data : BlobInput , { metadata } : SetOptions ) : Promise < void >
264
+ async set < K > ( key : Key < K > , data : BlobInput , { metadata } : SetOptions = { } ) {
261
265
Store . validateKey ( key )
262
266
263
267
const res = await this . client . makeRequest ( {
@@ -273,7 +277,7 @@ export class Store {
273
277
}
274
278
}
275
279
276
- async setJSON ( key : string , data : unknown , { metadata } : SetOptions = { } ) {
280
+ async setJSON < K > ( key : Key < K > , data : unknown , { metadata } : SetOptions = { } ) {
277
281
Store . validateKey ( key )
278
282
279
283
const payload = JSON . stringify ( data )
@@ -306,7 +310,7 @@ export class Store {
306
310
}
307
311
}
308
312
309
- private static validateKey ( key : string ) {
313
+ private static validateKey < K > ( key : Key < K > ) {
310
314
if ( key === '' ) {
311
315
throw new Error ( 'Blob key must not be empty.' )
312
316
}
0 commit comments