@ametie/vue-muza-use 1.1.1 → 1.2.1
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 +120 -5
- package/dist/index.cjs +256 -184
- package/dist/index.d.cts +89 -1
- package/dist/index.d.ts +89 -1
- package/dist/index.mjs +128 -2
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -41,6 +41,7 @@ A production-ready composable that eliminates boilerplate and solves the hard pr
|
|
|
41
41
|
- 🔐 **JWT Token Management** — Automatic token refresh with request queueing on 401 responses
|
|
42
42
|
- 🎛️ **Flexible Architecture** — Bring your own Axios instance with full configuration control
|
|
43
43
|
- 🍪 **withCredentials** — Per-request cookie and cross-origin credential control
|
|
44
|
+
- 🔭 **DevTools Panel** — Inspect live requests, payloads, and instance state via `@ametie/vue-muza-devtools`
|
|
44
45
|
|
|
45
46
|
---
|
|
46
47
|
|
|
@@ -63,11 +64,11 @@ A production-ready composable that eliminates boilerplate and solves the hard pr
|
|
|
63
64
|
| **Response caching** | ✅ | ❌ | ✅ | ✅ |
|
|
64
65
|
| **TypeScript** | ✅ | ✅ | ✅ | ✅ |
|
|
65
66
|
| **SSR / Nuxt** | ❌ | ✅ | ✅ | ✅ |
|
|
66
|
-
| **DevTools** |
|
|
67
|
+
| **DevTools** | ✅ | ❌ | ✅ | ❌ |
|
|
67
68
|
|
|
68
69
|
**Choose vue-muza-use if:** you build Vue 3 SPAs with Axios, need JWT token refresh out of the box, and want reactive request management without a heavyweight server-state solution.
|
|
69
70
|
|
|
70
|
-
**Choose TanStack Query if:** you need SSR
|
|
71
|
+
**Choose TanStack Query if:** you need SSR or advanced server-state normalization.
|
|
71
72
|
|
|
72
73
|
**Choose @vueuse/useFetch if:** you want a minimal fetch wrapper with no opinions.
|
|
73
74
|
|
|
@@ -97,9 +98,12 @@ A production-ready composable that eliminates boilerplate and solves the hard pr
|
|
|
97
98
|
- [Data Table with Pagination](#data-table-with-pagination--sorting)
|
|
98
99
|
- [Request Cancellation](#request-cancellation)
|
|
99
100
|
- [Batch Requests](#batch-requests)
|
|
101
|
+
- [Reactive Requests (Auto-tracking)](#reactive-requests--auto-tracking)
|
|
102
|
+
- [Batch Polling](#batch-polling)
|
|
100
103
|
|
|
101
104
|
**Advanced:**
|
|
102
105
|
- [Advanced Configuration](#️-advanced-configuration)
|
|
106
|
+
- [DevTools Panel](#-devtools-panel)
|
|
103
107
|
- [Authentication & Token Management](#-authentication--token-management)
|
|
104
108
|
- [Error Handling Reference](#-error-handling-reference)
|
|
105
109
|
- [Utilities & Standalone Composables](#-utilities--standalone-composables)
|
|
@@ -1405,6 +1409,77 @@ const { loading, progress, execute } = useApiBatch(urls, {
|
|
|
1405
1409
|
</template>
|
|
1406
1410
|
```
|
|
1407
1411
|
|
|
1412
|
+
#### Reactive Requests — Auto-tracking
|
|
1413
|
+
|
|
1414
|
+
**TL;DR: Pass a getter function as `requests` — the batch re-executes automatically when the getter's reactive dependencies change.**
|
|
1415
|
+
|
|
1416
|
+
This mirrors `useApi`'s auto-tracking behavior. No explicit `watch` option needed.
|
|
1417
|
+
|
|
1418
|
+
```typescript
|
|
1419
|
+
import { ref } from 'vue'
|
|
1420
|
+
import { useApiBatch } from '@ametie/vue-muza-use'
|
|
1421
|
+
|
|
1422
|
+
interface User { id: number; name: string }
|
|
1423
|
+
|
|
1424
|
+
const pages = ref([1, 2, 3])
|
|
1425
|
+
|
|
1426
|
+
// Getter is auto-tracked — re-executes when pages.value changes
|
|
1427
|
+
const { successfulData, loading } = useApiBatch<User>(
|
|
1428
|
+
() => pages.value.map(page => ({ url: '/users', params: { page } }))
|
|
1429
|
+
)
|
|
1430
|
+
|
|
1431
|
+
pages.value = [4, 5, 6] // → new batch fires automatically
|
|
1432
|
+
```
|
|
1433
|
+
|
|
1434
|
+
Set `lazy: true` to disable auto-tracking and keep full manual control:
|
|
1435
|
+
|
|
1436
|
+
```typescript
|
|
1437
|
+
const { execute } = useApiBatch(
|
|
1438
|
+
() => ids.value.map(id => `/items/${id}`),
|
|
1439
|
+
{ lazy: true } // reactive changes to ids do NOT trigger re-execution
|
|
1440
|
+
)
|
|
1441
|
+
|
|
1442
|
+
// You control when it runs
|
|
1443
|
+
await execute()
|
|
1444
|
+
```
|
|
1445
|
+
|
|
1446
|
+
#### Batch Polling
|
|
1447
|
+
|
|
1448
|
+
**TL;DR: Re-execute the batch on a fixed interval — useful for dashboards and status monitoring.**
|
|
1449
|
+
|
|
1450
|
+
Same semantics as `useApi`'s `poll` option.
|
|
1451
|
+
|
|
1452
|
+
```typescript
|
|
1453
|
+
import { useApiBatch } from '@ametie/vue-muza-use'
|
|
1454
|
+
|
|
1455
|
+
const { data, loading } = useApiBatch(
|
|
1456
|
+
['/stats/cpu', '/stats/memory', '/stats/disk'],
|
|
1457
|
+
{
|
|
1458
|
+
immediate: true,
|
|
1459
|
+
poll: 5000 // re-execute every 5 seconds
|
|
1460
|
+
}
|
|
1461
|
+
)
|
|
1462
|
+
```
|
|
1463
|
+
|
|
1464
|
+
With `whenHidden` control:
|
|
1465
|
+
|
|
1466
|
+
```typescript
|
|
1467
|
+
import { ref } from 'vue'
|
|
1468
|
+
import { useApiBatch } from '@ametie/vue-muza-use'
|
|
1469
|
+
|
|
1470
|
+
const interval = ref(10000)
|
|
1471
|
+
|
|
1472
|
+
const { data, abort } = useApiBatch(
|
|
1473
|
+
['/queue/jobs', '/queue/workers'],
|
|
1474
|
+
{
|
|
1475
|
+
immediate: true,
|
|
1476
|
+
poll: { interval, whenHidden: false } // pauses when tab is hidden
|
|
1477
|
+
}
|
|
1478
|
+
)
|
|
1479
|
+
|
|
1480
|
+
interval.value = 0 // stop polling
|
|
1481
|
+
```
|
|
1482
|
+
|
|
1408
1483
|
---
|
|
1409
1484
|
|
|
1410
1485
|
## ⚙️ Advanced Configuration
|
|
@@ -1496,6 +1571,44 @@ createApp(App).use(createApi({
|
|
|
1496
1571
|
|
|
1497
1572
|
---
|
|
1498
1573
|
|
|
1574
|
+
## 🔭 DevTools Panel
|
|
1575
|
+
|
|
1576
|
+
**TL;DR: Enable it in the plugin and get a live network inspector in your browser. No extra packages to install.**
|
|
1577
|
+
|
|
1578
|
+
The devtools panel is included with `@ametie/vue-muza-use`. It loads on demand and has zero impact on production bundles when disabled.
|
|
1579
|
+
|
|
1580
|
+
### Setup
|
|
1581
|
+
|
|
1582
|
+
Pass `devtools` to `createApi`. Gate it on `NODE_ENV` to keep production builds clean:
|
|
1583
|
+
|
|
1584
|
+
```typescript
|
|
1585
|
+
import { createApp } from 'vue'
|
|
1586
|
+
import { createApi, createApiClient } from '@ametie/vue-muza-use'
|
|
1587
|
+
import App from './App.vue'
|
|
1588
|
+
|
|
1589
|
+
const api = createApiClient({ baseURL: 'https://api.example.com' })
|
|
1590
|
+
|
|
1591
|
+
createApp(App).use(createApi({
|
|
1592
|
+
axios: api,
|
|
1593
|
+
devtools: {
|
|
1594
|
+
enabled: process.env.NODE_ENV !== 'production'
|
|
1595
|
+
}
|
|
1596
|
+
}))
|
|
1597
|
+
```
|
|
1598
|
+
|
|
1599
|
+
The panel loads asynchronously — it has zero impact on startup time.
|
|
1600
|
+
|
|
1601
|
+
### DevTools Options
|
|
1602
|
+
|
|
1603
|
+
| Option | Type | Default | Description |
|
|
1604
|
+
|--------|------|---------|-------------|
|
|
1605
|
+
| `enabled` | `boolean` | — | Required. Set `true` to mount the panel |
|
|
1606
|
+
| `maxHistory` | `number` | `300` | Maximum number of requests kept in the Network tab history |
|
|
1607
|
+
| `maxPayloadSize` | `number` | `200_000` | Maximum bytes per payload/response before truncation in the viewer |
|
|
1608
|
+
| `tabs` | `DevtoolsTab[]` | `[]` | Additional custom tabs to register in the panel |
|
|
1609
|
+
|
|
1610
|
+
---
|
|
1611
|
+
|
|
1499
1612
|
## 🔐 Authentication & Token Management
|
|
1500
1613
|
|
|
1501
1614
|
> **Note:** Authentication setup is optional. Only add this if your API requires JWT tokens.
|
|
@@ -2141,15 +2254,17 @@ type BatchInput = string | BatchRequestConfig
|
|
|
2141
2254
|
|
|
2142
2255
|
| Option | Type | Default | Description |
|
|
2143
2256
|
|--------|------|---------|-------------|
|
|
2144
|
-
| `settled` | `boolean` | `true` | When `true`, all requests run even if some fail. When `false`, the first error
|
|
2257
|
+
| `settled` | `boolean` | `true` | When `true`, all requests run even if some fail. When `false`, the first error aborts remaining requests |
|
|
2145
2258
|
| `concurrency` | `number` | unlimited | Maximum number of requests that run in parallel at once |
|
|
2146
2259
|
| `immediate` | `boolean` | `false` | Execute the batch automatically when the composable is created |
|
|
2260
|
+
| `lazy` | `boolean` | `false` | Disable auto-tracking. When `false`, a getter passed as `requests` re-executes the batch automatically when its reactive deps change. Set `true` for full manual control via `execute()` |
|
|
2261
|
+
| `poll` | `number \| { interval: MaybeRefOrGetter<number>, whenHidden?: MaybeRefOrGetter<boolean> }` | `0` | Polling interval in ms. After each execution, schedules the next one after `interval` ms. `0` disables polling. `whenHidden: false` (default) pauses when the tab is hidden |
|
|
2147
2262
|
| `skipErrorNotification` | `boolean` | `true` | Suppress global error handler for individual item failures |
|
|
2148
|
-
| `watch` | `WatchSource \| WatchSource[]` | `undefined` |
|
|
2263
|
+
| `watch` | `WatchSource \| WatchSource[]` | `undefined` | **Deprecated** — use a reactive getter with `lazy: false` instead. Will be removed in v2.0 |
|
|
2149
2264
|
| `onItemSuccess` | `(item: BatchResultItem<T>, index: number) => void` | `undefined` | Called each time a single request in the batch succeeds |
|
|
2150
2265
|
| `onItemError` | `(item: BatchResultItem<T>, index: number) => void` | `undefined` | Called each time a single request in the batch fails |
|
|
2151
2266
|
| `onProgress` | `(progress: BatchProgress) => void` | `undefined` | Called after each request completes with updated progress |
|
|
2152
|
-
| `onFinish` | `(results: BatchResultItem<T>[]) => void` | `undefined` | Called once when all requests have completed |
|
|
2267
|
+
| `onFinish` | `(results: BatchResultItem<T>[]) => void` | `undefined` | Called once when all requests have completed (even on `settled: false` rejection) |
|
|
2153
2268
|
|
|
2154
2269
|
**UseApiBatchReturn:**
|
|
2155
2270
|
|