Skip to content

Commit c0832df

Browse files
authored
Merge pull request #89 from xarlizard/dev
v2.0.0: Major API Refactor - Unified Options Array & Auto-Generated Function Names
2 parents 5d33cb8 + 95a1db0 commit c0832df

File tree

11 files changed

+3101
-1506
lines changed

11 files changed

+3101
-1506
lines changed

.eslintrc.json

Lines changed: 0 additions & 22 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,91 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [2.0.0] - 2025-12-14
9+
10+
### ⚠️ Breaking Changes
11+
12+
- **Removed legacy API support** - The deprecated `requiredProps`, `defaultProps`, `pathParams`, and `queryParams` options have been completely removed. You must use the unified `options` array instead.
13+
- **Path params are now auto-extracted** - Path parameters are automatically extracted from the endpoint string (e.g., `/users/:userId`). You no longer need to define them.
14+
- **Function names are auto-generated** - Function names are now automatically generated from the HTTP method:
15+
- `GET``fetchData`
16+
- `POST``postData`
17+
- `PUT``putData`
18+
- `PATCH``patchData`
19+
- `DELETE``deleteData`
20+
- **New function signature** - Functions now accept grouped parameters:
21+
```typescript
22+
fetchData({
23+
path: { userId: "123" },
24+
header: { Authorization: "Bearer token" },
25+
body: { name: "John" },
26+
query: { lang: "en" }
27+
})
28+
```
29+
- **Endpoint is now string only** - The `endpoint` property no longer accepts functions, only strings.
30+
31+
### Added
32+
33+
- **Unified `options` array configuration** - New unified way to define API parameters using a single `options` array
34+
- `ParamLocation` type with support for `"query"`, `"header"`, and `"body"` locations (path params are auto-extracted)
35+
- `ApiParam<T>` interface for type-safe parameter definitions
36+
- `param<T>()` helper function for improved TypeScript type inference
37+
- Support for header parameters via the options array
38+
- Support for body parameters via the options array
39+
- **Automatic path parameter extraction** - Path params are automatically extracted from endpoint strings (e.g., `/users/:userId`)
40+
- **Automatic function name generation** - Function names are auto-generated from HTTP methods
41+
- **Grouped parameter structure** - Parameters are now passed grouped by location (`path`, `header`, `body`, `query`)
42+
- **Simplified parameter requirements** - Options with `defaultValue` are always optional (implicit), reducing boilerplate
43+
44+
### Changed
45+
46+
- Improved type inference for parameter values using the `valueType` property in `ApiParam`
47+
- Better organization of parameter configuration - each parameter is now defined once with all its properties
48+
- Function calls now use grouped parameters for better clarity and organization
49+
50+
### Example Migration
51+
52+
**Before (v1.x):**
53+
```typescript
54+
const useGetUser = createApiHook({
55+
method: "GET",
56+
baseURL: "https://api.example.com",
57+
endpoint: "/users/:userId",
58+
requiredProps: ["userId"],
59+
defaultProps: { lang: "en_US" },
60+
pathParams: ["userId"],
61+
queryParams: ["lang"],
62+
});
63+
64+
// Usage
65+
fetchData({ userId: "123", lang: "es_ES" });
66+
```
67+
68+
**After (v2.0.0):**
69+
```typescript
70+
const useGetUser = createApiHook({
71+
method: "GET",
72+
baseURL: "https://api.example.com",
73+
endpoint: "/users/:userId",
74+
// Path params are automatically extracted from endpoint
75+
options: [
76+
{ key: "lang", location: "query", defaultValue: "en_US" },
77+
],
78+
});
79+
80+
// Usage with grouped params
81+
fetchData({
82+
path: { userId: "123" },
83+
query: { lang: "es_ES" }
84+
});
85+
```
86+
87+
**Key Changes:**
88+
- Path params are automatically extracted from endpoint - no need to define them
89+
- Function names are auto-generated (GET→`fetchData`, POST→`postData`, etc.)
90+
- Parameters are grouped by location in function calls
91+
- Options with `defaultValue` are optional (implicit)
92+
893
## [1.0.2] - 2025-08-05
994

1095
### Added

0 commit comments

Comments
 (0)