This commit is contained in:
2025-07-28 15:12:11 +00:00
parent 8f5c88b47e
commit 7dcc5f3fe2
13 changed files with 175 additions and 78 deletions

40
ts/core_base/response.ts Normal file
View File

@@ -0,0 +1,40 @@
import * as types from './types.js';
/**
* Abstract Core Response class that provides a fetch-like API
*/
export abstract class CoreResponse<T = any> implements types.IAbstractResponse<T> {
protected consumed = false;
// Public properties
public abstract readonly ok: boolean;
public abstract readonly status: number;
public abstract readonly statusText: string;
public abstract readonly headers: types.AbstractHeaders;
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>;
}