| 
									
										
										
										
											2025-07-28 15:12:11 +00:00
										 |  |  | import * as types from './types.js'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Abstract Core Response class that provides a fetch-like API | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2025-07-28 22:37:36 +00:00
										 |  |  | export abstract class CoreResponse<T = any> implements types.ICoreResponse<T> { | 
					
						
							| 
									
										
										
										
											2025-07-28 15:12:11 +00:00
										 |  |  |   protected consumed = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Public properties
 | 
					
						
							|  |  |  |   public abstract readonly ok: boolean; | 
					
						
							|  |  |  |   public abstract readonly status: number; | 
					
						
							|  |  |  |   public abstract readonly statusText: string; | 
					
						
							| 
									
										
										
										
											2025-07-28 22:37:36 +00:00
										 |  |  |   public abstract readonly headers: types.Headers; | 
					
						
							| 
									
										
										
										
											2025-07-28 15:12:11 +00:00
										 |  |  |   public abstract readonly url: string; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * Ensures the body can only be consumed once | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   protected ensureNotConsumed(): void { | 
					
						
							|  |  |  |     if (this.consumed) { | 
					
						
							|  |  |  |       throw new Error('Body has already been consumed'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     this.consumed = true; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * Parse response as JSON | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   abstract json(): Promise<T>; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * Get response as text | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   abstract text(): Promise<string>; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * Get response as ArrayBuffer | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   abstract arrayBuffer(): Promise<ArrayBuffer>; | 
					
						
							| 
									
										
										
										
											2025-08-18 00:21:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-28 22:50:12 +00:00
										 |  |  |   /** | 
					
						
							|  |  |  |    * Get response as a web-style ReadableStream | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   abstract stream(): ReadableStream<Uint8Array> | null; | 
					
						
							| 
									
										
										
										
											2025-08-19 01:20:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * Get response as a Node.js stream (throws in browser) | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   abstract streamNode(): NodeJS.ReadableStream | never; | 
					
						
							| 
									
										
										
										
											2025-08-18 00:21:14 +00:00
										 |  |  | } |