Skip to content

Commit 2d2346b

Browse files
author
Josper
committed
chore: 🤖 http-svc@1.0.2
1 parent 897e97d commit 2d2346b

File tree

4 files changed

+104
-7
lines changed

4 files changed

+104
-7
lines changed

CLAUDE.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Structure
6+
7+
This is a TypeScript monorepo for **HTTP Service** - a unified HTTP request library for browser and server environments. Uses pnpm workspaces with the following key packages:
8+
9+
- `packages/http-svc/` - Main HTTP service library
10+
- `packages/middleware/` - Base middleware interfaces
11+
- `packages/server-fetch/` - Server-side fetch implementation
12+
- `packages/xhr/` - XHR-based middleware
13+
- `docs/` - VitePress documentation
14+
- `server/` - Test server (Koa-based)
15+
16+
## Development Commands
17+
18+
### Interactive Development
19+
20+
- `pnpm start` - Interactive package selector for running dev scripts
21+
- `pnpm dev` - Run development server for selected package
22+
- `pnpm build` - Build selected package
23+
24+
### Core Package (http-svc)
25+
26+
- `pnpm test` - Run Jest tests
27+
- `pnpm build` - Dual build (modern ES2018+ and legacy ES2015+)
28+
- `pnpm build:modern` - Modern ES build only
29+
- `pnpm build:legacy` - Legacy ES2015 build only
30+
31+
### Documentation
32+
33+
- `pnpm docs:dev` - Start VitePress development server
34+
- `pnpm docs:build` - Build documentation site
35+
36+
### Package Management
37+
38+
- `pnpm create` - Create new packages
39+
- `pnpm pub` - Interactive publishing workflow
40+
41+
## Architecture
42+
43+
The HTTP Service follows a **middleware-based request pipeline** pattern similar to Koa.js:
44+
45+
### Core Components
46+
47+
- **HttpService** (`/packages/http-svc/src/core.ts`) - Main service class with three control units:
48+
- `AssembleControl` - Middleware assembly and dispatch
49+
- `ConfigControl` - Per-request configuration context
50+
- `RequestControl` - Request execution management
51+
52+
### Built-in Middleware Stack
53+
54+
Located in `/packages/http-svc/src/built-in/`:
55+
56+
- `HttpSvcFetch` - Core fetch implementation
57+
- `HttpSvcSpray` - Request optimization
58+
- `HttpSvcRetry` - Retry logic
59+
- `HttpSvcCache` - Caching mechanism
60+
- `HttpSvcXsrf` - CSRF protection
61+
- Plus utility middlewares for timeout, body processing, logging
62+
63+
### Key Features
64+
65+
- Fetch API-based core with fallback to XHR
66+
- Dual environment support (browser/Node.js)
67+
- TypeScript-first with comprehensive type definitions
68+
- Extensible middleware system
69+
- Dual module builds (ESM/CJS)
70+
71+
## Build System
72+
73+
- **Build Tool**: Vite with dual-target configuration
74+
- **Output**: Modern (.mjs) and legacy (.cjs) builds for maximum compatibility
75+
- **TypeScript**: Strict mode enabled with comprehensive type checking
76+
- **Module Formats**: Both ESM and CommonJS supported
77+
78+
## Testing
79+
80+
- **Framework**: Jest with ts-jest preset
81+
- **Location**: `/packages/http-svc/src/__tests__/`
82+
- **Pattern**: `**/*.spec.ts`
83+
- Run tests with `pnpm test` in the http-svc package
84+
85+
## Code Quality
86+
87+
- **ESLint**: TypeScript configuration with Prettier integration
88+
- **Line Length**: 140 characters maximum
89+
- **Formatting**: Prettier for consistent code style

packages/http-svc/CHANGELOG.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,19 @@
2727
2828
- 弃用的功能或特性 -->
2929

30-
## [v1.0.0] - 2024-12-05
30+
## [v1.0.2] - 2025-08-13
31+
32+
### Fixed
33+
34+
-`exports` 字段中为主入口点和 legacy 入口点添加 `types` 字段
35+
- 优化init-ctx时clone `FormData` 逻辑
36+
37+
## [v1.0.1] - 2024-12-05
3138

3239
### Added
3340

3441
- change dependencies version workspaces
3542

3643
## [v1.0.0] - 2024-07-18
3744

38-
### Added
39-
40-
- release v1.0.0
45+
- Initial release

packages/http-svc/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "http-svc",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "A HTTP request service for browser and node.js",
55
"private": false,
66
"main": "dist/index.legacy.js",
@@ -10,10 +10,12 @@
1010
"exports": {
1111
"./types": "./types/index.d.ts",
1212
".": {
13+
"types": "./types/index.d.ts",
1314
"import": "./dist/index.mjs",
1415
"require": "./dist/index.cjs"
1516
},
1617
"./legacy": {
18+
"types": "./types/index.d.ts",
1719
"import": "./dist/index.legacy.esm.js",
1820
"require": "./dist/index.legacy.js"
1921
}

packages/http-svc/src/built-in/init-ctx.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ const initCtx: IMiddlewareHandler = async function (ctx, next) {
3333
if (typeof data === 'object') {
3434
if (typeof FormData !== 'undefined' && data instanceof FormData) {
3535
const form = new FormData()
36-
for (const [key, value] of data.entries()) {
36+
const entries = Array.from((data as FormData).entries())
37+
entries.forEach(([key, value]) => {
3738
form.append(key, value)
38-
}
39+
})
3940
ctx.request.data = form
4041
} else if (Object.keys(data)) {
4142
ctx.request.data = JSON.parse(JSON.stringify(data))

0 commit comments

Comments
 (0)