chowbea-axios 1.0.3 β 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -209
- package/dist/lib/generator.js +6 -6
- package/oclif.manifest.json +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,244 +1,98 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://axios.chowbea.com/images/chowbea-axios.png" alt="chowbea-axios" width="100%" />
|
|
3
|
+
</p>
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
<h1 align="center">Chowbea-axios</h1>
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
<p align="center">
|
|
8
|
+
Turn your OpenAPI spec into a fully-typed Axios client. One command.
|
|
9
|
+
</p>
|
|
6
10
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
-
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://axios.chowbea.com">
|
|
13
|
+
<img src="https://img.shields.io/badge/π_Read_the_Docs-axios.chowbea.com-10b981?style=for-the-badge" alt="Documentation" />
|
|
14
|
+
</a>
|
|
15
|
+
</p>
|
|
12
16
|
|
|
13
|
-
|
|
17
|
+
<p align="center">
|
|
18
|
+
<a href="https://github.com/oddFEELING/chowbea-axios/stargazers"><img src="https://img.shields.io/github/stars/oddFEELING/chowbea-axios?style=flat-square&color=10b981" alt="GitHub stars" /></a>
|
|
19
|
+
<a href="https://www.npmjs.com/package/chowbea-axios"><img src="https://img.shields.io/npm/v/chowbea-axios?style=flat-square&color=10b981" alt="npm version" /></a>
|
|
20
|
+
<a href="https://www.npmjs.com/package/chowbea-axios"><img src="https://img.shields.io/npm/dm/chowbea-axios?style=flat-square&color=10b981" alt="npm downloads" /></a>
|
|
21
|
+
<a href="https://github.com/oddFEELING/chowbea-axios/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-10b981?style=flat-square" alt="license" /></a>
|
|
22
|
+
</p>
|
|
14
23
|
|
|
15
|
-
|
|
16
|
-
- **Retry logic**: Network operations retry 3x with exponential backoff
|
|
17
|
-
- **Caching**: Skips regeneration when spec hasn't changed
|
|
18
|
-
- **Atomic writes**: Generation never leaves files in a partial state
|
|
19
|
-
- **Graceful shutdown**: Watch mode preserves cache on interruption
|
|
20
|
-
- **Result-based errors**: API calls return `{ data, error }` instead of throwing
|
|
21
|
-
- **Error normalization**: Extracts messages from various API response formats
|
|
22
|
-
- **Local spec support**: Use local OpenAPI files instead of remote endpoints
|
|
23
|
-
- **Auth headers**: Configure headers with env var interpolation for protected specs
|
|
24
|
+
---
|
|
24
25
|
|
|
25
|
-
##
|
|
26
|
-
|
|
27
|
-
- Node `>=18` (per `package.json`)
|
|
28
|
-
- `init` installs `axios` into your project automatically
|
|
29
|
-
|
|
30
|
-
```bash
|
|
31
|
-
# Global install
|
|
32
|
-
npm install -g chowbea-axios
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
Or use without installing:
|
|
26
|
+
## Quick Start
|
|
36
27
|
|
|
37
28
|
```bash
|
|
38
|
-
#
|
|
29
|
+
# Initialize and configure
|
|
39
30
|
npx chowbea-axios init
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
## Quick Start (First Run)
|
|
43
|
-
|
|
44
|
-
```bash
|
|
45
|
-
# 1) Initialize in your project (creates config + base client files)
|
|
46
|
-
chowbea-axios init
|
|
47
|
-
|
|
48
|
-
# 2) Fetch spec and generate types + operations
|
|
49
|
-
chowbea-axios fetch
|
|
50
31
|
|
|
51
|
-
#
|
|
52
|
-
chowbea-axios
|
|
32
|
+
# Fetch spec and generate client
|
|
33
|
+
npx chowbea-axios fetch
|
|
53
34
|
```
|
|
54
35
|
|
|
55
|
-
Then
|
|
36
|
+
Then import and use:
|
|
56
37
|
|
|
57
38
|
```typescript
|
|
58
|
-
import { api } from "./
|
|
39
|
+
import { api } from "./services/api/api.client";
|
|
59
40
|
|
|
60
|
-
|
|
61
|
-
const { data, error } = await api.get("/users/{id}", { id: "123" });
|
|
41
|
+
const { data, error } = await api.op.getUserById({ id: "123" });
|
|
62
42
|
|
|
63
|
-
if (error)
|
|
64
|
-
console.error(error.message);
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
43
|
+
if (error) return console.error(error.message);
|
|
67
44
|
|
|
68
|
-
//
|
|
69
|
-
console.log(data.name);
|
|
45
|
+
console.log(data.name); // β¨ Fully typed
|
|
70
46
|
```
|
|
71
47
|
|
|
72
|
-
##
|
|
73
|
-
|
|
74
|
-
`api.config.toml` is created by `init` and is the main source of truth:
|
|
75
|
-
|
|
76
|
-
```toml
|
|
77
|
-
api_endpoint = "http://localhost:3000/docs/swagger/json"
|
|
78
|
-
poll_interval_ms = 10000
|
|
79
|
-
# spec_file = "./openapi.json"
|
|
80
|
-
|
|
81
|
-
[output]
|
|
82
|
-
folder = "app/services/api"
|
|
83
|
-
|
|
84
|
-
[instance]
|
|
85
|
-
base_url_env = "VITE_API_URL"
|
|
86
|
-
token_key = "auth-token"
|
|
87
|
-
with_credentials = true
|
|
88
|
-
timeout = 30000
|
|
48
|
+
## Why chowbea-axios?
|
|
89
49
|
|
|
90
|
-
|
|
91
|
-
|
|
50
|
+
- **Zero manual types** β Generated directly from your OpenAPI spec
|
|
51
|
+
- **Full autocomplete** β Every endpoint, parameter, and response
|
|
52
|
+
- **Result-based errors** β `{ data, error }` instead of try/catch
|
|
53
|
+
- **Watch mode** β Auto-regenerate when your spec changes
|
|
92
54
|
|
|
93
|
-
|
|
94
|
-
debug = false
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
- `api_endpoint`: Remote OpenAPI endpoint used by `fetch` and `watch`.
|
|
98
|
-
- `spec_file`: Optional local spec path; if set, it overrides `api_endpoint` for generation.
|
|
99
|
-
- `poll_interval_ms`: Watch interval if `--interval` is not provided.
|
|
100
|
-
- `[output].folder`: Where generated files go (relative to project root).
|
|
101
|
-
- `[instance].base_url_env`: Name of the env var read at runtime in `api.instance.ts`.
|
|
102
|
-
- `[instance].token_key`: localStorage key used by the axios instance.
|
|
103
|
-
- `[instance].with_credentials`: Adds cookies/credentials to requests.
|
|
104
|
-
- `[instance].timeout`: Axios request timeout (ms).
|
|
105
|
-
- `[fetch].headers`: Extra headers for remote fetch; values can use `$ENV` or `${ENV}`.
|
|
106
|
-
- `[watch].debug`: Enables verbose cycle logs.
|
|
107
|
-
|
|
108
|
-
## Generated Files & Editability
|
|
55
|
+
## What Gets Generated
|
|
109
56
|
|
|
110
57
|
```
|
|
111
|
-
|
|
112
|
-
βββ _internal/
|
|
113
|
-
β βββ .api-cache.json # Cache metadata
|
|
114
|
-
β βββ openapi.json # Cached spec
|
|
58
|
+
services/api/
|
|
115
59
|
βββ _generated/
|
|
116
|
-
β βββ api.
|
|
117
|
-
β βββ api.
|
|
118
|
-
βββ api.
|
|
119
|
-
βββ api.instance.ts
|
|
120
|
-
|
|
121
|
-
βββ api.client.ts # Typed API client (editable, generated once)
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
- `_internal` and `_generated` are always overwritten during generation.
|
|
125
|
-
- The root files are generated once and safe to edit.
|
|
126
|
-
|
|
127
|
-
## Client Usage & Error Handling
|
|
128
|
-
|
|
129
|
-
All client calls return `{ data, error }` instead of throwing. This keeps error handling explicit and predictable.
|
|
130
|
-
|
|
131
|
-
```typescript
|
|
132
|
-
import { api } from "./app/services/api/api.client";
|
|
133
|
-
|
|
134
|
-
// Result-based call
|
|
135
|
-
const { data, error } = await api.post("/users", { name: "Ada" });
|
|
136
|
-
|
|
137
|
-
if (error) {
|
|
138
|
-
console.error(error.message);
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
console.log(data.id);
|
|
60
|
+
β βββ api.types.ts # All TypeScript types
|
|
61
|
+
β βββ api.operations.ts # Typed operation methods
|
|
62
|
+
βββ api.client.ts # Your API client (editable)
|
|
63
|
+
βββ api.instance.ts # Axios instance (editable)
|
|
64
|
+
βββ api.helpers.ts # Type helpers (editable)
|
|
143
65
|
```
|
|
144
66
|
|
|
145
|
-
##
|
|
146
|
-
|
|
147
|
-
Use helpers to extract request/response types and schema models when you want explicit type control in app code.
|
|
148
|
-
|
|
149
|
-
**Base helpers**
|
|
150
|
-
- `Paths`: Union of all OpenAPI path strings.
|
|
151
|
-
- `HttpMethod`: `"get" | "post" | "put" | "delete" | "patch"`.
|
|
152
|
-
- `Expand<T>`: Expands a single level of a type for better intellisense.
|
|
153
|
-
- `ExpandRecursively<T>`: Expands nested types for full intellisense.
|
|
154
|
-
|
|
155
|
-
**Path-based helpers**
|
|
156
|
-
- `ApiRequestBody<P, M>`: Request body type for a path + method.
|
|
157
|
-
- `ApiResponseData<P, M, Status?>`: Response body type for a path + method.
|
|
158
|
-
- `ApiPathParams<P>`: Path params extracted from `{param}` segments.
|
|
159
|
-
- `ApiQueryParams<P, M>`: Query params type for a path + method.
|
|
160
|
-
- `ApiStatusCodes<P, M>`: Available status codes for a path + method.
|
|
67
|
+
## Commands
|
|
161
68
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
69
|
+
| Command | Description |
|
|
70
|
+
| ------- | ----------- |
|
|
71
|
+
| `init` | Interactive setup β creates config and base files |
|
|
72
|
+
| `fetch` | Fetch spec from endpoint and generate types |
|
|
73
|
+
| `generate` | Generate from cached/local spec |
|
|
74
|
+
| `watch` | Watch for spec changes and auto-regenerate |
|
|
75
|
+
| `status` | Show current config and cache status |
|
|
76
|
+
| `validate` | Validate your OpenAPI spec |
|
|
77
|
+
| `diff` | Compare specs and show changes |
|
|
166
78
|
|
|
167
|
-
|
|
168
|
-
- `ServerModel<ModelName>`: Extract schema types from OpenAPI components.
|
|
79
|
+
---
|
|
169
80
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
ExpandRecursively,
|
|
176
|
-
ApiRequestBody,
|
|
177
|
-
ApiResponseData,
|
|
178
|
-
ApiPathParams,
|
|
179
|
-
ApiQueryParams,
|
|
180
|
-
ApiStatusCodes,
|
|
181
|
-
ServerRequestBody,
|
|
182
|
-
ServerRequestParams,
|
|
183
|
-
ServerResponseType,
|
|
184
|
-
ServerModel,
|
|
185
|
-
} from "./app/services/api/api.helpers";
|
|
186
|
-
|
|
187
|
-
// Path-based helpers
|
|
188
|
-
type CreateUserInput = ApiRequestBody<"/users", "post">;
|
|
189
|
-
type UserResponse = ApiResponseData<"/users/{id}", "get">;
|
|
190
|
-
type UserPath = ApiPathParams<"/users/{id}">;
|
|
191
|
-
type UserQuery = ApiQueryParams<"/users", "get">;
|
|
192
|
-
type UserStatus = ApiStatusCodes<"/users/{id}", "get">;
|
|
193
|
-
|
|
194
|
-
// Operation-based helpers (uses operationId keys)
|
|
195
|
-
type CreateUserInputByOp = ServerRequestBody<"createUser">;
|
|
196
|
-
type UserParamsByOp = ServerRequestParams<"getUserById">;
|
|
197
|
-
type UserResponseByOp = ServerResponseType<"getUserById">;
|
|
198
|
-
|
|
199
|
-
// Schema helpers
|
|
200
|
-
type UserModel = ServerModel<"User">;
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
## Path-Based vs Operation-Based Approaches
|
|
204
|
-
|
|
205
|
-
**Path-based** is great for quick usage when you know the endpoint path:
|
|
206
|
-
|
|
207
|
-
```typescript
|
|
208
|
-
// Calls by path template
|
|
209
|
-
const { data, error } = await api.get("/users/{id}", { id: "123" });
|
|
210
|
-
```
|
|
81
|
+
<p align="center">
|
|
82
|
+
<a href="https://axios.chowbea.com">
|
|
83
|
+
<strong>β View full documentation</strong>
|
|
84
|
+
</a>
|
|
85
|
+
</p>
|
|
211
86
|
|
|
212
|
-
|
|
87
|
+
## β Support
|
|
213
88
|
|
|
214
|
-
|
|
215
|
-
// Calls by operationId (generated in api.operations.ts)
|
|
216
|
-
const { data, error } = await api.op.getUserById({ id: "123" });
|
|
217
|
-
```
|
|
89
|
+
If chowbea-axios helps you ship faster, consider giving it a star! It helps others discover the project and motivates continued development.
|
|
218
90
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
| Command | Purpose | Key flags |
|
|
226
|
-
| --- | --- | --- |
|
|
227
|
-
| `chowbea-axios init` | Interactive setup. Prompts for API endpoint, output folder, and package manager. | `--force`, `--skip-scripts`, `--skip-client`, `--skip-concurrent` |
|
|
228
|
-
| `chowbea-axios fetch` | Fetch remote spec and generate types/operations. | `-c, --config`, `-e, --endpoint`, `-s, --spec-file`, `-f, --force`, `-n, --dry-run`, `--types-only`, `--operations-only` |
|
|
229
|
-
| `chowbea-axios generate` | Generate types/operations from the cached spec (or a local file). | `-c, --config`, `-s, --spec-file`, `-n, --dry-run`, `--types-only`, `--operations-only` |
|
|
230
|
-
| `chowbea-axios watch` | Watch for spec changes and regenerate on a timer. | `-c, --config`, `-i, --interval`, `-d, --debug` |
|
|
231
|
-
| `chowbea-axios status` | Show config + cache + generated file status. | `-c, --config` |
|
|
232
|
-
| `chowbea-axios validate` | Validate the OpenAPI spec structure. | `-c, --config`, `-s, --spec`, `--strict` |
|
|
233
|
-
| `chowbea-axios diff` | Compare cached spec with a new spec (remote or local). | `-c, --config`, `-s, --spec` |
|
|
234
|
-
|
|
235
|
-
## Tips & Troubleshooting
|
|
236
|
-
|
|
237
|
-
- Re-run `fetch` whenever your API spec changes.
|
|
238
|
-
- Use `watch` during local dev to keep types up to date.
|
|
239
|
-
- Delete `app/services/api/_internal` to reset cache if types seem stale.
|
|
240
|
-
- If scripts are missing, re-run `init` (or add them manually).
|
|
241
|
-
- If headers use `$ENV`/`${ENV}`, make sure those env vars are set.
|
|
91
|
+
<p align="center">
|
|
92
|
+
<a href="https://github.com/oddFEELING/chowbea-axios">
|
|
93
|
+
<img src="https://img.shields.io/badge/β_Star_on_GitHub-oddFEELING%2Fchowbea--axios-10b981?style=for-the-badge&logo=github" alt="Star on GitHub" />
|
|
94
|
+
</a>
|
|
95
|
+
</p>
|
|
242
96
|
|
|
243
97
|
## License
|
|
244
98
|
|
package/dist/lib/generator.js
CHANGED
|
@@ -670,18 +670,18 @@ export type ServerRequestBody<OpId extends keyof operations> = ExpandRecursively
|
|
|
670
670
|
export type ServerRequestParams<OpId extends keyof operations> = ExpandRecursively<
|
|
671
671
|
operations[OpId] extends { parameters: infer P }
|
|
672
672
|
? P extends { path?: infer Path; query?: infer Query }
|
|
673
|
-
? (Path extends Record<string, unknown> ? { path: Path } :
|
|
674
|
-
(Query extends Record<string, unknown> ? { query?: Query } :
|
|
673
|
+
? (Path extends Record<string, unknown> ? { path: Path } : {}) &
|
|
674
|
+
(Query extends Record<string, unknown> ? { query?: Query } : {})
|
|
675
675
|
: P extends { path?: infer Path }
|
|
676
676
|
? Path extends Record<string, unknown>
|
|
677
677
|
? { path: Path }
|
|
678
|
-
:
|
|
678
|
+
: {}
|
|
679
679
|
: P extends { query?: infer Query }
|
|
680
680
|
? Query extends Record<string, unknown>
|
|
681
681
|
? { query?: Query }
|
|
682
|
-
:
|
|
683
|
-
:
|
|
684
|
-
:
|
|
682
|
+
: {}
|
|
683
|
+
: {}
|
|
684
|
+
: {}
|
|
685
685
|
>;
|
|
686
686
|
|
|
687
687
|
/**
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chowbea-axios",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "Type-safe axios client that makes api requests a breeze",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"codegen",
|
|
56
56
|
"cli"
|
|
57
57
|
],
|
|
58
|
-
"homepage": "https://
|
|
58
|
+
"homepage": "https://axios.chowbea.com",
|
|
59
59
|
"bugs": {
|
|
60
60
|
"url": "https://github.com/oddFEELING/chowbea-axios/issues"
|
|
61
61
|
},
|