Skip to content

Commit cf01338

Browse files
committed
Fix Bun type conflicts: use FetchFn with explicit FetchResponse interface
1 parent a79c03e commit cf01338

File tree

5 files changed

+23
-15
lines changed

5 files changed

+23
-15
lines changed

src/scraper/types.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,24 @@
44
* Types for URL metadata scraping.
55
*/
66

7+
/**
8+
* Minimal response interface that both standard Response and Bun's Response satisfy.
9+
* Avoids Bun's BunResponseOverride type conflicts.
10+
*/
11+
interface FetchResponse {
12+
readonly ok: boolean
13+
readonly status: number
14+
readonly headers: { get(name: string): string | null }
15+
text(): Promise<string>
16+
json(): Promise<unknown>
17+
arrayBuffer(): Promise<ArrayBuffer>
18+
}
19+
720
/**
821
* Fetch function type for dependency injection.
22+
* Uses explicit interface to avoid Bun type conflicts.
923
*/
10-
export type FetchFn = typeof fetch
24+
export type FetchFn = (url: string, init?: RequestInit) => Promise<FetchResponse>
1125

1226
/**
1327
* Configuration for the scraper.

src/search/openlibrary.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,13 @@
77

88
import { generateCacheKey } from '../caching/key'
99
import type { ResponseCache } from '../caching/types'
10-
import { type HttpResponse, httpFetch } from '../http'
10+
import { httpFetch } from '../http'
11+
import type { FetchFn } from '../scraper/types'
1112
import type { OpenLibraryResult } from './types'
1213
import { DEFAULT_TIMEOUT, DEFAULT_USER_AGENT } from './types'
1314

1415
const SEARCH_API = 'https://openlibrary.org/search.json'
1516

16-
/**
17-
* Fetch function type - returns HttpResponse which standard Response satisfies.
18-
*/
19-
type FetchFn = (url: string, init?: RequestInit) => Promise<HttpResponse>
20-
2117
/**
2218
* Configuration for Open Library search.
2319
*/

src/search/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
import type { ResponseCache } from '../caching/types'
9+
import type { FetchFn } from '../scraper/types'
910

1011
/**
1112
* Entity type categories for resolution.
@@ -182,7 +183,7 @@ export interface ResolverConfig {
182183
/** Request timeout in milliseconds (default: 30000) */
183184
timeout?: number | undefined
184185
/** Custom fetch function (for testing) */
185-
customFetch?: ((url: string, init?: RequestInit) => Promise<Response>) | undefined
186+
customFetch?: FetchFn | undefined
186187
}
187188

188189
/**

src/search/wikidata.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
import { generateCacheKey } from '../caching/key'
99
import type { ResponseCache } from '../caching/types'
10-
import { type HttpResponse, httpFetch } from '../http'
10+
import { httpFetch } from '../http'
11+
import type { FetchFn } from '../scraper/types'
1112
import type { EntityType, ExternalIdType, WikidataResult } from './types'
1213
import {
1314
DEFAULT_TIMEOUT,
@@ -19,11 +20,6 @@ import {
1920

2021
const SPARQL_ENDPOINT = 'https://query.wikidata.org/sparql'
2122

22-
/**
23-
* Fetch function type - returns HttpResponse which standard Response satisfies.
24-
*/
25-
type FetchFn = (url: string, init?: RequestInit) => Promise<HttpResponse>
26-
2723
/**
2824
* Configuration for Wikidata search.
2925
*/

src/types/place-lookup.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Types for looking up places and getting coordinates.
55
*/
66

7+
import type { FetchFn } from '../scraper/types'
78
import type { ClassifiedActivity } from './classifier'
89

910
export type PlaceLookupSource = 'google_maps_url' | 'places_api' | 'geocoding_api'
@@ -50,7 +51,7 @@ export interface PlaceLookupConfig {
5051
readonly regionBias?: string | undefined
5152
readonly defaultCountry?: string | undefined
5253
/** Custom fetch function for testing */
53-
readonly fetch?: typeof fetch | undefined
54+
readonly fetch?: FetchFn | undefined
5455
}
5556

5657
export interface PlaceLookupResult {

0 commit comments

Comments
 (0)