@ametie/vue-muza-use 1.2.0 → 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.
Files changed (2) hide show
  1. package/dist/index.cjs +154 -208
  2. package/package.json +4 -1
package/dist/index.cjs CHANGED
@@ -1,58 +1,5 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.ts
31
- var index_exports = {};
32
- __export(index_exports, {
33
- AuthEventType: () => AuthEventType,
34
- clearAllCache: () => clearAllCache,
35
- createApi: () => createApi,
36
- createApiClient: () => createApiClient,
37
- invalidateCache: () => invalidateCache,
38
- setAuthMonitor: () => setAuthMonitor,
39
- setupInterceptors: () => setupInterceptors,
40
- tokenManager: () => tokenManager,
41
- useAbortController: () => useAbortController,
42
- useApi: () => useApi,
43
- useApiBatch: () => useApiBatch,
44
- useApiConfig: () => useApiConfig,
45
- useApiDelete: () => useApiDelete,
46
- useApiGet: () => useApiGet,
47
- useApiPatch: () => useApiPatch,
48
- useApiPost: () => useApiPost,
49
- useApiPut: () => useApiPut,
50
- useApiState: () => useApiState
51
- });
52
- module.exports = __toCommonJS(index_exports);
53
-
54
- // src/plugin.ts
55
- var import_vue = require("vue");
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2;// src/plugin.ts
2
+ var _vue = require('vue');
56
3
 
57
4
  // src/devtools.ts
58
5
  var bridge = null;
@@ -64,11 +11,11 @@ function nextRequestId() {
64
11
  async function initDevtools(options, app) {
65
12
  if (!options.enabled) return;
66
13
  try {
67
- const { createBridge } = await import("@ametie/vue-muza-devtools");
14
+ const { createBridge } = await Promise.resolve().then(() => _interopRequireWildcard(require("@ametie/vue-muza-devtools")));
68
15
  bridge = createBridge(options, app);
69
16
  for (const fn of pendingCalls) fn();
70
17
  pendingCalls.length = 0;
71
- } catch {
18
+ } catch (e) {
72
19
  console.warn("[vue-muza-use] devtools enabled but @ametie/vue-muza-devtools is not installed");
73
20
  }
74
21
  }
@@ -77,20 +24,20 @@ var devtoolsBridge = {
77
24
  if (bridge) {
78
25
  bridge.onInstanceCreated(id, url, options);
79
26
  } else {
80
- pendingCalls.push(() => bridge?.onInstanceCreated(id, url, options));
27
+ pendingCalls.push(() => _optionalChain([bridge, 'optionalAccess', _ => _.onInstanceCreated, 'call', _2 => _2(id, url, options)]));
81
28
  }
82
29
  },
83
30
  onInstanceDestroyed(id) {
84
- bridge?.onInstanceDestroyed(id);
31
+ _optionalChain([bridge, 'optionalAccess', _3 => _3.onInstanceDestroyed, 'call', _4 => _4(id)]);
85
32
  },
86
33
  onStateUpdate(id, state) {
87
- bridge?.onStateUpdate(id, state);
34
+ _optionalChain([bridge, 'optionalAccess', _5 => _5.onStateUpdate, 'call', _6 => _6(id, state)]);
88
35
  },
89
36
  onRequestStart(record) {
90
- bridge?.onRequestStart(record);
37
+ _optionalChain([bridge, 'optionalAccess', _7 => _7.onRequestStart, 'call', _8 => _8(record)]);
91
38
  },
92
39
  onRequestEnd(id, result) {
93
- bridge?.onRequestEnd(id, result);
40
+ _optionalChain([bridge, 'optionalAccess', _9 => _9.onRequestEnd, 'call', _10 => _10(id, result)]);
94
41
  }
95
42
  };
96
43
 
