Skip to content

Commit 578fbc5

Browse files
committed
fix: add missing implementation for isTagManifest and isHtmlBlob type guards
1 parent ca233ef commit 578fbc5

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

src/shared/blob-types.cts

+16-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,23 @@ export type HtmlBlob = {
1010
export type BlobType = NetlifyCacheHandlerValue | TagManifest | HtmlBlob
1111

1212
export const isTagManifest = (value: BlobType): value is TagManifest => {
13-
return false
13+
return (
14+
typeof value === 'object' &&
15+
value !== null &&
16+
'revalidatedAt' in value &&
17+
typeof value.revalidatedAt === 'number' &&
18+
Object.keys(value).length === 1
19+
)
1420
}
1521

1622
export const isHtmlBlob = (value: BlobType): value is HtmlBlob => {
17-
return false
23+
return (
24+
typeof value === 'object' &&
25+
value !== null &&
26+
'html' in value &&
27+
'isFallback' in value &&
28+
typeof value.html === 'string' &&
29+
typeof value.isFallback === 'boolean' &&
30+
Object.keys(value).length === 2
31+
)
1832
}

src/shared/blob-types.test.ts

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { describe, expect, it } from 'vitest'
2+
3+
import { BlobType, HtmlBlob, isHtmlBlob, isTagManifest, TagManifest } from './blob-types.cjs'
4+
5+
describe('isTagManifest', () => {
6+
it(`returns true for TagManifest instance`, () => {
7+
const value: TagManifest = { revalidatedAt: 0 }
8+
expect(isTagManifest(value)).toBe(true)
9+
})
10+
11+
it(`returns false for non-TagManifest instance`, () => {
12+
const value: BlobType = { html: '', isFallback: false }
13+
expect(isTagManifest(value)).toBe(false)
14+
})
15+
})
16+
17+
describe('isHtmlBlob', () => {
18+
it(`returns true for HtmlBlob instance`, () => {
19+
const value: HtmlBlob = { html: '', isFallback: false }
20+
expect(isHtmlBlob(value)).toBe(true)
21+
})
22+
23+
it(`returns false for non-HtmlBlob instance`, () => {
24+
const value: BlobType = { revalidatedAt: 0 }
25+
expect(isHtmlBlob(value)).toBe(false)
26+
})
27+
})

0 commit comments

Comments
 (0)