From 0459622c437f19cb81301ac04d625926cf066eb5 Mon Sep 17 00:00:00 2001 From: Casey Collier Date: Sun, 20 Jul 2025 16:15:36 -0400 Subject: [PATCH] Fix streaming methods to support baseURL resolution - Extract URL resolution logic into resolveUrl() helper method - Fix stream() and streamJSON() to use baseURL for relative URLs - Prevents 'Failed to parse URL' errors when using relative paths - Bump version to 0.1.3 --- package.json | 2 +- src/core/typed-fetch.ts | 14 +++++++++----- website/package.json | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 4797167..6a702d5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@catalystlabs/typedfetch", - "version": "0.1.2", + "version": "0.1.3", "description": "Type-safe HTTP client that doesn't suck - Fetch for humans who have stuff to build", "type": "module", "main": "./dist/index.js", diff --git a/src/core/typed-fetch.ts b/src/core/typed-fetch.ts index 15e3357..ab5fc76 100644 --- a/src/core/typed-fetch.ts +++ b/src/core/typed-fetch.ts @@ -151,19 +151,22 @@ export class RevolutionaryTypedFetch { return this.request('DELETE', url, options) } - private async request(method: string, url: string, options: RequestInit = {}): Promise<{ data: T; response: Response }> { + private resolveUrl(url: string): string { // Use baseURL from config or instance const baseURL = this.config.request.baseURL || this.baseURL // Construct full URL - let fullUrl: string if (url.startsWith('http')) { - fullUrl = url + return url } else if (baseURL) { - fullUrl = new URL(url, baseURL).toString() + return new URL(url, baseURL).toString() } else { throw new Error(`Relative URL "${url}" requires a baseURL to be set`) } + } + + private async request(method: string, url: string, options: RequestInit = {}): Promise<{ data: T; response: Response }> { + const fullUrl = this.resolveUrl(url) const cacheKey = `${method}:${fullUrl}` const startTime = performance.now() let cached = false @@ -378,7 +381,8 @@ export class RevolutionaryTypedFetch { // Streaming support async stream(url: string): Promise { - const response = await fetch(url) + const fullUrl = this.resolveUrl(url) + const response = await fetch(fullUrl) if (!response.body) throw new Error('No response body') return response.body } diff --git a/website/package.json b/website/package.json index cd3d313..0167992 100644 --- a/website/package.json +++ b/website/package.json @@ -9,7 +9,7 @@ "preview": "vite preview" }, "dependencies": { - "@catalystlabs/typedfetch": "^0.1.1", + "@catalystlabs/typedfetch": "^0.1.2", "@mantine/code-highlight": "^8.0.0", "@mantine/core": "^8.0.0", "@mantine/hooks": "^8.0.0",