diff --git a/README.md b/README.md index a2f0dd8..7dbe9df 100644 --- a/README.md +++ b/README.md @@ -271,7 +271,8 @@ await store.setJSON('some-key', { ### `delete(key: string): Promise` -If an entry exists with the given key, deletes it and returns `true`. If not, `false` is returned. +Deletes an object with the given key, if one exists. The return value is always `undefined`, regardless of whether or +not there was an object to delete. ```javascript await store.delete('my-key') diff --git a/src/main.test.ts b/src/main.test.ts index 769f5ff..179fef8 100644 --- a/src/main.test.ts +++ b/src/main.test.ts @@ -1081,12 +1081,13 @@ describe('delete', () => { siteID, }) - expect(await blobs.delete(key)).toBe(true) - expect(await blobs.delete(complexKey)).toBe(true) + await blobs.delete(key) + await blobs.delete(complexKey) + expect(mockStore.fulfilled).toBeTruthy() }) - test('Returns `false` when the blob does not exist', async () => { + test('Does not throw when the blob does not exist', async () => { const mockStore = new MockFetch() .delete({ headers: { authorization: `Bearer ${apiToken}` }, @@ -1106,7 +1107,8 @@ describe('delete', () => { siteID, }) - expect(await blobs.delete(key)).toBe(false) + await blobs.delete(key) + expect(mockStore.fulfilled).toBeTruthy() }) @@ -1149,11 +1151,12 @@ describe('delete', () => { siteID, }) - expect(await blobs.delete(key)).toBe(true) + await blobs.delete(key) + expect(mockStore.fulfilled).toBeTruthy() }) - test('Returns `false` when the blob does not exist', async () => { + test('Does not throw when the blob does not exist', async () => { const mockStore = new MockFetch().delete({ headers: { authorization: `Bearer ${edgeToken}` }, response: new Response(null, { status: 404 }), @@ -1169,7 +1172,8 @@ describe('delete', () => { siteID, }) - expect(await blobs.delete(key)).toBe(false) + await blobs.delete(key) + expect(mockStore.fulfilled).toBeTruthy() }) diff --git a/src/store.ts b/src/store.ts index 6d38ef0..2e76f54 100644 --- a/src/store.ts +++ b/src/store.ts @@ -77,19 +77,11 @@ export class Store { } } - async delete(key: string): Promise { + async delete(key: string) { const res = await this.client.makeRequest({ key, method: HTTPMethod.DELETE, storeName: this.name }) - switch (res.status) { - case 200: - case 202: - return true - - case 404: - return false - - default: - throw new BlobsInternalError(res.status) + if (![200, 202, 404].includes(res.status)) { + throw new BlobsInternalError(res.status) } }