@nuxx/torn-fetch 0.3.0 → 1.0.0
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 +46 -29
- package/dist/index.d.ts +1191 -11
- package/dist/index.js +1 -1
- package/package.json +23 -6
package/README.md
CHANGED
|
@@ -12,18 +12,35 @@ A TypeScript wrapper around `openapi-fetch` that provides a better developer exp
|
|
|
12
12
|
## Installation
|
|
13
13
|
|
|
14
14
|
```bash
|
|
15
|
-
npm install @nuxx/
|
|
15
|
+
npm install @nuxx/torn-fetch
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
+
## Migration from v0.x
|
|
19
|
+
|
|
20
|
+
If you're upgrading from v0.x, the main export has been renamed from `useTornFetch` to `tornFetch`. The old name still works in v1.x with a deprecation warning, but will be removed in v2.0.0.
|
|
21
|
+
|
|
22
|
+
**Migration:**
|
|
23
|
+
```typescript
|
|
24
|
+
// Old (v0.x)
|
|
25
|
+
import { useTornFetch } from '@nuxx/torn-fetch'
|
|
26
|
+
const data = await useTornFetch(apiKey, path)
|
|
27
|
+
|
|
28
|
+
// New (v1.0+)
|
|
29
|
+
import { tornFetch } from '@nuxx/torn-fetch'
|
|
30
|
+
const data = await tornFetch(apiKey, path)
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The function signature and behavior are identical.
|
|
34
|
+
|
|
18
35
|
## Usage
|
|
19
36
|
|
|
20
37
|
### Basic Usage
|
|
21
38
|
|
|
22
39
|
```typescript
|
|
23
|
-
import {
|
|
40
|
+
import { tornFetch } from '@nuxx/torn-fetch'
|
|
24
41
|
|
|
25
42
|
try {
|
|
26
|
-
const userAttacks = await
|
|
43
|
+
const userAttacks = await tornFetch(
|
|
27
44
|
'your-api-key',
|
|
28
45
|
'/user/attacks'
|
|
29
46
|
)
|
|
@@ -34,10 +51,10 @@ try {
|
|
|
34
51
|
```
|
|
35
52
|
|
|
36
53
|
```typescript
|
|
37
|
-
import {
|
|
54
|
+
import { tornFetch } from '@nuxx/torn-fetch'
|
|
38
55
|
|
|
39
56
|
// Use with path parameters
|
|
40
|
-
const attacks = await
|
|
57
|
+
const attacks = await tornFetch(
|
|
41
58
|
'your-api-key',
|
|
42
59
|
'/faction/{id}/chain',
|
|
43
60
|
{
|
|
@@ -49,10 +66,10 @@ const attacks = await useTornFetch(
|
|
|
49
66
|
```
|
|
50
67
|
|
|
51
68
|
```typescript
|
|
52
|
-
import {
|
|
69
|
+
import { tornFetch } from '@nuxx/torn-fetch'
|
|
53
70
|
|
|
54
71
|
// Use with query parameters
|
|
55
|
-
const attacks = await
|
|
72
|
+
const attacks = await tornFetch(
|
|
56
73
|
'your-api-key',
|
|
57
74
|
'/user/attacks',
|
|
58
75
|
{
|
|
@@ -69,10 +86,10 @@ const attacks = await useTornFetch(
|
|
|
69
86
|
The library automatically throws JavaScript errors when the Torn API returns error responses:
|
|
70
87
|
|
|
71
88
|
```typescript
|
|
72
|
-
import {
|
|
89
|
+
import { tornFetch } from '@nuxx/torn-fetch'
|
|
73
90
|
|
|
74
91
|
try {
|
|
75
|
-
const userAttacks = await
|
|
92
|
+
const userAttacks = await tornFetch(
|
|
76
93
|
'invalid-key-abc123',
|
|
77
94
|
'/user/attacks'
|
|
78
95
|
)
|
|
@@ -84,9 +101,9 @@ try {
|
|
|
84
101
|
|
|
85
102
|
## API Reference
|
|
86
103
|
|
|
87
|
-
### `
|
|
104
|
+
### `tornFetch<TPath>(apiKey: string, path: TPath, options?: TParams<TPath>): Promise<TResponse<TPath>>`
|
|
88
105
|
|
|
89
|
-
|
|
106
|
+
Makes a type-safe call to the Torn API with automatic error handling.
|
|
90
107
|
|
|
91
108
|
**Parameters:**
|
|
92
109
|
- `apiKey`: Your Torn API key
|
|
@@ -104,28 +121,28 @@ Creates a specialized fetcher function for a specific API endpoint.
|
|
|
104
121
|
### Prerequisites
|
|
105
122
|
|
|
106
123
|
- Node.js 18+
|
|
107
|
-
-
|
|
124
|
+
- Bun
|
|
108
125
|
|
|
109
126
|
### Setup
|
|
110
127
|
|
|
111
128
|
```bash
|
|
112
129
|
# Install dependencies
|
|
113
|
-
|
|
130
|
+
bun install
|
|
114
131
|
|
|
115
132
|
# Get the latest Torn API schema and build
|
|
116
|
-
|
|
133
|
+
bun run build
|
|
117
134
|
```
|
|
118
135
|
|
|
119
136
|
### Scripts
|
|
120
137
|
|
|
121
|
-
- `
|
|
122
|
-
- `
|
|
123
|
-
- `
|
|
124
|
-
- `
|
|
125
|
-
- `
|
|
126
|
-
- `
|
|
127
|
-
- `
|
|
128
|
-
- `
|
|
138
|
+
- `bun run get-schema` - Downloads the latest Torn API OpenAPI schema and generates TypeScript types
|
|
139
|
+
- `bun run build` - Builds the project using tsup
|
|
140
|
+
- `bun run lint` - Runs ESLint on the codebase
|
|
141
|
+
- `bun run type-check` - Runs TypeScript type checking
|
|
142
|
+
- `bun run test` - Runs the test suite
|
|
143
|
+
- `bun run test:watch` - Runs tests in watch mode
|
|
144
|
+
- `bun run test:coverage` - Runs tests with coverage reporting
|
|
145
|
+
- `bun run ci` - Runs the complete CI pipeline (schema, lint, type-check, test, build)
|
|
129
146
|
|
|
130
147
|
## Testing
|
|
131
148
|
|
|
@@ -138,9 +155,9 @@ This package includes comprehensive tests with 100% code coverage. The test suit
|
|
|
138
155
|
|
|
139
156
|
Run tests with:
|
|
140
157
|
```bash
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
158
|
+
bun run test # Run tests once
|
|
159
|
+
bun run test:watch # Run tests in watch mode
|
|
160
|
+
bun run test:coverage # Run tests with coverage report
|
|
144
161
|
```
|
|
145
162
|
|
|
146
163
|
See [TESTING.md](./TESTING.md) for detailed testing documentation.
|
|
@@ -148,7 +165,7 @@ See [TESTING.md](./TESTING.md) for detailed testing documentation.
|
|
|
148
165
|
## Project Structure
|
|
149
166
|
|
|
150
167
|
```
|
|
151
|
-
|
|
168
|
+
torn-fetch/
|
|
152
169
|
├── coverage/ # Test coverage reports
|
|
153
170
|
├── dist/ # Compiled output
|
|
154
171
|
├── src/
|
|
@@ -161,10 +178,10 @@ use-torn-fetch/
|
|
|
161
178
|
│ └── torn-api.ts # Generated TypeScript types
|
|
162
179
|
├── eslint.config.js # ESLint configuration
|
|
163
180
|
├── package.json
|
|
164
|
-
├── pnpm-workspace.yaml # pnpm workspace configuration
|
|
165
181
|
├── tsconfig.json # TypeScript configuration
|
|
166
|
-
├── tsup.config.ts # Build configuration
|
|
182
|
+
├── tsup.config.ts # Build configuration
|
|
167
183
|
├── vitest.config.ts # Test configuration
|
|
184
|
+
├── bun.lock # Bun lock file
|
|
168
185
|
├── TESTING.md # Testing documentation
|
|
169
186
|
└── README.md
|
|
170
187
|
```
|
|
@@ -174,7 +191,7 @@ use-torn-fetch/
|
|
|
174
191
|
1. Fork the repository
|
|
175
192
|
2. Create a feature branch
|
|
176
193
|
3. Make your changes
|
|
177
|
-
4. Run the full CI pipeline: `
|
|
194
|
+
4. Run the full CI pipeline: `bun run ci`
|
|
178
195
|
5. Submit a pull request
|
|
179
196
|
|
|
180
197
|
All contributions should include appropriate tests and maintain 100% code coverage.
|