File tree 2 files changed +6
-3
lines changed
2 files changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -781,7 +781,9 @@ describe('set', () => {
781
781
siteID,
782
782
} )
783
783
784
+ // @ts -expect-error The `key` paramater is typed to not allow this
784
785
expect ( async ( ) => await blobs . set ( '' , 'value' ) ) . rejects . toThrowError ( 'Blob key must not be empty.' )
786
+ // @ts -expect-error The `key` paramater is typed to not allow this
785
787
expect ( async ( ) => await blobs . set ( '/key' , 'value' ) ) . rejects . toThrowError (
786
788
'Blob key must not start with forward slash (/).' ,
787
789
)
Original file line number Diff line number Diff line change @@ -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,7 @@ export class Store {
257
258
)
258
259
}
259
260
260
- async set ( key : string , data : BlobInput , { metadata } : SetOptions = { } ) {
261
+ async set < K > ( key : Key < K > , data : BlobInput , { metadata } : SetOptions = { } ) {
261
262
Store . validateKey ( key )
262
263
263
264
const res = await this . client . makeRequest ( {
@@ -273,7 +274,7 @@ export class Store {
273
274
}
274
275
}
275
276
276
- async setJSON ( key : string , data : unknown , { metadata } : SetOptions = { } ) {
277
+ async setJSON < K > ( key : Key < K > , data : unknown , { metadata } : SetOptions = { } ) {
277
278
Store . validateKey ( key )
278
279
279
280
const payload = JSON . stringify ( data )
@@ -306,7 +307,7 @@ export class Store {
306
307
}
307
308
}
308
309
309
- private static validateKey ( key : string ) {
310
+ private static validateKey < K > ( key : Key < K > ) {
310
311
if ( key === '' ) {
311
312
throw new Error ( 'Blob key must not be empty.' )
312
313
}
You can’t perform that action at this time.
0 commit comments