@spoosh/core 0.1.0-beta.0 → 0.2.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 +40 -7
- package/dist/index.d.mts +492 -288
- package/dist/index.d.ts +492 -288
- package/dist/index.js +211 -26
- package/dist/index.mjs +211 -26
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -199,15 +199,48 @@ Creates a lightweight type-safe API client.
|
|
|
199
199
|
| `defaultOptions` | `RequestInit` | Default fetch options (headers, credentials, etc.) |
|
|
200
200
|
| `middlewares` | `SpooshMiddleware[]` | Request/response middlewares |
|
|
201
201
|
|
|
202
|
-
###
|
|
202
|
+
### Spoosh (class)
|
|
203
203
|
|
|
204
|
-
Creates a full-featured client with plugin system. Use this with `@spoosh/react`.
|
|
204
|
+
Creates a full-featured client with plugin system using a clean class-based API. Use this with `@spoosh/react`.
|
|
205
|
+
|
|
206
|
+
```typescript
|
|
207
|
+
import { Spoosh } from "@spoosh/core";
|
|
208
|
+
import { cachePlugin } from "@spoosh/plugin-cache";
|
|
209
|
+
import { retryPlugin } from "@spoosh/plugin-retry";
|
|
210
|
+
|
|
211
|
+
const client = new Spoosh<ApiSchema, Error>("/api", {
|
|
212
|
+
headers: { Authorization: "Bearer token" }
|
|
213
|
+
}).use([
|
|
214
|
+
cachePlugin({ staleTime: 5000 }),
|
|
215
|
+
retryPlugin({ retries: 3 })
|
|
216
|
+
]);
|
|
217
|
+
|
|
218
|
+
const { api } = client;
|
|
219
|
+
const { data } = await api.users.$get();
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
**Constructor Parameters:**
|
|
223
|
+
|
|
224
|
+
| Parameter | Type | Description |
|
|
225
|
+
| ---------------- | --------------- | --------------------------------------- |
|
|
226
|
+
| `baseUrl` | `string` | Base URL for all API requests |
|
|
227
|
+
| `defaultOptions` | `RequestInit` | (Optional) Default fetch options |
|
|
228
|
+
|
|
229
|
+
**Methods:**
|
|
230
|
+
|
|
231
|
+
| Method | Description |
|
|
232
|
+
| ------ | ----------- |
|
|
233
|
+
| `.use(plugins)` | Add plugins to the client. Returns a new instance with updated types. |
|
|
234
|
+
|
|
235
|
+
**Properties:**
|
|
236
|
+
|
|
237
|
+
| Property | Description |
|
|
238
|
+
| -------- | ----------- |
|
|
239
|
+
| `.api` | Type-safe API client for making requests |
|
|
240
|
+
| `.stateManager` | Cache and state management |
|
|
241
|
+
| `.eventEmitter` | Event system for refetch/invalidation |
|
|
242
|
+
| `.pluginExecutor` | Plugin lifecycle management |
|
|
205
243
|
|
|
206
|
-
| Option | Type | Description |
|
|
207
|
-
| ---------------- | ---------------- | ----------------------------- |
|
|
208
|
-
| `baseUrl` | `string` | Base URL for all API requests |
|
|
209
|
-
| `plugins` | `SpooshPlugin[]` | Array of plugins to use |
|
|
210
|
-
| `defaultOptions` | `RequestInit` | Default fetch options |
|
|
211
244
|
|
|
212
245
|
## Creating Plugins
|
|
213
246
|
|