@@ -112,7 +59,7 @@ function useApiConfig() {
112
59
  if (globalConfig) {
113
60
  return globalConfig;
114
61
  }
115
- const config = (0, import_vue.inject)(API_INJECTION_KEY, null);
62
+ const config = _vue.inject.call(void 0, API_INJECTION_KEY, null);
116
63
  if (!config) {
117
64
  throw new Error(
118
65
  "API plugin not installed!\n\nMake sure you have called app.use(createApi(...)) in your main.ts:\n\nimport { createApi, createApiClient } from '@ametie/vue-muza-use'\n\nconst api = createApiClient({ baseURL: '...' })\n\napp.use(createApi({\n axios: api,\n onError: (error) => console.error(error)\n}))"
@@ -122,13 +69,13 @@ function useApiConfig() {
122
69
  }
123
70
 
124
71
  // src/utils/debounce.ts
125
- var DebounceCancelledError = class extends Error {
126
- isDebounceCancelled = true;
72
+ var DebounceCancelledError = (_class = class extends Error {
73
+ __init() {this.isDebounceCancelled = true}
127
74
  constructor() {
128
- super("Debounced call was superseded by a newer call");
75
+ super("Debounced call was superseded by a newer call");_class.prototype.__init.call(this);;
129
76
  this.name = "DebounceCancelledError";
130
77
  }
131
- };
78
+ }, _class);
132
79
  function debounceFn(fn, delay) {
133
80
  let timeoutId = null;
134
81
  let pendingReject = null;
@@ -168,22 +115,22 @@ function parseUrlQueryParams(url) {
168
115
  }
169
116
 
170
117
  // src/useApi.ts
171
- var import_axios2 = require("axios");
172
- var import_vue5 = require("vue");
118
+ var _axios = require('axios'); var _axios2 = _interopRequireDefault(_axios);
119
+
173
120
 
174
121
  // src/utils/errorParser.ts
175
- var import_axios = require("axios");
122
+
176
123
  function parseApiError(error) {
177
- if ((0, import_axios.isAxiosError)(error)) {
124
+ if (_axios.isAxiosError.call(void 0, error)) {
178
125
  const axiosError = error;
179
126
  if (axiosError.response) {
180
127
  const { data, status } = axiosError.response;
181
- const message = data?.message || data?.error || axiosError.message || "Unknown Error";
128
+ const message = _optionalChain([data, 'optionalAccess', _11 => _11.message]) || _optionalChain([data, 'optionalAccess', _12 => _12.error]) || axiosError.message || "Unknown Error";
182
129
  return {
183
130
  message,
184
131
  status,
185
- code: data?.code,
186
- errors: data?.errors,
132
+ code: _optionalChain([data, 'optionalAccess', _13 => _13.code]),
133
+ errors: _optionalChain([data, 'optionalAccess', _14 => _14.errors]),
187
134
  details: data
188
135
  };
189
136
  }
@@ -195,14 +142,14 @@ function parseApiError(error) {
195
142
  }
196
143
 
197
144
  // src/composables/useApiState.ts
198
- var import_vue2 = require("vue");
145
+
199
146
  function useApiState(initialData = null, options = {}) {
200
147
  const { initialLoading = false } = options;
201
- const data = (0, import_vue2.ref)(initialData);
202
- const loading = (0, import_vue2.ref)(initialLoading);
203
- const error = (0, import_vue2.ref)(null);
204
- const statusCode = (0, import_vue2.ref)(null);
205
- const response = (0, import_vue2.ref)(null);
148
+ const data = _vue.ref.call(void 0, initialData);
149
+ const loading = _vue.ref.call(void 0, initialLoading);
150
+ const error = _vue.ref.call(void 0, null);
151
+ const statusCode = _vue.ref.call(void 0, null);
152
+ const response = _vue.ref.call(void 0, null);
206
153
  const mutate = (newDataOrUpdater, fullResponse) => {
207
154
  if (typeof newDataOrUpdater === "function") {
208
155
  const updater = newDataOrUpdater;
@@ -246,11 +193,11 @@ function useApiState(initialData = null, options = {}) {
246
193
  }
247
194
 
248
195
  // src/composables/useAbortController.ts
249
- var import_vue3 = require("vue");
196
+
250
197
  var abortController = new AbortController();
251
- var abortCount = (0, import_vue3.ref)(0);
198
+ var abortCount = _vue.ref.call(void 0, 0);
252
199
  function useAbortController() {
253
- const signal = (0, import_vue3.readonly)((0, import_vue3.ref)(abortController.signal));
200
+ const signal = _vue.readonly.call(void 0, _vue.ref.call(void 0, abortController.signal));
254
201
  const abort = () => {
255
202
  abortCount.value++;
256
203
  abortController.abort();
@@ -267,7 +214,7 @@ function useAbortController() {
267
214
  abort,
268
215
  getSignal,
269
216
  isAbortError,
270
- abortCount: (0, import_vue3.readonly)(abortCount)
217
+ abortCount: _vue.readonly.call(void 0, abortCount)
271
218
  };
272
219
  }
273
220
 
@@ -296,7 +243,7 @@ function clearAllCache() {
296
243
  }
297
244
 
298
245
  // src/composables/useRefetchTriggers.ts
299
- var import_vue4 = require("vue");
246
+
300
247
  var DEFAULT_FOCUS_THROTTLE = 6e4;
301
248
  function useRefetchTriggers({
302
249
  refetchOnFocus,
@@ -309,7 +256,7 @@ function useRefetchTriggers({
309
256
  lastFetchedAt = Date.now();
310
257
  };
311
258
  if (refetchOnFocus && typeof document !== "undefined") {
312
- const throttle = typeof refetchOnFocus === "object" ? refetchOnFocus.throttle ?? DEFAULT_FOCUS_THROTTLE : DEFAULT_FOCUS_THROTTLE;
259
+ const throttle = typeof refetchOnFocus === "object" ? _nullishCoalesce(refetchOnFocus.throttle, () => ( DEFAULT_FOCUS_THROTTLE)) : DEFAULT_FOCUS_THROTTLE;
313
260
  const handleFocus = () => {
314
261
  if (document.hidden) return;
315
262
  if (loading.value) return;
@@ -317,8 +264,8 @@ function useRefetchTriggers({
317
264
  onTrigger();
318
265
  };
319
266
  document.addEventListener("visibilitychange", handleFocus);
320
- if ((0, import_vue4.getCurrentScope)()) {
321
- (0, import_vue4.onScopeDispose)(() => document.removeEventListener("visibilitychange", handleFocus));
267
+ if (_vue.getCurrentScope.call(void 0, )) {
268
+ _vue.onScopeDispose.call(void 0, () => document.removeEventListener("visibilitychange", handleFocus));
322
269
  }
323
270
  }
324
271
  if (refetchOnReconnect && typeof window !== "undefined") {
@@ -327,8 +274,8 @@ function useRefetchTriggers({
327
274
  onTrigger();
328
275
  };
329
276
  window.addEventListener("online", handleReconnect);
330
- if ((0, import_vue4.getCurrentScope)()) {
331
- (0, import_vue4.onScopeDispose)(() => window.removeEventListener("online", handleReconnect));
277
+ if (_vue.getCurrentScope.call(void 0, )) {
278
+ _vue.onScopeDispose.call(void 0, () => window.removeEventListener("online", handleReconnect));
332
279
  }
333
280
  }
334
281
  return { notifyFetched };
@@ -341,7 +288,7 @@ function normalizeCacheOptions(cache) {
341
288
  if (typeof cache === "string") {
342
289
  return { id: cache, staleTime: DEFAULT_STALE_TIME, swr: false };
343
290
  }
344
- return { id: cache.id, staleTime: cache.staleTime ?? DEFAULT_STALE_TIME, swr: cache.swr ?? false };
291
+ return { id: cache.id, staleTime: _nullishCoalesce(cache.staleTime, () => ( DEFAULT_STALE_TIME)), swr: _nullishCoalesce(cache.swr, () => ( false)) };
345
292
  }
346
293
  function cancellableSleep(ms, signal) {
347
294
  return new Promise((resolve) => {
@@ -374,11 +321,11 @@ function useApi(url, options = {}) {
374
321
  initialData = null,
375
322
  debounce = 0,
376
323
  skipErrorNotification = false,
377
- retry = globalOptions?.retry ?? false,
378
- retryDelay = globalOptions?.retryDelay ?? 1e3,
379
- retryStatusCodes = globalOptions?.retryStatusCodes ?? DEFAULT_RETRY_STATUS_CODES,
324
+ retry = _nullishCoalesce(_optionalChain([globalOptions, 'optionalAccess', _15 => _15.retry]), () => ( false)),
325
+ retryDelay = _nullishCoalesce(_optionalChain([globalOptions, 'optionalAccess', _16 => _16.retryDelay]), () => ( 1e3)),
326
+ retryStatusCodes = _nullishCoalesce(_optionalChain([globalOptions, 'optionalAccess', _17 => _17.retryStatusCodes]), () => ( DEFAULT_RETRY_STATUS_CODES)),
380
327
  authMode = "default",
381
- useGlobalAbort = globalOptions?.useGlobalAbort ?? true,
328
+ useGlobalAbort = _nullishCoalesce(_optionalChain([globalOptions, 'optionalAccess', _18 => _18.useGlobalAbort]), () => ( true)),
382
329
  initialLoading = false,
383
330
  poll = 0,
384
331
  // Explicitly excluded from axiosConfig — these are useApi-only options
@@ -393,23 +340,23 @@ function useApi(url, options = {}) {
393
340
  } = options;
394
341
  const maxRetries = retry === false ? 0 : retry === true ? 3 : retry;
395
342
  const applySelect = (raw) => select ? select(raw) : raw;
396
- const startLoading = initialLoading ?? immediate;
343
+ const startLoading = _nullishCoalesce(initialLoading, () => ( immediate));
397
344
  const state = useApiState(initialData, { initialLoading: startLoading });
398
- const revalidating = (0, import_vue5.ref)(false);
399
- const instanceId = (0, import_vue5.getCurrentInstance)() != null ? (0, import_vue5.useId)() : nextRequestId();
400
- devtoolsBridge.onInstanceCreated(instanceId, (0, import_vue5.toValue)(url), {
401
- authMode: options.authMode ?? "default",
345
+ const revalidating = _vue.ref.call(void 0, false);
346
+ const instanceId = _vue.getCurrentInstance.call(void 0, ) != null ? _vue.useId.call(void 0, ) : nextRequestId();
347
+ devtoolsBridge.onInstanceCreated(instanceId, _vue.toValue.call(void 0, url), {
348
+ authMode: _nullishCoalesce(options.authMode, () => ( "default")),
402
349
  cache: options.cache,
403
- retry: options.retry ?? false,
350
+ retry: _nullishCoalesce(options.retry, () => ( false)),
404
351
  poll: (() => {
405
- const v = (0, import_vue5.toValue)(options.poll);
352
+ const v = _vue.toValue.call(void 0, options.poll);
406
353
  return typeof v === "number" ? v : 0;
407
354
  })(),
408
- immediate: options.immediate ?? false,
409
- lazy: options.lazy ?? false
355
+ immediate: _nullishCoalesce(options.immediate, () => ( false)),
356
+ lazy: _nullishCoalesce(options.lazy, () => ( false))
410
357
  });
411
- if ((0, import_vue5.getCurrentScope)()) {
412
- (0, import_vue5.watch)(
358
+ if (_vue.getCurrentScope.call(void 0, )) {
359
+ _vue.watch.call(void 0,
413
360
  () => ({
414
361
  loading: state.loading.value,
415
362
  error: state.error.value,
@@ -420,18 +367,18 @@ function useApi(url, options = {}) {
420
367
  { deep: true }
421
368
  );
422
369
  }
423
- const abortController2 = (0, import_vue5.ref)(null);
370
+ const abortController2 = _vue.ref.call(void 0, null);
424
371
  const globalAbort = useGlobalAbort ? useAbortController() : null;
425
372
  let pollTimer = null;
426
373
  let notifyFetched = () => {
427
374
  };
428
375
  const getPollConfig = () => {
429
- const val = (0, import_vue5.toValue)(poll);
376
+ const val = _vue.toValue.call(void 0, poll);
430
377
  if (typeof val === "number") return { interval: val, whenHidden: false };
431
378
  if (val && typeof val === "object") {
432
379
  return {
433
- interval: (0, import_vue5.toValue)(val.interval),
434
- whenHidden: (0, import_vue5.toValue)(val.whenHidden) ?? false
380
+ interval: _vue.toValue.call(void 0, val.interval),
381
+ whenHidden: _nullishCoalesce(_vue.toValue.call(void 0, val.whenHidden), () => ( false))
435
382
  };
436
383
  }
437
384
  return { interval: 0, whenHidden: false };
@@ -451,11 +398,11 @@ function useApi(url, options = {}) {
451
398
  }
452
399
  }
453
400
  if (pollTimer) clearTimeout(pollTimer);
454
- const requestUrl = (0, import_vue5.toValue)(url);
401
+ const requestUrl = _vue.toValue.call(void 0, url);
455
402
  if (abortController2.value) abortController2.value.abort("Cancelled by new request");
456
403
  const controller = new AbortController();
457
404
  abortController2.value = controller;
458
- if (config?.signal) {
405
+ if (_optionalChain([config, 'optionalAccess', _19 => _19.signal])) {
459
406
  const signal = config.signal;
460
407
  if (signal.aborted) {
461
408
  controller.abort(signal.reason);
@@ -478,7 +425,7 @@ function useApi(url, options = {}) {
478
425
  }
479
426
  }
480
427
  if (!isRevalidating) {
481
- onBefore?.();
428
+ _optionalChain([onBefore, 'optionalCall', _20 => _20()]);
482
429
  state.setLoading(true);
483
430
  }
484
431
  state.setError(null);
@@ -491,11 +438,11 @@ function useApi(url, options = {}) {
491
438
  if (!requestUrl) {
492
439
  throw new Error("Request URL is missing");
493
440
  }
494
- const rawData = config?.data !== void 0 ? config.data : axiosConfig.data;
495
- const resolvedData = (0, import_vue5.toValue)(rawData);
496
- const rawParams = config?.params !== void 0 ? config.params : axiosConfig.params;
497
- const resolvedParams = (0, import_vue5.toValue)(rawParams);
498
- const devtoolsQueryParams = resolvedParams ?? parseUrlQueryParams(requestUrl);
441
+ const rawData = _optionalChain([config, 'optionalAccess', _21 => _21.data]) !== void 0 ? config.data : axiosConfig.data;
442
+ const resolvedData = _vue.toValue.call(void 0, rawData);
443
+ const rawParams = _optionalChain([config, 'optionalAccess', _22 => _22.params]) !== void 0 ? config.params : axiosConfig.params;
444
+ const resolvedParams = _vue.toValue.call(void 0, rawParams);
445
+ const devtoolsQueryParams = _nullishCoalesce(resolvedParams, () => ( parseUrlQueryParams(requestUrl)));
499
446
  devtoolsRequestId = nextRequestId();
500
447
  devtoolsRequestStartedAt = Date.now();
501
448
  devtoolsBridge.onRequestStart({
@@ -507,7 +454,7 @@ function useApi(url, options = {}) {
507
454
  status: "pending",
508
455
  statusCode: null,
509
456
  requestHeaders: {},
510
- payload: resolvedData ?? null,
457
+ payload: _nullishCoalesce(resolvedData, () => ( null)),
511
458
  queryParams: devtoolsQueryParams
512
459
  });
513
460
  while (true) {
@@ -520,7 +467,7 @@ function useApi(url, options = {}) {
520
467
  data: resolvedData,
521
468
  params: resolvedParams,
522
469
  signal: controller.signal,
523
- ...{ authMode: config?.authMode || authMode }
470
+ ...{ authMode: _optionalChain([config, 'optionalAccess', _23 => _23.authMode]) || authMode }
524
471
  });
525
472
  const selected = applySelect(response.data);
526
473
  state.mutate(selected, response);
@@ -531,7 +478,7 @@ function useApi(url, options = {}) {
531
478
  if (options.invalidateCache) {
532
479
  invalidateCache(options.invalidateCache);
533
480
  }
534
- onSuccess?.(response);
481
+ _optionalChain([onSuccess, 'optionalCall', _24 => _24(response)]);
535
482
  notifyFetched();
536
483
  devtoolsRequestEndResult = {
537
484
  status: "success",
@@ -541,7 +488,7 @@ function useApi(url, options = {}) {
541
488
  };
542
489
  return selected;
543
490
  } catch (err) {
544
- if (controller.signal.aborted || (0, import_axios2.isAxiosError)(err) && err.code === "ERR_CANCELED") {
491
+ if (controller.signal.aborted || _axios.isAxiosError.call(void 0, err) && err.code === "ERR_CANCELED") {
545
492
  wasCancelled = true;
546
493
  return null;
547
494
  }
@@ -560,7 +507,7 @@ function useApi(url, options = {}) {
560
507
  devtoolsRequestEndResult = {
561
508
  status: "error",
562
509
  error: apiError,
563
- statusCode: apiError.status ?? null,
510
+ statusCode: _nullishCoalesce(apiError.status, () => ( null)),
564
511
  duration: Date.now() - devtoolsRequestStartedAt
565
512
  };
566
513
  if (!skipErrorNotification && globalErrorHandler) {
@@ -568,12 +515,12 @@ function useApi(url, options = {}) {
568
515
  }
569
516
  state.setError(apiError);
570
517
  state.setStatusCode(apiError.status);
571
- onError?.(apiError);
518
+ _optionalChain([onError, 'optionalCall', _25 => _25(apiError)]);
572
519
  return null;
573
520
  }
574
521
  }
575
522
  } catch (err) {
576
- if (controller.signal.aborted || (0, import_axios2.isAxiosError)(err) && err.code === "ERR_CANCELED") {
523
+ if (controller.signal.aborted || _axios.isAxiosError.call(void 0, err) && err.code === "ERR_CANCELED") {
577
524
  wasCancelled = true;
578
525
  return null;
579
526
  }
@@ -589,20 +536,20 @@ function useApi(url, options = {}) {
589
536
  }
590
537
  state.setError(apiError);
591
538
  state.setStatusCode(apiError.status);
592
- onError?.(apiError);
539
+ _optionalChain([onError, 'optionalCall', _26 => _26(apiError)]);
593
540
  return null;
594
541
  } finally {
595
542
  if (devtoolsRequestId !== null) {
596
543
  devtoolsBridge.onRequestEnd(
597
544
  devtoolsRequestId,
598
- devtoolsRequestEndResult ?? { status: "aborted", duration: Date.now() - devtoolsRequestStartedAt }
545
+ _nullishCoalesce(devtoolsRequestEndResult, () => ( { status: "aborted", duration: Date.now() - devtoolsRequestStartedAt }))
599
546
  );
600
547
  }
601
548
  if (globalAbortHandler && subscribedSignal) subscribedSignal.removeEventListener("abort", globalAbortHandler);
602
549
  revalidating.value = false;
603
550
  if (!wasCancelled) {
604
551
  if (!isRevalidating) state.setLoading(false);
605
- onFinish?.();
552
+ _optionalChain([onFinish, 'optionalCall', _27 => _27()]);
606
553
  const { interval, whenHidden } = getPollConfig();
607
554
  if (interval > 0) {
608
555
  const shouldPoll = whenHidden || typeof document !== "undefined" && !document.hidden;
@@ -626,7 +573,7 @@ function useApi(url, options = {}) {
626
573
  }) : executeRequest;
627
574
  const abort = (msg) => {
628
575
  if (pollTimer) clearTimeout(pollTimer);
629
- abortController2.value?.abort(msg);
576
+ _optionalChain([abortController2, 'access', _28 => _28.value, 'optionalAccess', _29 => _29.abort, 'call', _30 => _30(msg)]);
630
577
  abortController2.value = null;
631
578
  };
632
579
  const reset = () => {
@@ -634,8 +581,8 @@ function useApi(url, options = {}) {
634
581
  state.reset();
635
582
  state.setLoading(false);
636
583
  };
637
- const refetchOnFocus = _refetchOnFocus ?? globalOptions?.refetchOnFocus;
638
- const refetchOnReconnect = _refetchOnReconnect ?? globalOptions?.refetchOnReconnect;
584
+ const refetchOnFocus = _nullishCoalesce(_refetchOnFocus, () => ( _optionalChain([globalOptions, 'optionalAccess', _31 => _31.refetchOnFocus])));
585
+ const refetchOnReconnect = _nullishCoalesce(_refetchOnReconnect, () => ( _optionalChain([globalOptions, 'optionalAccess', _32 => _32.refetchOnReconnect])));
639
586
  const { notifyFetched: _notifyFetched } = useRefetchTriggers({
640
587
  refetchOnFocus,
641
588
  refetchOnReconnect,
@@ -645,12 +592,12 @@ function useApi(url, options = {}) {
645
592
  notifyFetched = _notifyFetched;
646
593
  let trackingScope;
647
594
  const startAutoTracking = () => {
648
- trackingScope = (0, import_vue5.effectScope)();
595
+ trackingScope = _vue.effectScope.call(void 0, );
649
596
  trackingScope.run(() => {
650
- const urlComputed = (0, import_vue5.computed)(() => (0, import_vue5.toValue)(url));
651
- const paramsComputed = (0, import_vue5.computed)(() => (0, import_vue5.toValue)(options.params));
652
- const dataComputed = (0, import_vue5.computed)(() => (0, import_vue5.toValue)(options.data));
653
- (0, import_vue5.watch)(
597
+ const urlComputed = _vue.computed.call(void 0, () => _vue.toValue.call(void 0, url));
598
+ const paramsComputed = _vue.computed.call(void 0, () => _vue.toValue.call(void 0, options.params));
599
+ const dataComputed = _vue.computed.call(void 0, () => _vue.toValue.call(void 0, options.data));
600
+ _vue.watch.call(void 0,
654
601
  [urlComputed, paramsComputed, dataComputed],
655
602
  () => execute(),
656
603
  { flush: "pre", deep: true }
@@ -659,22 +606,22 @@ function useApi(url, options = {}) {
659
606
  };
660
607
  if (!lazy) {
661
608
  startAutoTracking();
662
- if ((0, import_vue5.getCurrentScope)()) {
663
- (0, import_vue5.onScopeDispose)(() => trackingScope.stop());
609
+ if (_vue.getCurrentScope.call(void 0, )) {
610
+ _vue.onScopeDispose.call(void 0, () => trackingScope.stop());
664
611
  }
665
612
  }
666
613
  const ignoreUpdates = (updater) => {
667
- trackingScope?.pause();
614
+ _optionalChain([trackingScope, 'optionalAccess', _33 => _33.pause, 'call', _34 => _34()]);
668
615
  try {
669
616
  updater();
670
617
  } finally {
671
- trackingScope?.resume();
672
- trackingScope?.stop();
618
+ _optionalChain([trackingScope, 'optionalAccess', _35 => _35.resume, 'call', _36 => _36()]);
619
+ _optionalChain([trackingScope, 'optionalAccess', _37 => _37.stop, 'call', _38 => _38()]);
673
620
  if (!lazy) startAutoTracking();
674
621
  }
675
622
  };
676
- if ((0, import_vue5.getCurrentScope)()) {
677
- (0, import_vue5.onScopeDispose)(() => {
623
+ if (_vue.getCurrentScope.call(void 0, )) {
624
+ _vue.onScopeDispose.call(void 0, () => {
678
625
  abort("Scope disposed");
679
626
  devtoolsBridge.onInstanceDestroyed(instanceId);
680
627
  });
@@ -689,12 +636,12 @@ function useApi(url, options = {}) {
689
636
  }
690
637
  };
691
638
  document.addEventListener("visibilitychange", handleVisibility);
692
- if ((0, import_vue5.getCurrentScope)()) {
693
- (0, import_vue5.onScopeDispose)(() => document.removeEventListener("visibilitychange", handleVisibility));
639
+ if (_vue.getCurrentScope.call(void 0, )) {
640
+ _vue.onScopeDispose.call(void 0, () => document.removeEventListener("visibilitychange", handleVisibility));
694
641
  }
695
642
  }
696
643
  if (poll) {
697
- (0, import_vue5.watch)(() => (0, import_vue5.toValue)(poll), () => {
644
+ _vue.watch.call(void 0, () => _vue.toValue.call(void 0, poll), () => {
698
645
  const { interval } = getPollConfig();
699
646
  if (interval > 0) {
700
647
  if (pollTimer) {
@@ -733,7 +680,7 @@ function useApiDelete(url, options) {
733
680
  }
734
681
 
735
682
  // src/useApiBatch.ts
736
- var import_vue6 = require("vue");
683
+
737
684
  function normalizeRequest(item) {
738
685
  if (typeof item === "string") return { url: item, method: "GET" };
739
686
  return { method: "GET", ...item };
@@ -753,30 +700,30 @@ function useApiBatch(requests, options = {}) {
753
700
  onProgress,
754
701
  ...apiOptions
755
702
  } = options;
756
- const getRequests = () => (0, import_vue6.toValue)(requests).map(normalizeRequest);
757
- const data = (0, import_vue6.ref)([]);
758
- const loading = (0, import_vue6.ref)(false);
759
- const error = (0, import_vue6.ref)(null);
760
- const errors = (0, import_vue6.ref)([]);
761
- const progress = (0, import_vue6.ref)({
703
+ const getRequests = () => _vue.toValue.call(void 0, requests).map(normalizeRequest);
704
+ const data = _vue.ref.call(void 0, []);
705
+ const loading = _vue.ref.call(void 0, false);
706
+ const error = _vue.ref.call(void 0, null);
707
+ const errors = _vue.ref.call(void 0, []);
708
+ const progress = _vue.ref.call(void 0, {
762
709
  completed: 0,
763
710
  total: 0,
764
711
  percentage: 0,
765
712
  succeeded: 0,
766
713
  failed: 0
767
714
  });
768
- const successfulData = (0, import_vue6.computed)(
715
+ const successfulData = _vue.computed.call(void 0,
769
716
  () => data.value.filter((item) => item.success && item.data !== null).map((item) => item.data)
770
717
  );
771
- const abortControllers = (0, import_vue6.ref)([]);
718
+ const abortControllers = _vue.ref.call(void 0, []);
772
719
  let isAborted = false;
773
720
  let pollTimer = null;
774
721
  const getPollConfig = () => {
775
- const val = (0, import_vue6.toValue)(poll);
722
+ const val = _vue.toValue.call(void 0, poll);
776
723
  if (typeof val === "number") return { interval: val, whenHidden: false };
777
724
  return {
778
- interval: (0, import_vue6.toValue)(val.interval),
779
- whenHidden: (0, import_vue6.toValue)(val.whenHidden) ?? false
725
+ interval: _vue.toValue.call(void 0, val.interval),
726
+ whenHidden: _nullishCoalesce(_vue.toValue.call(void 0, val.whenHidden), () => ( false))
780
727
  };
781
728
  };
782
729
  const updateProgress = (succeeded, failed, total) => {
@@ -789,10 +736,10 @@ function useApiBatch(requests, options = {}) {
789
736
  failed
790
737
  };
791
738
  progress.value = newProgress;
792
- onProgress?.(newProgress);
739
+ _optionalChain([onProgress, 'optionalCall', _39 => _39(newProgress)]);
793
740
  };
794
741
  const executeRequest = async (config, index, signal) => {
795
- const scope = (0, import_vue6.effectScope)();
742
+ const scope = _vue.effectScope.call(void 0, );
796
743
  const api = scope.run(() => useApi(config.url, {
797
744
  ...apiOptions,
798
745
  method: config.method,
@@ -823,16 +770,16 @@ function useApiBatch(requests, options = {}) {
823
770
  url: config.url,
824
771
  index,
825
772
  success: result !== null && result !== void 0,
826
- data: result ?? null,
773
+ data: _nullishCoalesce(result, () => ( null)),
827
774
  error: reqError.value,
828
775
  statusCode: statusCode.value,
829
776
  response: response.value,
830
777
  request: config
831
778
  };
832
779
  if (item.success) {
833
- onItemSuccess?.(item, index);
780
+ _optionalChain([onItemSuccess, 'optionalCall', _40 => _40(item, index)]);
834
781
  } else if (item.error) {
835
- onItemError?.(item, index);
782
+ _optionalChain([onItemError, 'optionalCall', _41 => _41(item, index)]);
836
783
  }
837
784
  return item;
838
785
  } catch (err) {
@@ -851,7 +798,7 @@ function useApiBatch(requests, options = {}) {
851
798
  response: null,
852
799
  request: config
853
800
  };
854
- onItemError?.(item, index);
801
+ _optionalChain([onItemError, 'optionalCall', _42 => _42(item, index)]);
855
802
  return item;
856
803
  } finally {
857
804
  scope.stop();
@@ -956,7 +903,7 @@ function useApiBatch(requests, options = {}) {
956
903
  } finally {
957
904
  loading.value = false;
958
905
  abortControllers.value = [];
959
- onFinish?.(finalResults);
906
+ _optionalChain([onFinish, 'optionalCall', _43 => _43(finalResults)]);
960
907
  if (!isAborted) {
961
908
  const { interval, whenHidden } = getPollConfig();
962
909
  if (interval > 0) {
@@ -996,26 +943,26 @@ function useApiBatch(requests, options = {}) {
996
943
  failed: 0
997
944
  };
998
945
  };
999
- if ((0, import_vue6.getCurrentScope)()) {
1000
- (0, import_vue6.onScopeDispose)(() => abort("Scope disposed"));
946
+ if (_vue.getCurrentScope.call(void 0, )) {
947
+ _vue.onScopeDispose.call(void 0, () => abort("Scope disposed"));
1001
948
  }
1002
949
  if (!lazy && typeof requests === "function") {
1003
- const trackingScope = (0, import_vue6.effectScope)();
950
+ const trackingScope = _vue.effectScope.call(void 0, );
1004
951
  trackingScope.run(() => {
1005
- const requestsComputed = (0, import_vue6.computed)(
952
+ const requestsComputed = _vue.computed.call(void 0,
1006
953
  () => requests().map(normalizeRequest)
1007
954
  );
1008
- (0, import_vue6.watch)(requestsComputed, () => {
955
+ _vue.watch.call(void 0, requestsComputed, () => {
1009
956
  execute();
1010
957
  }, { deep: true });
1011
958
  });
1012
- if ((0, import_vue6.getCurrentScope)()) (0, import_vue6.onScopeDispose)(() => trackingScope.stop());
959
+ if (_vue.getCurrentScope.call(void 0, )) _vue.onScopeDispose.call(void 0, () => trackingScope.stop());
1013
960
  execute();
1014
961
  } else if (immediate) {
1015
962
  execute();
1016
963
  }
1017
964
  if (watchSource) {
1018
- (0, import_vue6.watch)(watchSource, () => {
965
+ _vue.watch.call(void 0, watchSource, () => {
1019
966
  execute();
1020
967
  }, { deep: true });
1021
968
  }
@@ -1033,7 +980,7 @@ function useApiBatch(requests, options = {}) {
1033
980
  }
1034
981
 
1035
982
  // src/features/createInstance.ts
1036
- var import_axios3 = __toESM(require("axios"), 1);
983
+
1037
984
 
1038
985
  // src/features/monitor.ts
1039
986
  var AuthEventType = /* @__PURE__ */ ((AuthEventType2) => {
@@ -1044,7 +991,7 @@ var AuthEventType = /* @__PURE__ */ ((AuthEventType2) => {
1044
991
  return AuthEventType2;
1045
992
  })(AuthEventType || {});
1046
993
  var defaultMonitor = (type, payload) => {
1047
- const isDev = typeof process !== "undefined" && process.env?.NODE_ENV === "development";
994
+ const isDev = typeof process !== "undefined" && _optionalChain([process, 'access', _44 => _44.env, 'optionalAccess', _45 => _45.NODE_ENV]) === "development";
1048
995
  if (isDev) {
1049
996
  console.debug(`[AuthMonitor] ${type}`, payload);
1050
997
  }
@@ -1063,9 +1010,9 @@ var ACCESS_TOKEN_KEY = "accessToken";
1063
1010
  var REFRESH_TOKEN_KEY = "refreshToken";
1064
1011
  var TOKEN_EXPIRES_KEY = "tokenExpiresAt";
1065
1012
  var LocalStorageTokenStorage = class {
1066
- storeRefreshToken;
1013
+
1067
1014
  constructor(options = {}) {
1068
- this.storeRefreshToken = options.storeRefreshToken ?? true;
1015
+ this.storeRefreshToken = _nullishCoalesce(options.storeRefreshToken, () => ( true));
1069
1016
  }
1070
1017
  getAccessToken() {
1071
1018
  return localStorage.getItem(ACCESS_TOKEN_KEY);
@@ -1108,10 +1055,10 @@ var LocalStorageTokenStorage = class {
1108
1055
  return Date.now() >= expiresAt - 5e3;
1109
1056
  }
1110
1057
  };
1111
- var TokenManager = class {
1112
- storage;
1113
- refreshPromise = null;
1114
- constructor(storage = new LocalStorageTokenStorage()) {
1058
+ var TokenManager = (_class2 = class {
1059
+
1060
+ __init2() {this.refreshPromise = null}
1061
+ constructor(storage = new LocalStorageTokenStorage()) {;_class2.prototype.__init2.call(this);
1115
1062
  this.storage = storage;
1116
1063
  }
1117
1064
  /**
@@ -1188,7 +1135,7 @@ var TokenManager = class {
1188
1135
  setStorage(storage) {
1189
1136
  this.storage = storage;
1190
1137
  }
1191
- };
1138
+ }, _class2);
1192
1139
  var tokenManager = new TokenManager();
1193
1140
 
1194
1141
  // src/features/interceptors.ts
@@ -1230,17 +1177,17 @@ function setupInterceptors(axiosInstance, options = {}) {
1230
1177
  (response) => response,
1231
1178
  async (error) => {
1232
1179
  const originalRequest = error.config;
1233
- if (!originalRequest || error.response?.status !== 401 || originalRequest._retry) {
1180
+ if (!originalRequest || _optionalChain([error, 'access', _46 => _46.response, 'optionalAccess', _47 => _47.status]) !== 401 || originalRequest._retry) {
1234
1181
  return Promise.reject(error);
1235
1182
  }
1236
1183
  if (originalRequest.authMode === "public" || originalRequest.authMode === "optional") {
1237
1184
  return Promise.reject(error);
1238
1185
  }
1239
- if (originalRequest.url?.includes(refreshUrl)) {
1186
+ if (_optionalChain([originalRequest, 'access', _48 => _48.url, 'optionalAccess', _49 => _49.includes, 'call', _50 => _50(refreshUrl)])) {
1240
1187
  isRefreshing = false;
1241
1188
  processQueue(error, null);
1242
1189
  tokenManager.clearTokens();
1243
- onTokenRefreshFailed?.();
1190
+ _optionalChain([onTokenRefreshFailed, 'optionalCall', _51 => _51()]);
1244
1191
  return Promise.reject(error);
1245
1192
  }
1246
1193
  if (isRefreshing) {
@@ -1298,7 +1245,7 @@ function setupInterceptors(axiosInstance, options = {}) {
1298
1245
  trackAuthEvent("AUTH_REFRESH_ERROR" /* REFRESH_ERROR */, { error: refreshError });
1299
1246
  processQueue(refreshError, null);
1300
1247
  tokenManager.clearTokens();
1301
- onTokenRefreshFailed?.();
1248
+ _optionalChain([onTokenRefreshFailed, 'optionalCall', _52 => _52()]);
1302
1249
  return Promise.reject(refreshError);
1303
1250
  } finally {
1304
1251
  isRefreshing = false;
@@ -1314,9 +1261,9 @@ function createApiClient(options = {}) {
1314
1261
  authOptions,
1315
1262
  ...axiosConfig
1316
1263
  } = options;
1317
- const storeRefreshToken = !authOptions?.refreshWithCredentials;
1264
+ const storeRefreshToken = !_optionalChain([authOptions, 'optionalAccess', _53 => _53.refreshWithCredentials]);
1318
1265
  tokenManager.setStorage(new LocalStorageTokenStorage({ storeRefreshToken }));
1319
- const instance = import_axios3.default.create({
1266
+ const instance = _axios2.default.create({
1320
1267
  timeout: 6e4,
1321
1268
  headers: { "Content-Type": "application/json" },
1322
1269
  ...axiosConfig
@@ -1326,24 +1273,23 @@ function createApiClient(options = {}) {
1326
1273
  }
1327
1274
  return instance;
1328
1275
  }
1329
- // Annotate the CommonJS export names for ESM import in node:
1330
- 0 && (module.exports = {
1331
- AuthEventType,
1332
- clearAllCache,
1333
- createApi,
1334
- createApiClient,
1335
- invalidateCache,
1336
- setAuthMonitor,
1337
- setupInterceptors,
1338
- tokenManager,
1339
- useAbortController,
1340
- useApi,
1341
- useApiBatch,
1342
- useApiConfig,
1343
- useApiDelete,
1344
- useApiGet,
1345
- useApiPatch,
1346
- useApiPost,
1347
- useApiPut,
1348
- useApiState
1349
- });
1276
+
1277
+
1278
+
1279
+
1280
+
1281
+
1282
+
1283
+
1284
+
1285
+
1286
+
1287
+
1288
+
1289
+
1290
+
1291
+
1292
+
1293
+
1294
+
1295
+ exports.AuthEventType = AuthEventType; exports.clearAllCache = clearAllCache; exports.createApi = createApi; exports.createApiClient = createApiClient; exports.invalidateCache = invalidateCache; exports.setAuthMonitor = setAuthMonitor; exports.setupInterceptors = setupInterceptors; exports.tokenManager = tokenManager; exports.useAbortController = useAbortController; exports.useApi = useApi; exports.useApiBatch = useApiBatch; exports.useApiConfig = useApiConfig; exports.useApiDelete = useApiDelete; exports.useApiGet = useApiGet; exports.useApiPatch = useApiPatch; exports.useApiPost = useApiPost; exports.useApiPut = useApiPut; exports.useApiState = useApiState;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ametie/vue-muza-use",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Powerful Vue 3 API composable (Muza) with Axios, Auto-Refresh & TypeScript",
5
5
  "author": "MortyQ",
6
6
  "license": "MIT",
@@ -48,6 +48,9 @@
48
48
  "test": "vitest",
49
49
  "dev": "tsup --watch"
50
50
  },
51
+ "dependencies": {
52
+ "@ametie/vue-muza-devtools": "workspace:*"
53
+ },
51
54
  "peerDependencies": {
52
55
  "axios": "^1.0.0",
53
56
  "vue": "^3.5.0"