@varlet/axle 0.10.1 → 0.10.2-alpha.1737055052455

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 CHANGED
@@ -57,7 +57,7 @@ axios.interceptors.request.use(
57
57
  (error) => {
58
58
  // Do something with request error
59
59
  return Promise.reject(error)
60
- }
60
+ },
61
61
  )
62
62
 
63
63
  // Add a response interceptor
@@ -71,7 +71,7 @@ axios.interceptors.response.use(
71
71
  // Any status codes that falls outside the range of 2xx cause this function to trigger
72
72
  // Do something with response error
73
73
  return Promise.reject(error)
74
- }
74
+ },
75
75
  )
76
76
  ```
77
77
 
@@ -218,21 +218,17 @@ const headersInterceptor = requestHeadersInterceptor({
218
218
  headers: () => ({
219
219
  token: localStorage.getItem('token'),
220
220
  'Axle-Custom-Header': 'Axle-Custom-Header',
221
- })
221
+ }),
222
222
  })
223
223
 
224
224
  const retryInterceptor = responseRetryInterceptor({ count: 3 })
225
225
 
226
226
  axios.interceptors.request.use(
227
- headersInterceptor.onFulfilled,
228
- headersInterceptor.onRejected,
229
- headersInterceptor.options
230
- )
231
- axios.interceptors.response.use(
232
- retryInterceptor.onFulfilled,
233
- retryInterceptor.onRejected,
234
- retryInterceptor.options
227
+ headersInterceptor.onFulfilled,
228
+ headersInterceptor.onRejected,
229
+ headersInterceptor.options,
235
230
  )
231
+ axios.interceptors.response.use(retryInterceptor.onFulfilled, retryInterceptor.onRejected, retryInterceptor.options)
236
232
  ```
237
233
 
238
234
  ### axle
@@ -262,25 +258,25 @@ It is used to request filtering to determine what request should apply the inter
262
258
 
263
259
  ```ts
264
260
  axle.useResponseInterceptor(
265
- responseRetryInterceptor({
261
+ responseRetryInterceptor({
266
262
  count: 3,
267
263
  include: ['method:put', 'method:post', 'status:500'],
268
- exclude: ['/system/**', '/user/addUser', 'status:400']
264
+ exclude: ['/system/**', '/user/addUser', 'status:400'],
269
265
  }),
270
266
  )
271
267
  ```
272
268
 
273
269
  ### List of built-in interceptor
274
270
 
