Skip to content

Commit d01c589

Browse files
committed
feat!: remove fresh property from metadata result
1 parent a566287 commit d01c589

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,9 @@ const cachedETag = getFromMockCache('my-key')
221221

222222
// Get entry from the blob store only if its ETag is different from the one you
223223
// have locally, which means the entry has changed since you last obtained it
224-
const { data, etag, fresh } = await store.getWithMetadata('some-key', { etag: cachedETag })
224+
const { data, etag } = await store.getWithMetadata('some-key', { etag: cachedETag })
225225

226-
if (fresh) {
226+
if (etag === cachedETag) {
227227
// `data` is `null` because the local blob is fresh
228228
} else {
229229
// `data` contains the new blob, store it locally alongside the new ETag

src/main.test.ts

+12-11
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,10 @@ describe('getWithMetadata', () => {
574574
cool: true,
575575
functions: ['edge', 'serverless'],
576576
}
577-
const etags = ['"thewrongetag"', '"therightetag"']
577+
const etags = {
578+
right: '"therightetag"',
579+
wrong: '"thewrongetag"',
580+
}
578581
const metadataHeaders = {
579582
'x-amz-meta-user': `b64;${base64Encode(mockMetadata)}`,
580583
}
@@ -585,8 +588,8 @@ describe('getWithMetadata', () => {
585588
url: `https://api.netlify.com/api/v1/sites/${siteID}/blobs/${key}?context=production`,
586589
})
587590
.get({
588-
headers: { 'if-none-match': etags[0] },
589-
response: new Response(value, { headers: { ...metadataHeaders, etag: etags[0] }, status: 200 }),
591+
headers: { 'if-none-match': etags.wrong },
592+
response: new Response(value, { headers: { ...metadataHeaders, etag: etags.right }, status: 200 }),
590593
url: `${signedURL}b`,
591594
})
592595
.get({
@@ -595,8 +598,8 @@ describe('getWithMetadata', () => {
595598
url: `https://api.netlify.com/api/v1/sites/${siteID}/blobs/${key}?context=production`,
596599
})
597600
.get({
598-
headers: { 'if-none-match': etags[1] },
599-
response: new Response(null, { headers: { ...metadataHeaders, etag: etags[0] }, status: 304 }),
601+
headers: { 'if-none-match': etags.right },
602+
response: new Response(null, { headers: { ...metadataHeaders, etag: etags.right }, status: 304 }),
600603
url: `${signedURL}a`,
601604
})
602605

@@ -608,16 +611,14 @@ describe('getWithMetadata', () => {
608611
siteID,
609612
})
610613

611-
const staleEntry = await blobs.getWithMetadata(key, { etag: etags[0] })
614+
const staleEntry = await blobs.getWithMetadata(key, { etag: etags.wrong })
612615
expect(staleEntry?.data).toBe(value)
613-
expect(staleEntry?.etag).toBe(etags[0])
614-
expect(staleEntry?.fresh).toBe(false)
616+
expect(staleEntry?.etag).toBe(etags.right)
615617
expect(staleEntry?.metadata).toEqual(mockMetadata)
616618

617-
const freshEntry = await blobs.getWithMetadata(key, { etag: etags[1], type: 'text' })
619+
const freshEntry = await blobs.getWithMetadata(key, { etag: etags.right, type: 'text' })
618620
expect(freshEntry?.data).toBe(null)
619-
expect(freshEntry?.etag).toBe(etags[0])
620-
expect(freshEntry?.fresh).toBe(true)
621+
expect(freshEntry?.etag).toBe(etags.right)
621622
expect(freshEntry?.metadata).toEqual(mockMetadata)
622623

623624
expect(mockStore.fulfilled).toBeTruthy()

src/store.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ interface GetWithMetadataOptions {
2626

2727
interface GetWithMetadataResult {
2828
etag?: string
29-
fresh: boolean
3029
metadata: Metadata
3130
}
3231

@@ -219,12 +218,11 @@ export class Store {
219218
const metadata = getMetadataFromResponse(res)
220219
const result: GetWithMetadataResult = {
221220
etag: responseETag,
222-
fresh: false,
223221
metadata,
224222
}
225223

226224
if (res.status === 304 && requestETag) {
227-
return { data: null, ...result, fresh: true }
225+
return { data: null, ...result }
228226
}
229227

230228
if (type === undefined || type === 'text') {

0 commit comments

Comments
 (0)