diff --git a/readme.plan.md b/readme.plan.md deleted file mode 100644 index 4f0b42a..0000000 --- a/readme.plan.md +++ /dev/null @@ -1,53 +0,0 @@ -# Smartrequest Refactoring Plan - -Command to reread CLAUDE.md: `cat /home/philkunz/.claude/CLAUDE.md` - -## Objective -Refactor smartrequest to use native fetch-like API with a streamlined core that supports unix sockets and keep-alive. - -## Architecture Overview -- Rename `legacy/` to `core/` and remove "smartrequest." prefix from filenames -- Create a modern Response class similar to fetch API -- Use core as foundation for modern API, not as legacy adapter -- Maintain unix socket and keep-alive support - -## Task Checklist - -- [x] Reread /home/philkunz/.claude/CLAUDE.md -- [x] Create ts/core directory structure with request.ts, types.ts, and plugins.ts -- [x] Migrate core request logic from legacy to core/request.ts -- [x] Create modern Response class with fetch-like API -- [x] Update modern API to use new core module -- [x] Create legacy adapter for backward compatibility -- [x] Update exports in ts/index.ts -- [x] Run tests and fix any issues -- [x] Clean up old legacy files - -## Implementation Details - -### Core Module Structure -``` -ts/core/ -├── request.ts # Core HTTP/HTTPS request logic with unix socket support -├── types.ts # Core interfaces and types -├── plugins.ts # Dependencies (http, https, agentkeepalive, etc.) -└── response.ts # Modern Response class -``` - -### Response Class API -The new Response class will provide fetch-like methods: -- `json()`: Promise - Parse response as JSON -- `text()`: Promise - Get response as text -- `arrayBuffer()`: Promise - Get response as ArrayBuffer -- `stream()`: ReadableStream - Get response as stream -- `ok`: boolean - Status is 2xx -- `status`: number - HTTP status code -- `statusText`: string - HTTP status text -- `headers`: Headers - Response headers - -### Migration Strategy -1. Move core request logic without breaking changes -2. Create Response wrapper that provides modern API -3. Update SmartRequestClient to use new core -4. Add legacy adapter for backward compatibility -5. Ensure all tests pass throughout migration \ No newline at end of file diff --git a/ts/core/index.ts b/ts/core/index.ts index 6b0f9cd..9878a50 100644 --- a/ts/core/index.ts +++ b/ts/core/index.ts @@ -1,4 +1,4 @@ // Core exports export * from './types.js'; export * from './response.js'; -export { SmartRequest, request, coreRequest, isUnixSocket, parseUnixSocketUrl } from './request.js'; \ No newline at end of file +export { SmartRequest, isUnixSocket, parseUnixSocketUrl } from './request.js'; \ No newline at end of file diff --git a/ts/core/request.ts b/ts/core/request.ts index dd6b2e9..7adceef 100644 --- a/ts/core/request.ts +++ b/ts/core/request.ts @@ -177,29 +177,6 @@ export class SmartRequest { } } -/** - * Core request function that handles all HTTP/HTTPS requests - * @deprecated Use SmartRequest class instead - */ -export async function coreRequest( - urlArg: string, - optionsArg: types.ICoreRequestOptions = {}, - requestDataFunc: ((req: plugins.http.ClientRequest) => void) | null = null -): Promise { - const request = new SmartRequest(urlArg, optionsArg, requestDataFunc); - return request.executeCore(); -} - -/** - * Modern request function that returns a SmartResponse - */ -export async function request( - urlArg: string, - optionsArg: types.ICoreRequestOptions = {} -): Promise { - return SmartRequest.create(urlArg, optionsArg); -} - /** * Convenience exports for backward compatibility */ diff --git a/ts/legacy/adapter.ts b/ts/legacy/adapter.ts index 0f8019b..fbc1491 100644 --- a/ts/legacy/adapter.ts +++ b/ts/legacy/adapter.ts @@ -72,7 +72,8 @@ export async function request( responseStreamArg = false, requestDataFunc?: (req: plugins.http.ClientRequest) => void ): Promise { - const stream = await core.coreRequest(urlArg, optionsArg, requestDataFunc); + const smartRequest = new core.SmartRequest(urlArg, optionsArg, requestDataFunc); + const stream = await smartRequest.executeCore(); if (responseStreamArg) { // For stream responses, just cast and return diff --git a/ts/modern/smartrequestclient.ts b/ts/modern/smartrequestclient.ts index 244c863..dec04a0 100644 --- a/ts/modern/smartrequestclient.ts +++ b/ts/modern/smartrequestclient.ts @@ -1,4 +1,4 @@ -import { request, SmartResponse, type ICoreRequestOptions } from '../core/index.js'; +import { SmartRequest, SmartResponse, type ICoreRequestOptions } from '../core/index.js'; import * as plugins from '../core/plugins.js'; import type { HttpMethod, ResponseType, FormField } from './types/common.js'; @@ -308,7 +308,7 @@ export class SmartRequestClient { for (let attempt = 0; attempt <= this._retries; attempt++) { try { - const response = await request(this._url, this._options); + const response = await SmartRequest.create(this._url, this._options); return response as SmartResponse; } catch (error) { lastError = error as Error;