275
- | Name | Description |
276
- | --- | --- |
277
- | [requestHeadersInterceptor](https://github.com/varletjs/axle/blob/main/packages/axle/src/interceptors/examples/requestHeadersInterceptor.md) | Used to customize the request header |
278
- | [requestMockInterceptor](https://github.com/varletjs/axle/blob/main/packages/axle/src/interceptors/examples/requestMockInterceptor.md) | Used to mock data |
279
- | [requestMd5Interceptor](https://github.com/varletjs/axle/blob/main/packages/axle/src/interceptors/examples/requestMd5Interceptor.md) | Used for md encryption of parameters and headers |
280
- | [responseRetryInterceptor](https://github.com/varletjs/axle/blob/main/packages/axle/src/interceptors/examples/responseRetryInterceptor.md) | Used to realize the request abnormal retry |
281
- | [responseStatusInterceptor](https://github.com/varletjs/axle/blob/main/packages/axle/src/interceptors/examples/responseStatusInterceptor.md) | Used to intercept status code |
282
- | [responseBlobInterceptor](https://github.com/varletjs/axle/blob/main/packages/axle/src/interceptors/examples/responseBlobInterceptor.md) | Used to intercept blob type |
283
- | [responseTimeoutInterceptor](https://github.com/varletjs/axle/blob/main/packages/axle/src/interceptors/examples/responseTimeoutInterceptor.md) | Used to abnormal timeout |
271
+ | Name | Description |
272
+ | ---------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------ |
273
+ | [requestHeadersInterceptor](https://github.com/varletjs/axle/blob/main/packages/axle/src/interceptors/examples/requestHeadersInterceptor.md) | Used to customize the request header |
274
+ | [requestMockInterceptor](https://github.com/varletjs/axle/blob/main/packages/axle/src/interceptors/examples/requestMockInterceptor.md) | Used to mock data |
275
+ | [requestMd5Interceptor](https://github.com/varletjs/axle/blob/main/packages/axle/src/interceptors/examples/requestMd5Interceptor.md) | Used for md encryption of parameters and headers |
276
+ | [responseRetryInterceptor](https://github.com/varletjs/axle/blob/main/packages/axle/src/interceptors/examples/responseRetryInterceptor.md) | Used to realize the request abnormal retry |
277
+ | [responseStatusInterceptor](https://github.com/varletjs/axle/blob/main/packages/axle/src/interceptors/examples/responseStatusInterceptor.md) | Used to intercept status code |
278
+ | [responseBlobInterceptor](https://github.com/varletjs/axle/blob/main/packages/axle/src/interceptors/examples/responseBlobInterceptor.md) | Used to intercept blob type |
279
+ | [responseTimeoutInterceptor](https://github.com/varletjs/axle/blob/main/packages/axle/src/interceptors/examples/responseTimeoutInterceptor.md) | Used to abnormal timeout |
284
280
 
285
281
  ## Vue Composition API
286
282
 
@@ -288,64 +284,64 @@ Axle provides the usage of Vue Composition API style, which encapsulates the `lo
288
284
 
289
285
  ```html
290
286
  <script setup>
291
- import { createAxle } from '@varlet/axle'
292
- import { createUseAxle } from '@varlet/axle/use'
287
+ import { createAxle } from '@varlet/axle'
288
+ import { createUseAxle } from '@varlet/axle/use'
293
289
 
294
- const axle = createAxle(/** @see https://axios-http.com **/)
290
+ const axle = createAxle(/** @see https://axios-http.com **/)
295
291
 
296
- const useAxle = createUseAxle({
297
- axle,
298
- // Optional value: Default immediate of the useAxle, defaults true
299
- immediate: false,
300
- // Optional value: Default onTransform of the useAxle
301
- onTransform: (response) => response,
302
- })
292
+ const useAxle = createUseAxle({
293
+ axle,
294
+ // Optional value: Default immediate of the useAxle, defaults true
295
+ immediate: false,
296
+ // Optional value: Default onTransform of the useAxle
297
+ onTransform: (response) => response,
298
+ })
303
299
 
304
- const [
305
- users,
306
- // request runner/invoker
307
- getUsers,
308
- // extra properties
309
- { loading, error, uploadProgress, downloadProgress, abort, resetValue }
310
- ] = useAxle({
311
- // Request initial value
312
- value: [],
313
- // Request method
314
- method: 'get',
315
- // Request url can be a getter function
316
- url: '/user',
317
- // Whether to send the request immediately, defaults true
318
- immediate: false,
319
- // Whether the value needs to be reset before requesting, defaults false
320
- resetValue: true,
321
- // Whether to clone when resetting value, defaults false
322
- // When set to true, use JSON.parse(JSON.stringify(value)) cloned
323
- // When set to a function, the set function will be used as the clone function, such as v => _.cloneDeep(v)
324
- cloneResetValue: true,
325
- // Request params, defaults {}, can be a getter function
326
- params: { current: 1, pageSize: 10 },
327
- // Axios config, see https://axios-http.com can be a getter function
328
- config: { headers: {} },
329
- // lifecycle
330
- onBefore(refs) {
331
- const { data, loading, error, uploadProgress, downloadProgress } = refs
332
- console.log(data.value, loading.value, error.value, uploadProgress.value, downloadProgress.value)
333
- // Do request before
334
- },
335
- onTransform(response, refs) {
336
- // Handle data transform, The transformed data will be the value of users.
337
- return response.data
338
- },
339
- onSuccess(response, refs) {
340
- // Do request success
341
- },
342
- onError(error, refs) {
343
- // Do request error
344
- },
345
- onAfter(refs) {
346
- // Do request after
347
- },
348
- })
300
+ const [
301
+ users,
302
+ // request runner/invoker
303
+ getUsers,
304
+ // extra properties
305
+ { loading, error, uploadProgress, downloadProgress, abort, resetValue },
306
+ ] = useAxle({
307
+ // Request initial value
308
+ value: [],
309
+ // Request method
310
+ method: 'get',
311
+ // Request url can be a getter function
312
+ url: '/user',
313
+ // Whether to send the request immediately, defaults true
314
+ immediate: false,
315
+ // Whether the value needs to be reset before requesting, defaults false
316
+ resetValue: true,
317
+ // Whether to clone when resetting value, defaults false
318
+ // When set to true, use JSON.parse(JSON.stringify(value)) cloned
319
+ // When set to a function, the set function will be used as the clone function, such as v => _.cloneDeep(v)
320
+ cloneResetValue: true,
321
+ // Request params, defaults {}, can be a getter function
322
+ params: { current: 1, pageSize: 10 },
323
+ // Axios config, see https://axios-http.com can be a getter function
324
+ config: { headers: {} },
325
+ // lifecycle
326
+ onBefore(refs) {
327
+ const { data, loading, error, uploadProgress, downloadProgress } = refs
328
+ console.log(data.value, loading.value, error.value, uploadProgress.value, downloadProgress.value)
329
+ // Do request before
330
+ },
331
+ onTransform(response, refs) {
332
+ // Handle data transform, The transformed data will be the value of users.
333
+ return response.data
334
+ },
335
+ onSuccess(response, refs) {
336
+ // Do request success
337
+ },
338
+ onError(error, refs) {
339
+ // Do request error
340
+ },
341
+ onAfter(refs) {
342
+ // Do request after
343
+ },
344
+ })
349
345
  </script>
350
346
 
351
347
  <template>
@@ -365,42 +361,42 @@ Axle provides some parallel request processing tools, please refer to the follow
365
361
 
366
362
  ```html
367
363
  <script setup>
368
- import { createAxle } from '@varlet/axle'
369
- import { createUseAxle, useValues, useAverageProgress, useHasLoading } from '@varlet/axle/use'
364
+ import { createAxle } from '@varlet/axle'
365
+ import { createUseAxle, useAverageProgress, useHasLoading, useValues } from '@varlet/axle/use'
370
366
 
371
- const axle = createAxle(/** @see https://axios-http.com **/)
367
+ const axle = createAxle(/** @see https://axios-http.com **/)
372
368
 
373
- const useAxle = createUseAxle({ axle })
369
+ const useAxle = createUseAxle({ axle })
374
370
 
375
- const [users, getUsers, { loading: isUsersLoading, downloadProgress: usersDownloadProgress }] = useAxle({
376
- method: 'get',
377
- url: '/user',
378
- })
371
+ const [users, getUsers, { loading: isUsersLoading, downloadProgress: usersDownloadProgress }] = useAxle({
372
+ method: 'get',
373
+ url: '/user',
374
+ })
379
375
 
380
- const [roles, getRoles, { loading: isRolesLoading, downloadProgress: rolesDownloadProgress }] = useAxle({
381
- method: 'get',
382
- url: '/role',
383
- })
376
+ const [roles, getRoles, { loading: isRolesLoading, downloadProgress: rolesDownloadProgress }] = useAxle({
377
+ method: 'get',
378
+ url: '/role',
379
+ })
384
380
 
385
- // At the end of all requests, loading is false
386
- const loading = useHasLoading(isUsersLoading, isRolesLoading)
387
- // At the end of all requests, downloadProgress is 1
388
- const downloadProgress = useAverageProgress(usersDownloadProgress, rolesDownloadProgress)
389
- // Ref<[
390
- // [{ name: 'foo' }, { name: 'bar' }],
391
- // [{ role: 'admin' }, { role: 'user' }]
392
- // ]> <-
393
- // [
394
- // Ref<[{ name: 'foo' }, { name: 'bar' }]>,
395
- // Ref<[{ role: 'admin' }, { role: 'user' }]>
396
- // ]
397
- const usersRoles = useValues(users, roles)
398
-
399
- function sendAllRequest() {
400
- // parallel
401
- getUsers()
402
- getRoles()
403
- }
381
+ // At the end of all requests, loading is false
382
+ const loading = useHasLoading(isUsersLoading, isRolesLoading)
383
+ // At the end of all requests, downloadProgress is 1
384
+ const downloadProgress = useAverageProgress(usersDownloadProgress, rolesDownloadProgress)
385
+ // Ref<[
386
+ // [{ name: 'foo' }, { name: 'bar' }],
387
+ // [{ role: 'admin' }, { role: 'user' }]
388
+ // ]> <-
389
+ // [
390
+ // Ref<[{ name: 'foo' }, { name: 'bar' }]>,
391
+ // Ref<[{ role: 'admin' }, { role: 'user' }]>
392
+ // ]
393
+ const usersRoles = useValues(users, roles)
394
+
395
+ function sendAllRequest() {
396
+ // parallel
397
+ getUsers()
398
+ getRoles()
399
+ }
404
400
  </script>
405
401
 
406
402
  <template>
@@ -419,8 +415,8 @@ function sendAllRequest() {
419
415
 
420
416
  ```ts
421
417
  import { createAxle } from '@varlet/axle'
422
- import { createUseAxle } from '@varlet/axle/use'
423
418
  import { createApi } from '@varlet/axle/api'
419
+ import { createUseAxle } from '@varlet/axle/use'
424
420
 
425
421
  const axle = createAxle({
426
422
  baseURL: '/api',
@@ -507,15 +503,15 @@ before:
507
503
 
508
504
  ```html
509
505
  <script setup>
510
- const [users, getUsers, { loading: isUsersLoading }] = useAxle({
511
- method: 'get',
512
- url: '/user',
513
- })
506
+ const [users, getUsers, { loading: isUsersLoading }] = useAxle({
507
+ method: 'get',
508
+ url: '/user',
509
+ })
514
510
 
515
- const [posts, getPosts, { loading: isPostsLoading }] = useAxle({
516
- method: 'get',
517
- url: '/post',
518
- })
511
+ const [posts, getPosts, { loading: isPostsLoading }] = useAxle({
512
+ method: 'get',
513
+ url: '/post',
514
+ })
519
515
  </script>
520
516
 
521
517
  <template>
@@ -530,15 +526,15 @@ after:
530
526
 
531
527
  ```html
532
528
  <script setup>
533
- const [users, getUsers] = useAxle({
534
- method: 'get',
535
- url: '/user',
536
- })
529
+ const [users, getUsers] = useAxle({
530
+ method: 'get',
531
+ url: '/user',
532
+ })
537
533
 
538
- const [posts, getPosts] = useAxle({
539
- method: 'get',
540
- url: '/post',
541
- })
534
+ const [posts, getPosts] = useAxle({
535
+ method: 'get',
536
+ url: '/post',
537
+ })
542
538
  </script>
543
539
 
544
540
  <template>
package/README.zh-CN.md CHANGED
@@ -57,7 +57,7 @@ axios.interceptors.request.use(
57
57
  (error) => {
58
58
  // 请求错误处理
59
59
  return Promise.reject(error)
60
- }
60
+ },
61
61
  )
62
62
 
63
63
  // 添加请求后返回拦截器
@@ -71,7 +71,7 @@ axios.interceptors.response.use(
71
71
  // 任何超出 2xx 范围的状态代码都会导致此函数触发
72
72
  // 对响应错误做一些事情
73
73
  return Promise.reject(error)
74
- }
74
+ },
75
75
  )
76
76
  ```
77
77
 
@@ -218,21 +218,17 @@ const headersInterceptor = requestHeadersInterceptor({
218
218
  headers: () => ({
219
219
  token: localStorage.getItem('token'),
220
220
  'Axle-Custom-Header': 'Axle-Custom-Header',
221
- })
221
+ }),
222
222
  })
223
223
 
224
224
  const retryInterceptor = responseRetryInterceptor({ count: 3 })
225
225
 
226
226
  axios.interceptors.request.use(
227
- headersInterceptor.onFulfilled,
228
- headersInterceptor.onRejected,
229
- headersInterceptor.options
230
- )
231
- axios.interceptors.response.use(
232
- retryInterceptor.onFulfilled,
233
- retryInterceptor.onRejected,
234
- retryInterceptor.options
227
+ headersInterceptor.onFulfilled,
228
+ headersInterceptor.onRejected,
229
+ headersInterceptor.options,
235
230
  )
231
+ axios.interceptors.response.use(retryInterceptor.onFulfilled, retryInterceptor.onRejected, retryInterceptor.options)
236
232
  ```
237
233
 
238
234
  ### axle
@@ -262,25 +258,25 @@ axle.useResponseInterceptor(responseRetryInterceptor({ count: 3 }))
262
258
 
263
259
  ```ts
264
260
  axle.useResponseInterceptor(
265
- responseRetryInterceptor({
261
+ responseRetryInterceptor({
266
262
  count: 3,
267
263
  include: ['method:put', 'method:post', 'status:500'],
268
- exclude: ['/system/**', '/user/addUser', 'status:400']
264
+ exclude: ['/system/**', '/user/addUser', 'status:400'],
269
265
  }),
270
266
  )
271
267
  ```
272
268
 
273
269
  ### 内置拦截器一览
274
270
 
275
- | 名称 | 描述 |
276
- | --- | --- |
277
- | [requestHeadersInterceptor](https://github.com/varletjs/axle/blob/main/packages/axle/src/interceptors/examples/requestHeadersInterceptor.md) | 用于自定义请求头 |
278
- | [requestMockInterceptor](https://github.com/varletjs/axle/blob/main/packages/axle/src/interceptors/examples/requestMockInterceptor.md) | 用于模拟数据 |
279
- | [requestMd5Interceptor](https://github.com/varletjs/axle/blob/main/packages/axle/src/interceptors/examples/requestMd5Interceptor.md) | 用于对请求参数进行 md5 处理 |
280
- | [responseRetryInterceptor](https://github.com/varletjs/axle/blob/main/packages/axle/src/interceptors/examples/responseRetryInterceptor.md) | 用于实现请求异常重试 |
281
- | [responseStatusInterceptor](https://github.com/varletjs/axle/blob/main/packages/axle/src/interceptors/examples/responseStatusInterceptor.md) | 用于拦截状态码 |
282
- | [responseBlobInterceptor](https://github.com/varletjs/axle/blob/main/packages/axle/src/interceptors/examples/responseBlobInterceptor.md) | 用于拦截 blob 类型 |
283
- | [responseTimeoutInterceptor](https://github.com/varletjs/axle/blob/main/packages/axle/src/interceptors/examples/responseTimeoutInterceptor.md) | 用于归一化超时异常 |
271
+ | 名称 | 描述 |
272
+ | ---------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------- |
273
+ | [requestHeadersInterceptor](https://github.com/varletjs/axle/blob/main/packages/axle/src/interceptors/examples/requestHeadersInterceptor.md) | 用于自定义请求头 |
274
+ | [requestMockInterceptor](https://github.com/varletjs/axle/blob/main/packages/axle/src/interceptors/examples/requestMockInterceptor.md) | 用于模拟数据 |
275
+ | [requestMd5Interceptor](https://github.com/varletjs/axle/blob/main/packages/axle/src/interceptors/examples/requestMd5Interceptor.md) | 用于对请求参数进行 md5 处理 |
276
+ | [responseRetryInterceptor](https://github.com/varletjs/axle/blob/main/packages/axle/src/interceptors/examples/responseRetryInterceptor.md) | 用于实现请求异常重试 |
277
+ | [responseStatusInterceptor](https://github.com/varletjs/axle/blob/main/packages/axle/src/interceptors/examples/responseStatusInterceptor.md) | 用于拦截状态码 |
278
+ | [responseBlobInterceptor](https://github.com/varletjs/axle/blob/main/packages/axle/src/interceptors/examples/responseBlobInterceptor.md) | 用于拦截 blob 类型 |
279
+ | [responseTimeoutInterceptor](https://github.com/varletjs/axle/blob/main/packages/axle/src/interceptors/examples/responseTimeoutInterceptor.md) | 用于归一化超时异常 |
284
280
 
285
281
  ## Vue 组合式 API
286
282
 
@@ -288,64 +284,64 @@ Axle 提供了 Vue Composition API 风格的用法,封装了请求的 `加载
288
284
 
289
285
  ```html
290
286
  <script setup>
291
- import { createAxle } from '@varlet/axle'
292
- import { createUseAxle } from '@varlet/axle/use'
287
+ import { createAxle } from '@varlet/axle'
288
+ import { createUseAxle } from '@varlet/axle/use'
293
289
 
294
- const axle = createAxle(/** @see https://axios-http.com **/)
290
+ const axle = createAxle(/** @see https://axios-http.com **/)
295
291
 
296
- const useAxle = createUseAxle({
297
- axle,
298
- // 可选项: useAxle 的默认 immediate, 默认值: true
299
- immediate: false,
300
- // 可选项: useAxle 的默认 onTransform
301
- onTransform: (response) => response,
302
- })
292
+ const useAxle = createUseAxle({
293
+ axle,
294
+ // 可选项: useAxle 的默认 immediate, 默认值: true
295
+ immediate: false,
296
+ // 可选项: useAxle 的默认 onTransform
297
+ onTransform: (response) => response,
298
+ })
303
299
 
304
- const [
305
- users,
306
- // 请求触发器
307
- getUsers,
308
- // 附加属性
309
- { loading, error, uploadProgress, downloadProgress, abort }
310
- ] = useAxle({
311
- // 请求初始化数据
312
- value: [],
313
- // 请求方法
314
- method: 'get',
315
- // 请求地址, 可以是 getter 函数
316
- url: '/user',
317
- // 是否立即发送请求, 默认值: true
318
- immediate: false,
319
- // 请求前是否需要重置 value, 默认值: false
320
- resetValue: true,
321
- // 重置 value 是否对 value 进行拷贝
322
- // 设置为 true 时, 使用 JSON.parse(JSON.stringify(value)) 进行拷贝
323
- // 设置为一个函数时, 该函数将作为拷贝函数对 value 进行拷贝, 如 v => _.cloneDeep(v)
324
- cloneResetValue: true,
325
- // 请求参数, 默认值: {}, 可以是 getter 函数
326
- params: { current: 1, pageSize: 10 },
327
- // Axios 配置, see https://axios-http.com, 可以是 getter 函数
328
- config: { headers: {} },
329
- // 生命周期
330
- onBefore(refs) {
331
- const { data, loading, error, uploadProgress, downloadProgress } = refs
332
- console.log(data.value, loading.value, error.value, uploadProgress.value, downloadProgress.value)
333
- // 处理请求前逻辑
334
- },
335
- onTransform(response, refs) {
336
- // 处理数据转换,转换后的数据将成为 users 的值。
337
- return response.data
338
- },
339
- onSuccess(response, refs) {
340
- // 处理请求成功逻辑
341
- },
342
- onError(error, refs) {
343
- // 处理请求错误逻辑
344
- },
345
- onAfter(refs) {
346
- // 处理请求结束逻辑,无论成功失败都会触发。
347
- },
348
- })
300
+ const [
301
+ users,
302
+ // 请求触发器
303
+ getUsers,
304
+ // 附加属性
305
+ { loading, error, uploadProgress, downloadProgress, abort },
306
+ ] = useAxle({
307
+ // 请求初始化数据
308
+ value: [],
309
+ // 请求方法
310
+ method: 'get',
311
+ // 请求地址, 可以是 getter 函数
312
+ url: '/user',
313
+ // 是否立即发送请求, 默认值: true
314
+ immediate: false,
315
+ // 请求前是否需要重置 value, 默认值: false
316
+ resetValue: true,
317
+ // 重置 value 是否对 value 进行拷贝
318
+ // 设置为 true 时, 使用 JSON.parse(JSON.stringify(value)) 进行拷贝
319
+ // 设置为一个函数时, 该函数将作为拷贝函数对 value 进行拷贝, 如 v => _.cloneDeep(v)
320
+ cloneResetValue: true,
321
+ // 请求参数, 默认值: {}, 可以是 getter 函数
322
+ params: { current: 1, pageSize: 10 },
323
+ // Axios 配置, see https://axios-http.com, 可以是 getter 函数
324
+ config: { headers: {} },
325
+ // 生命周期
326
+ onBefore(refs) {
327
+ const { data, loading, error, uploadProgress, downloadProgress } = refs
328
+ console.log(data.value, loading.value, error.value, uploadProgress.value, downloadProgress.value)
329
+ // 处理请求前逻辑
330
+ },
331
+ onTransform(response, refs) {
332
+ // 处理数据转换,转换后的数据将成为 users 的值。
333
+ return response.data
334
+ },
335
+ onSuccess(response, refs) {
336
+ // 处理请求成功逻辑
337
+ },
338
+ onError(error, refs) {
339
+ // 处理请求错误逻辑
340
+ },
341
+ onAfter(refs) {
342
+ // 处理请求结束逻辑,无论成功失败都会触发。
343
+ },
344
+ })
349
345
  </script>
350
346
 
351
347
  <template>
@@ -365,42 +361,42 @@ Axle 提供了一些并行请求处理工具,请参考以下示例。
365
361
 
366
362
  ```html
367
363
  <script setup>
368
- import { createAxle } from '@varlet/axle'
369
- import { createUseAxle, useValues, useAverageProgress, useHasLoading } from '@varlet/axle/use'
364
+ import { createAxle } from '@varlet/axle'
365
+ import { createUseAxle, useAverageProgress, useHasLoading, useValues } from '@varlet/axle/use'
370
366
 
371
- const axle = createAxle(/** @see https://axios-http.com **/)
367
+ const axle = createAxle(/** @see https://axios-http.com **/)
372
368
 
373
- const useAxle = createUseAxle({ axle })
369
+ const useAxle = createUseAxle({ axle })
374
370
 
375
- const [users, getUsers, { loading: isUsersLoading, downloadProgress: usersDownloadProgress }] = useAxle({
376
- method: 'get',
377
- url: '/user',
378
- })
371
+ const [users, getUsers, { loading: isUsersLoading, downloadProgress: usersDownloadProgress }] = useAxle({
372
+ method: 'get',
373
+ url: '/user',
374
+ })
379
375
 
380
- const [roles, getRoles, { loading: isRolesLoading, downloadProgress: rolesDownloadProgress }] = useAxle({
381
- method: 'get',
382
- url: '/role',
383
- })
376
+ const [roles, getRoles, { loading: isRolesLoading, downloadProgress: rolesDownloadProgress }] = useAxle({
377
+ method: 'get',
378
+ url: '/role',
379
+ })
384
380
 
385
- // 所有请求结束时,loading 为 false
386
- const loading = useHasLoading(isUsersLoading, isRolesLoading)
387
- // 所有请求结束时,downloadProgress 为 1
388
- const downloadProgress = useAverageProgress(usersDownloadProgress, rolesDownloadProgress)
389
- // Ref<[
390
- // [{ name: 'foo' }, { name: 'bar' }],
391
- // [{ role: 'admin' }, { role: 'user' }]
392
- // ]> <-
393
- // [
394
- // Ref<[{ name: 'foo' }, { name: 'bar' }]>,
395
- // Ref<[{ role: 'admin' }, { role: 'user' }]>
396
- // ]
397
- const usersRoles = useValues(users, roles)
398
-
399
- function sendAllRequest() {
400
- // parallel
401
- getUsers()
402
- getRoles()
403
- }
381
+ // 所有请求结束时,loading 为 false
382
+ const loading = useHasLoading(isUsersLoading, isRolesLoading)
383
+ // 所有请求结束时,downloadProgress 为 1
384
+ const downloadProgress = useAverageProgress(usersDownloadProgress, rolesDownloadProgress)
385
+ // Ref<[
386
+ // [{ name: 'foo' }, { name: 'bar' }],
387
+ // [{ role: 'admin' }, { role: 'user' }]
388
+ // ]> <-
389
+ // [
390
+ // Ref<[{ name: 'foo' }, { name: 'bar' }]>,
391
+ // Ref<[{ role: 'admin' }, { role: 'user' }]>
392
+ // ]
393
+ const usersRoles = useValues(users, roles)
394
+
395
+ function sendAllRequest() {
396
+ // parallel
397
+ getUsers()
398
+ getRoles()
399
+ }
404
400
  </script>
405
401
 
406
402
  <template>
@@ -419,8 +415,8 @@ function sendAllRequest() {
419
415
 
420
416
  ```ts
421
417
  import { createAxle } from '@varlet/axle'
422
- import { createUseAxle } from '@varlet/axle/use'
423
418
  import { createApi } from '@varlet/axle/api'
419
+ import { createUseAxle } from '@varlet/axle/use'
424
420
 
425
421
  const axle = createAxle({
426
422
  baseURL: '/api',
@@ -507,15 +503,15 @@ async function handleDelete(id: string) {
507
503
 
508
504
  ```html
509
505
  <script setup>
510
- const [users, getUsers, { loading: isUsersLoading }] = useAxle({
511
- method: 'get',
512
- url: '/user',
513
- })
506
+ const [users, getUsers, { loading: isUsersLoading }] = useAxle({
507
+ method: 'get',
508
+ url: '/user',
509
+ })
514
510
 
515
- const [posts, getPosts, { loading: isPostsLoading }] = useAxle({
516
- method: 'get',
517
- url: '/post',
518
- })
511
+ const [posts, getPosts, { loading: isPostsLoading }] = useAxle({
512
+ method: 'get',
513
+ url: '/post',
514
+ })
519
515
  </script>
520
516
 
521
517
  <template>
@@ -530,15 +526,15 @@ const [posts, getPosts, { loading: isPostsLoading }] = useAxle({
530
526
 
531
527
  ```html
532
528
  <script setup>
533
- const [users, getUsers] = useAxle({
534
- method: 'get',
535
- url: '/user',
536
- })
529
+ const [users, getUsers] = useAxle({
530
+ method: 'get',
531
+ url: '/user',
532
+ })
537
533
 
538
- const [posts, getPosts] = useAxle({
539
- method: 'get',
540
- url: '/post',
541
- })
534
+ const [posts, getPosts] = useAxle({
535
+ method: 'get',
536
+ url: '/post',
537
+ })
542
538
  </script>
543
539
 
544
540
  <template>
package/lib/api.d.cts CHANGED
@@ -1,16 +1,16 @@
1
1
  import { UseAxleOptions, UseAxle, UseAxleInstance } from './use.cjs';
2
- import { e as AxleInstance, d as RunnerMethod, A as AxleRequestConfig } from './instance-6ab5bfe4.js';
2
+ import { e as AxleInstance, d as RunnerMethod, A as AxleRequestConfig } from './instance-ab0b388e.js';
3
3
  import 'vue';
4
4
  import 'axios';
5
5
 
6
6
  type ApiPathParams = Record<string, any> | (() => Record<string, any>);
7
- type ApiUseOptions<V, R, P> = Partial<UseAxleOptions<V, R, P>> & {
7
+ type ApiUseOptions<V, R, P, D> = Partial<UseAxleOptions<V, R, P, D>> & {
8
8
  pathParams?: ApiPathParams;
9
9
  };
10
- declare function createApi(axle: AxleInstance, useAxle: UseAxle): <R = any, P = Record<string, any>>(url: string, method: RunnerMethod) => {
10
+ declare function createApi(axle: AxleInstance, useAxle: UseAxle): <R = any, P = Record<string, any>, D = Record<string, any>>(url: string, method: RunnerMethod) => {
11
11
  url: string;
12
- load: (params?: P | undefined, pathParams?: ApiPathParams, config?: AxleRequestConfig) => Promise<R>;
13
- use: <UV = any>(options?: ApiUseOptions<UV, R, P>) => UseAxleInstance<UV, R, P>;
12
+ load: (params?: P | undefined, pathParams?: ApiPathParams, config?: AxleRequestConfig<D> | undefined) => Promise<R>;
13
+ use: <V = any>(options?: ApiUseOptions<V, R, P, D>) => UseAxleInstance<V, R, P, D>;
14
14
  patchUrl: (url: string, pathParams: ApiPathParams) => string;
15
15
  };
16
16
 
package/lib/api.d.ts CHANGED
@@ -1,16 +1,16 @@
1
1
  import { UseAxleOptions, UseAxle, UseAxleInstance } from './use.js';
2
- import { e as AxleInstance, d as RunnerMethod, A as AxleRequestConfig } from './instance-6ab5bfe4.js';
2
+ import { e as AxleInstance, d as RunnerMethod, A as AxleRequestConfig } from './instance-ab0b388e.js';
3
3
  import 'vue';
4
4
  import 'axios';
5
5
 
6
6
  type ApiPathParams = Record<string, any> | (() => Record<string, any>);
7
- type ApiUseOptions<V, R, P> = Partial<UseAxleOptions<V, R, P>> & {
7
+ type ApiUseOptions<V, R, P, D> = Partial<UseAxleOptions<V, R, P, D>> & {
8
8
  pathParams?: ApiPathParams;
9
9
  };
10
- declare function createApi(axle: AxleInstance, useAxle: UseAxle): <R = any, P = Record<string, any>>(url: string, method: RunnerMethod) => {
10
+ declare function createApi(axle: AxleInstance, useAxle: UseAxle): <R = any, P = Record<string, any>, D = Record<string, any>>(url: string, method: RunnerMethod) => {
11
11
  url: string;
12
- load: (params?: P | undefined, pathParams?: ApiPathParams, config?: AxleRequestConfig) => Promise<R>;
13
- use: <UV = any>(options?: ApiUseOptions<UV, R, P>) => UseAxleInstance<UV, R, P>;
12
+ load: (params?: P | undefined, pathParams?: ApiPathParams, config?: AxleRequestConfig<D> | undefined) => Promise<R>;
13
+ use: <V = any>(options?: ApiUseOptions<V, R, P, D>) => UseAxleInstance<V, R, P, D>;
14
14
  patchUrl: (url: string, pathParams: ApiPathParams) => string;
15
15
  };
16
16
 
package/lib/index.cjs CHANGED
@@ -209,8 +209,8 @@ function createMatcher(include, exclude) {
209
209
  }
210
210
 
211
211
  // src/helper.ts
212
- var import_rattail = require("rattail");
213
212
  var import_axios3 = require("axios");
213
+ var import_rattail = require("rattail");
214
214
  function withResponse(promise) {
215
215
  return new Promise((resolve, reject) => {
216
216
  promise.then((response) => {
@@ -368,7 +368,7 @@ var import_axios5 = __toESM(require("axios"), 1);
368
368
  function responseRetryInterceptor(options) {
369
369
  return {
370
370
  onFulfilled: (response) => response,
371
- async onRejected(error) {
371
+ onRejected(error) {
372
372
  var _a, _b, _c;
373
373
  const matcher = createMatcher(options.include, options.exclude);
374
374
  if (!matcher((_a = error.config.method) != null ? _a : "", (_b = error.config.url) != null ? _b : "", (_c = error == null ? void 0 : error.response) == null ? void 0 : _c.status) || (0, import_axios5.isCancel)(error)) {
@@ -427,11 +427,11 @@ function responseStatusInterceptor(options) {
427
427
  }
428
428
 
429
429
  // src/interceptors/requestMd5Interceptor.ts
430
- var import_qs2 = __toESM(require("qs"), 1);
431
430
  var import_md5 = __toESM(require("crypto-js/md5.js"), 1);
432
431
  var import_get = __toESM(require("lodash/get.js"), 1);
433
432
  var import_set = __toESM(require("lodash/set.js"), 1);
434
433
  var import_minimatch3 = require("minimatch");
434
+ var import_qs2 = __toESM(require("qs"), 1);
435
435
  var import_rattail3 = require("rattail");
436
436
  function withCtxMd5(ctx, mapping) {
437
437
  mapping.path.forEach((path) => {
package/lib/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { R as RequestInterceptor, a as ResponseInterceptor } from './instance-6ab5bfe4.js';
2
- export { e as AxleInstance, A as AxleRequestConfig, b as FetchMethod, F as FetchRunner, I as Interceptor, c as ModifyMethod, M as ModifyRunner, d as RunnerMethod, h as createAxle, f as createFetchRunner, g as createModifyRunner } from './instance-6ab5bfe4.js';
1
+ import { R as RequestInterceptor, a as ResponseInterceptor } from './instance-ab0b388e.js';
2
+ export { e as AxleInstance, A as AxleRequestConfig, b as FetchMethod, F as FetchRunner, I as Interceptor, c as ModifyMethod, M as ModifyRunner, d as RunnerMethod, h as createAxle, f as createFetchRunner, g as createModifyRunner } from './instance-ab0b388e.js';
3
3
  import { AxiosResponse, AxiosInterceptorOptions, AxiosRequestConfig } from 'axios';
4
4
  export { AxiosError, AxiosInstance, AxiosInterceptorOptions, AxiosRequestConfig, AxiosRequestHeaders, AxiosResponse, HeadersDefaults, InternalAxiosRequestConfig, ResponseType, isAxiosError } from 'axios';
5
5
 
package/lib/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { R as RequestInterceptor, a as ResponseInterceptor } from './instance-6ab5bfe4.js';
2
- export { e as AxleInstance, A as AxleRequestConfig, b as FetchMethod, F as FetchRunner, I as Interceptor, c as ModifyMethod, M as ModifyRunner, d as RunnerMethod, h as createAxle, f as createFetchRunner, g as createModifyRunner } from './instance-6ab5bfe4.js';
1
+ import { R as RequestInterceptor, a as ResponseInterceptor } from './instance-ab0b388e.js';
2
+ export { e as AxleInstance, A as AxleRequestConfig, b as FetchMethod, F as FetchRunner, I as Interceptor, c as ModifyMethod, M as ModifyRunner, d as RunnerMethod, h as createAxle, f as createFetchRunner, g as createModifyRunner } from './instance-ab0b388e.js';
3
3
  import { AxiosResponse, AxiosInterceptorOptions, AxiosRequestConfig } from 'axios';
4
4
  export { AxiosError, AxiosInstance, AxiosInterceptorOptions, AxiosRequestConfig, AxiosRequestHeaders, AxiosResponse, HeadersDefaults, InternalAxiosRequestConfig, ResponseType, isAxiosError } from 'axios';
5
5
 
package/lib/index.js CHANGED
@@ -146,8 +146,8 @@ function createMatcher(include, exclude) {
146
146
  }
147
147
 
148
148
  // src/helper.ts
149
- import { inBrowser } from "rattail";
150
149
  import { isAxiosError as isAxiosError2 } from "axios";
150
+ import { inBrowser } from "rattail";
151
151
  function withResponse(promise) {
152
152
  return new Promise((resolve, reject) => {
153
153
  promise.then((response) => {
@@ -305,7 +305,7 @@ import axios2, { isCancel } from "axios";
305
305
  function responseRetryInterceptor(options) {
306
306
  return {
307
307
  onFulfilled: (response) => response,
308
- async onRejected(error) {
308
+ onRejected(error) {
309
309
  var _a, _b, _c;
310
310
  const matcher = createMatcher(options.include, options.exclude);
311
311
  if (!matcher((_a = error.config.method) != null ? _a : "", (_b = error.config.url) != null ? _b : "", (_c = error == null ? void 0 : error.response) == null ? void 0 : _c.status) || isCancel(error)) {
@@ -364,11 +364,11 @@ function responseStatusInterceptor(options) {
364
364
  }
365
365
 
366
366
  // src/interceptors/requestMd5Interceptor.ts
367
- import qs2 from "qs";
368
367
  import md5 from "crypto-js/md5.js";
369
368
  import get from "lodash/get.js";
370
369
  import set from "lodash/set.js";
371
370
  import { minimatch as minimatch3 } from "minimatch";
371
+ import qs2 from "qs";
372
372
  import { isString } from "rattail";
373
373
  function withCtxMd5(ctx, mapping) {
374
374
  mapping.path.forEach((path) => {
@@ -1,10 +1,10 @@
1
1
  import { AxiosRequestConfig, AxiosResponse, AxiosInterceptorOptions, InternalAxiosRequestConfig, HeadersDefaults, AxiosInstance, ResponseType } from 'axios';
2
2
 
3
- interface AxleRequestConfig extends AxiosRequestConfig {
3
+ interface AxleRequestConfig<D = any> extends AxiosRequestConfig<D> {
4
4
  }
5
5
 
6
- type FetchRunner = <R = AxiosResponse, P = Record<string, any>>(url: string, params?: P, config?: AxleRequestConfig) => Promise<R>;
7
- type ModifyRunner = <R = AxiosResponse, P = Record<string, any>>(url: string, params?: P, config?: AxleRequestConfig) => Promise<R>;
6
+ type FetchRunner = <R = AxiosResponse, P = Record<string, any>, D = Record<string, any>>(url: string, params?: P, config?: AxleRequestConfig<D>) => Promise<R>;
7
+ type ModifyRunner = <R = AxiosResponse, P = Record<string, any>, D = Record<string, any>>(url: string, params?: P, config?: AxleRequestConfig<D>) => Promise<R>;
8
8
  type FetchMethod = 'get' | 'delete' | 'options' | 'head';
9
9
  type ModifyMethod = 'post' | 'put' | 'patch';
10
10
  type RunnerMethod = keyof Omit<AxleInstance, 'axios' | 'getHeaders' | 'setHeader' | 'removeHeader' | 'useRequestInterceptor' | 'useResponseInterceptor'>;
@@ -56,8 +56,8 @@ type AxleInstance = {
56
56
  useResponseInterceptor(...interceptors: ResponseInterceptor[]): void;
57
57
  axios: AxiosInstance;
58
58
  };
59
- declare function createFetchRunner(service: AxiosInstance, method: FetchMethod, responseType: ResponseType): <R = AxiosResponse<any, any>, P = Record<string, any>>(url: string, params?: P | undefined, config?: AxleRequestConfig) => Promise<R>;
60
- declare function createModifyRunner(service: AxiosInstance, method: ModifyMethod, contentType: 'application/json' | 'multipart/form-data' | 'application/x-www-form-urlencoded'): <R = AxiosResponse<any, any>, P = Record<string, any>>(url: string, params?: P | undefined, config?: AxleRequestConfig) => Promise<R>;
59
+ declare function createFetchRunner(service: AxiosInstance, method: FetchMethod, responseType: ResponseType): <R = AxiosResponse<any, any>, P = Record<string, any>, D = Record<string, any>>(url: string, params?: P | undefined, config?: AxleRequestConfig<D> | undefined) => Promise<R>;
60
+ declare function createModifyRunner(service: AxiosInstance, method: ModifyMethod, contentType: 'application/json' | 'multipart/form-data' | 'application/x-www-form-urlencoded'): <R = AxiosResponse<any, any>, P = Record<string, any>, D = Record<string, any>>(url: string, params?: P | undefined, config?: AxleRequestConfig<D> | undefined) => Promise<R>;
61
61
  declare function createAxle(config?: AxleRequestConfig): AxleInstance;
62
62
 
63
63
  export { AxleRequestConfig as A, FetchRunner as F, Interceptor as I, ModifyRunner as M, RequestInterceptor as R, ResponseInterceptor as a, FetchMethod as b, ModifyMethod as c, RunnerMethod as d, AxleInstance as e, createFetchRunner as f, createModifyRunner as g, createAxle as h };
package/lib/use.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Ref, WritableComputedRef } from 'vue';
2
- import { A as AxleRequestConfig, d as RunnerMethod, e as AxleInstance } from './instance-6ab5bfe4.js';
2
+ import { A as AxleRequestConfig, d as RunnerMethod, e as AxleInstance } from './instance-ab0b388e.js';
3
3
  import 'axios';
4
4
 
5
5
  declare function useValues<T extends Ref<any>[]>(...valueCollection: T): WritableComputedRef<T[number]['value'][]>;
@@ -8,10 +8,10 @@ declare function useHasLoading(...loadings: Ref<boolean>[]): Ref<boolean>;
8
8
 
9
9
  declare function useAverageProgress(...progressCollection: Ref<number>[]): Ref<number>;
10
10
 
11
- interface RunOptions<V, P> {
11
+ interface RunOptions<V, P, D> {
12
12
  url?: string;
13
13
  params?: P;
14
- config?: AxleRequestConfig;
14
+ config?: AxleRequestConfig<D>;
15
15
  resetValue?: boolean;
16
16
  cloneResetValue?: boolean | ((value: V) => V);
17
17
  }
@@ -30,10 +30,10 @@ interface UseAxleRefs<V> {
30
30
  uploadProgress: Ref<number>;
31
31
  downloadProgress: Ref<number>;
32
32
  }
33
- type Run<V, R, P> = {
34
- (options?: RunOptions<V, P>): Promise<R>;
33
+ type Run<V, R, P, D> = {
34
+ (options?: RunOptions<V, P, D>): Promise<R>;
35
35
  } & UseAxleExtra<V>;
36
- interface UseAxleOptions<V = any, R = any, P = Record<string, any>> {
36
+ interface UseAxleOptions<V = any, R = any, P = Record<string, any>, D = Record<string, any>> {
37
37
  url: string | (() => string);
38
38
  method: RunnerMethod;
39
39
  value?: V;
@@ -41,7 +41,7 @@ interface UseAxleOptions<V = any, R = any, P = Record<string, any>> {
41
41
  resetValue?: boolean;
42
42
  cloneResetValue?: boolean | ((value: V) => V);
43
43
  immediate?: boolean;
44
- config?: AxleRequestConfig | (() => AxleRequestConfig);
44
+ config?: AxleRequestConfig<D> | (() => AxleRequestConfig<D>);
45
45
  onBefore?(refs: UseAxleRefs<V>): void;
46
46
  onAfter?(refs: UseAxleRefs<V>): void;
47
47
  onTransform?(response: R, refs: UseAxleRefs<V>): V | Promise<V>;
@@ -51,13 +51,13 @@ interface UseAxleOptions<V = any, R = any, P = Record<string, any>> {
51
51
  interface ResetValueOptions<V> {
52
52
  cloneResetValue?: boolean | ((value: V) => V);
53
53
  }
54
- type UseAxleInstance<V, R, P> = [value: Ref<V>, run: Run<V, R, P>, extra: UseAxleExtra<V>];
54
+ type UseAxleInstance<V, R, P, D> = [value: Ref<V>, run: Run<V, R, P, D>, extra: UseAxleExtra<V>];
55
55
  interface CreateUseAxleOptions {
56
56
  axle: AxleInstance;
57
57
  immediate?: boolean;
58
58
  onTransform?(response: any, refs: any): any;
59
59
  }
60
- type UseAxle = <V = any, R = any, P = Record<string, any>>(options: UseAxleOptions<V, R, P>) => UseAxleInstance<V, R, P>;
60
+ type UseAxle = <V = any, R = any, P = Record<string, any>, D = Record<string, any>>(options: UseAxleOptions<V, R, P, D>) => UseAxleInstance<V, R, P, D>;
61
61
  declare function normalizeValueGetter<T>(valueGetter: T | (() => T)): T;
62
62
  declare function createUseAxle(options: CreateUseAxleOptions): UseAxle;
63
63
 
package/lib/use.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Ref, WritableComputedRef } from 'vue';
2
- import { A as AxleRequestConfig, d as RunnerMethod, e as AxleInstance } from './instance-6ab5bfe4.js';
2
+ import { A as AxleRequestConfig, d as RunnerMethod, e as AxleInstance } from './instance-ab0b388e.js';
3
3
  import 'axios';
4
4
 
5
5
  declare function useValues<T extends Ref<any>[]>(...valueCollection: T): WritableComputedRef<T[number]['value'][]>;
@@ -8,10 +8,10 @@ declare function useHasLoading(...loadings: Ref<boolean>[]): Ref<boolean>;
8
8
 
9
9
  declare function useAverageProgress(...progressCollection: Ref<number>[]): Ref<number>;
10
10
 
11
- interface RunOptions<V, P> {
11
+ interface RunOptions<V, P, D> {
12
12
  url?: string;
13
13
  params?: P;
14
- config?: AxleRequestConfig;
14
+ config?: AxleRequestConfig<D>;
15
15
  resetValue?: boolean;
16
16
  cloneResetValue?: boolean | ((value: V) => V);
17
17
  }
@@ -30,10 +30,10 @@ interface UseAxleRefs<V> {
30
30
  uploadProgress: Ref<number>;
31
31
  downloadProgress: Ref<number>;
32
32
  }
33
- type Run<V, R, P> = {
34
- (options?: RunOptions<V, P>): Promise<R>;
33
+ type Run<V, R, P, D> = {
34
+ (options?: RunOptions<V, P, D>): Promise<R>;
35
35
  } & UseAxleExtra<V>;
36
- interface UseAxleOptions<V = any, R = any, P = Record<string, any>> {
36
+ interface UseAxleOptions<V = any, R = any, P = Record<string, any>, D = Record<string, any>> {
37
37
  url: string | (() => string);
38
38
  method: RunnerMethod;
39
39
  value?: V;
@@ -41,7 +41,7 @@ interface UseAxleOptions<V = any, R = any, P = Record<string, any>> {
41
41
  resetValue?: boolean;
42
42
  cloneResetValue?: boolean | ((value: V) => V);
43
43
  immediate?: boolean;
44
- config?: AxleRequestConfig | (() => AxleRequestConfig);
44
+ config?: AxleRequestConfig<D> | (() => AxleRequestConfig<D>);
45
45
  onBefore?(refs: UseAxleRefs<V>): void;
46
46
  onAfter?(refs: UseAxleRefs<V>): void;
47
47
  onTransform?(response: R, refs: UseAxleRefs<V>): V | Promise<V>;
@@ -51,13 +51,13 @@ interface UseAxleOptions<V = any, R = any, P = Record<string, any>> {
51
51
  interface ResetValueOptions<V> {
52
52
  cloneResetValue?: boolean | ((value: V) => V);
53
53
  }
54
- type UseAxleInstance<V, R, P> = [value: Ref<V>, run: Run<V, R, P>, extra: UseAxleExtra<V>];
54
+ type UseAxleInstance<V, R, P, D> = [value: Ref<V>, run: Run<V, R, P, D>, extra: UseAxleExtra<V>];
55
55
  interface CreateUseAxleOptions {
56
56
  axle: AxleInstance;
57
57
  immediate?: boolean;
58
58
  onTransform?(response: any, refs: any): any;
59
59
  }
60
- type UseAxle = <V = any, R = any, P = Record<string, any>>(options: UseAxleOptions<V, R, P>) => UseAxleInstance<V, R, P>;
60
+ type UseAxle = <V = any, R = any, P = Record<string, any>, D = Record<string, any>>(options: UseAxleOptions<V, R, P, D>) => UseAxleInstance<V, R, P, D>;
61
61
  declare function normalizeValueGetter<T>(valueGetter: T | (() => T)): T;
62
62
  declare function createUseAxle(options: CreateUseAxleOptions): UseAxle;
63
63
 
package/package.json CHANGED
@@ -1,19 +1,25 @@
1
1
  {
2
2
  "name": "@varlet/axle",
3
- "version": "0.10.1",
3
+ "version": "0.10.2-alpha.1737055052455",
4
4
  "description": "Progressive request tool based on axios",
5
- "type": "module",
6
- "main": "lib/index.cjs",
7
- "module": "lib/index.js",
8
- "types": "index.d.ts",
9
- "typesVersions": {
10
- "*": {
11
- "*": [
12
- "./lib/*"
13
- ]
14
- }
5
+ "keywords": [
6
+ "axle",
7
+ "axios",
8
+ "helpers",
9
+ "vue3",
10
+ "composition api"
11
+ ],
12
+ "bugs": {
13
+ "url": "https://github.com/varletjs/axle/issues"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/varletjs/axle.git"
15
18
  },
19
+ "license": "MIT",
20
+ "author": "haoziqaq <357229046@qq.com>",
16
21
  "sideEffects": false,
22
+ "type": "module",
17
23
  "exports": {
18
24
  ".": {
19
25
  "import": "./lib/index.js",
@@ -32,28 +38,26 @@
32
38
  },
33
39
  "./*": "./*"
34
40
  },
41
+ "main": "lib/index.cjs",
42
+ "module": "lib/index.js",
43
+ "types": "index.d.ts",
44
+ "typesVersions": {
45
+ "*": {
46
+ "*": [
47
+ "./lib/*"
48
+ ]
49
+ }
50
+ },
35
51
  "files": [
36
52
  "lib"
37
53
  ],
38
- "keywords": [
39
- "axle",
40
- "axios",
41
- "helpers",
42
- "vue3",
43
- "composition api"
44
- ],
45
- "author": "haoziqaq <357229046@qq.com>",
46
- "license": "MIT",
47
54
  "dependencies": {
48
- "rattail": "1.0.0",
49
55
  "axios": "^1.7.3",
50
56
  "crypto-js": "^4.2.0",
51
57
  "lodash": "4.17.21",
52
58
  "minimatch": "^9.0.3",
53
- "qs": "^6.11.0"
54
- },
55
- "peerDependencies": {
56
- "vue": "^3.2.0"
59
+ "qs": "^6.11.0",
60
+ "rattail": "1.0.0"
57
61
  },
58
62
  "devDependencies": {
59
63
  "@types/crypto-js": "^4.2.1",
@@ -64,15 +68,11 @@
64
68
  "typescript": "^5.1.5",
65
69
  "vue": "3.3.4"
66
70
  },
67
- "repository": {
68
- "type": "git",
69
- "url": "git+https://github.com/varletjs/axle.git"
70
- },
71
- "bugs": {
72
- "url": "https://github.com/varletjs/axle/issues"
71
+ "peerDependencies": {
72
+ "vue": "^3.2.0"
73
73
  },
74
74
  "scripts": {
75
- "dev": "tsup src/index.ts src/use.ts src/api.ts --format esm --out-dir=lib --watch --dts",
76
- "build": "tsup src/index.ts src/use.ts src/api.ts --format esm,cjs --out-dir=lib --dts --clean"
75
+ "build": "tsup src/index.ts src/use.ts src/api.ts --format esm,cjs --out-dir=lib --dts --clean",
76
+ "dev": "tsup src/index.ts src/use.ts src/api.ts --format esm --out-dir=lib --watch --dts"
77
77
  }
78
78
  }