update
This commit is contained in:
@@ -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<T> - Parse response as JSON
|
||||
- `text()`: Promise<string> - Get response as text
|
||||
- `arrayBuffer()`: Promise<ArrayBuffer> - 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
|
@@ -1,4 +1,4 @@
|
||||
// Core exports
|
||||
export * from './types.js';
|
||||
export * from './response.js';
|
||||
export { SmartRequest, request, coreRequest, isUnixSocket, parseUnixSocketUrl } from './request.js';
|
||||
export { SmartRequest, isUnixSocket, parseUnixSocketUrl } from './request.js';
|
@@ -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<plugins.http.IncomingMessage> {
|
||||
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<SmartResponse> {
|
||||
return SmartRequest.create(urlArg, optionsArg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience exports for backward compatibility
|
||||
*/
|
||||
|
@@ -72,7 +72,8 @@ export async function request(
|
||||
responseStreamArg = false,
|
||||
requestDataFunc?: (req: plugins.http.ClientRequest) => void
|
||||
): Promise<core.IExtendedIncomingMessage> {
|
||||
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
|
||||
|
@@ -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<T = any> {
|
||||
|
||||
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<R>;
|
||||
} catch (error) {
|
||||
lastError = error as Error;
|
||||
|
Reference in New Issue
Block a user