nuxt-custom-fetch 2.2.0 → 2.3.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/dist/module.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "nuxt-custom-fetch",
3
3
  "configKey": "customFetch",
4
- "version": "2.2.0",
4
+ "version": "2.3.1",
5
5
  "builder": {
6
- "@nuxt/module-builder": "0.8.4",
6
+ "@nuxt/module-builder": "1.0.0",
7
7
  "unbuild": "unknown"
8
8
  }
9
9
  }
@@ -1,4 +1,4 @@
1
- import { createError, reactive, ref, toValue, unref, useAsyncData, useNuxtApp } from "#imports";
1
+ import { createError, getCurrentScope, onScopeDispose, reactive, ref, toValue, unref, useAsyncData, useNuxtApp, useRequestFetch, watch } from "#imports";
2
2
  import { hash, serialize } from "ohash";
3
3
  function Noop() {
4
4
  }
@@ -69,9 +69,15 @@ export class CustomFetch {
69
69
  Object.assign(config, this.baseConfig(config));
70
70
  const generateOptionSegmentsWithConfig = generateOptionSegments(config);
71
71
  if (this.showLogs && import.meta.client) {
72
- console.warn("[Custom Fetch] `Request:`", url, " `Query:`", serialize(generateOptionSegmentsWithConfig), " `Body:`", serialize(config.body));
72
+ let bodyLogs;
73
+ try {
74
+ bodyLogs = serialize(config.body);
75
+ } catch (error) {
76
+ console.warn("[Custom Fetch] couldn't serialize `Body:`", error);
77
+ }
78
+ console.warn("[Custom Fetch] `Request:`", url, " `Query:`", serialize(generateOptionSegmentsWithConfig), " `Body:`", bodyLogs);
73
79
  }
74
- const { onRequest, onRequestError, onResponse, onResponseError, offline, handler, useHandler, immutableKey, ...restAjaxConfig } = config;
80
+ const { onRequest, onRequestError, onResponse, onResponseError, offline, handler, useHandler, showLogs, immutableKey, ...restAjaxConfig } = config;
75
81
  if (import.meta.client && navigator && !navigator.onLine) {
76
82
  if (offline) {
77
83
  offline();
@@ -139,7 +145,7 @@ export class CustomFetch {
139
145
  if (_cachedController.get(key)) {
140
146
  _cachedController.get(key)?.abort?.();
141
147
  }
142
- return $fetch(url, {
148
+ return useRequestFetch()(url, {
143
149
  signal: _cachedController.get(key)?.signal,
144
150
  ...defaultOptions,
145
151
  ..._config
@@ -184,6 +190,16 @@ export class CustomFetch {
184
190
  asyncData.pending.value = false;
185
191
  _cachedController.delete(key);
186
192
  });
193
+ asyncData.refresh = asyncData.execute = () => _handler().then((result) => asyncData.data.value = result);
194
+ const hasScope = getCurrentScope();
195
+ if (options.watch) {
196
+ const unsub = watch(options.watch, async () => {
197
+ asyncData.refresh();
198
+ });
199
+ if (hasScope) {
200
+ onScopeDispose(unsub);
201
+ }
202
+ }
187
203
  return promise;
188
204
  }
189
205
  return useAsyncData(config.key || key, _handler, options);
package/dist/types.d.mts CHANGED
@@ -1 +1 @@
1
- export { type ModuleOptions, default } from './module.js'
1
+ export { type ModuleOptions, default } from './module.mjs'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-custom-fetch",
3
3
  "type": "module",
4
- "version": "2.2.0",
4
+ "version": "2.3.1",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -9,12 +9,11 @@
9
9
  },
10
10
  "exports": {
11
11
  ".": {
12
- "import": "./dist/module.mjs",
13
- "require": "./dist/module.cjs"
12
+ "import": "./dist/module.mjs"
14
13
  }
15
14
  },
16
- "main": "./dist/module.cjs",
17
- "types": "./dist/types.d.ts",
15
+ "main": "./dist/module.mjs",
16
+ "types": "./dist/types.d.mts",
18
17
  "files": [
19
18
  "dist"
20
19
  ],
@@ -36,25 +35,25 @@
36
35
  }
37
36
  },
38
37
  "dependencies": {
39
- "@nuxt/kit": "^3.15.4",
38
+ "@nuxt/kit": "^3.16.2",
40
39
  "ohash": "^2.0.11"
41
40
  },
42
41
  "devDependencies": {
43
- "@antfu/eslint-config": "^4.4.0",
44
- "@commitlint/cli": "^19.7.1",
45
- "@commitlint/config-conventional": "^19.7.1",
46
- "@nuxt/module-builder": "^0.8.4",
47
- "@nuxt/schema": "^3.15.4",
48
- "@types/node": "^22.13.9",
42
+ "@antfu/eslint-config": "^4.11.0",
43
+ "@commitlint/cli": "^19.8.0",
44
+ "@commitlint/config-conventional": "^19.8.0",
45
+ "@nuxt/module-builder": "^1.0.0",
46
+ "@nuxt/schema": "^3.16.2",
47
+ "@types/node": "^22.14.0",
49
48
  "changelogen": "^0.6.1",
50
49
  "commitizen": "^4.3.1",
51
50
  "cz-git": "^1.11.1",
52
- "eslint": "^9.21.0",
51
+ "eslint": "^9.24.0",
53
52
  "husky": "^9.1.7",
54
- "lint-staged": "^15.4.3",
53
+ "lint-staged": "^15.5.0",
55
54
  "nitro": "npm:nitropack",
56
- "nuxt": "^3.15.4",
57
- "typescript": "5.7.3"
55
+ "nuxt": "^3.16.2",
56
+ "typescript": "5.8.3"
58
57
  },
59
58
  "husky": {
60
59
  "hooks": {
package/dist/module.cjs DELETED
@@ -1,5 +0,0 @@
1
- module.exports = function(...args) {
2
- return import('./module.mjs').then(m => m.default.call(this, ...args))
3
- }
4
- const _meta = module.exports.meta = require('./module.json')
5
- module.exports.getMeta = () => Promise.resolve(_meta)
package/dist/module.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import * as _nuxt_schema from '@nuxt/schema';
2
-
3
- interface ModuleOptions {
4
- }
5
- declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
6
-
7
- export { type ModuleOptions, _default as default };
package/dist/types.d.ts DELETED
@@ -1 +0,0 @@
1
- export { type ModuleOptions, default } from './module'