Skip to content

feat: remove return value of delete() #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ await store.setJSON('some-key', {

### `delete(key: string): Promise<void>`

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')
Expand Down
18 changes: 11 additions & 7 deletions src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}` },
Expand All @@ -1106,7 +1107,8 @@ describe('delete', () => {
siteID,
})

expect(await blobs.delete(key)).toBe(false)
await blobs.delete(key)

expect(mockStore.fulfilled).toBeTruthy()
})

Expand Down Expand Up @@ -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 }),
Expand All @@ -1169,7 +1172,8 @@ describe('delete', () => {
siteID,
})

expect(await blobs.delete(key)).toBe(false)
await blobs.delete(key)

expect(mockStore.fulfilled).toBeTruthy()
})

Expand Down
14 changes: 3 additions & 11 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,11 @@ export class Store {
}
}

async delete(key: string): Promise<boolean> {
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)
}
}

Expand Down