nuxt-custom-fetch 2.3.0 → 4.0.0-alpha.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 +29 -28
- package/dist/module.d.mts +4 -3
- package/dist/module.json +2 -2
- package/dist/module.mjs +2 -1
- package/dist/runtime/ajax.d.ts +13 -13
- package/dist/runtime/ajax.js +54 -62
- package/dist/runtime/type.d.ts +9 -3
- package/dist/runtime/utils.d.ts +6 -0
- package/dist/runtime/utils.js +29 -0
- package/dist/types.d.mts +3 -1
- package/package.json +16 -15
- package/dist/module.cjs +0 -5
- package/dist/module.d.ts +0 -7
- package/dist/types.d.ts +0 -1
package/README.md
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
# Nuxt Module
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
simple wrapper useAsyncData
|
|
4
4
|
|
|
5
|
-
`version
|
|
5
|
+
`version >= 3.17.0`
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Attention
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
1. Invalid request in onMounted
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
- Execute in `nextTick`, or set `{server: false}` to watch `status` changes
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
2. When using `refresh` and `execute`, it should also be noted that the parameters are not responsive, so they will always be the parameters requested for the first time
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
3. If a reactive object is passed and using `watch`, it will automatically re request
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
## 安装
|
|
17
|
+
## Install
|
|
20
18
|
|
|
21
19
|
```bash
|
|
22
20
|
pnpm add nuxt-custom-fetch
|
|
@@ -29,9 +27,9 @@ export default defineNuxtConfig({
|
|
|
29
27
|
})
|
|
30
28
|
```
|
|
31
29
|
|
|
32
|
-
##
|
|
30
|
+
## Usage
|
|
33
31
|
|
|
34
|
-
|
|
32
|
+
global CustomFetch
|
|
35
33
|
|
|
36
34
|
```ts
|
|
37
35
|
const ajax = new CustomFetch({
|
|
@@ -48,7 +46,7 @@ ajax.http({
|
|
|
48
46
|
})
|
|
49
47
|
```
|
|
50
48
|
|
|
51
|
-
##
|
|
49
|
+
## Types
|
|
52
50
|
|
|
53
51
|
### useAsyncDataType
|
|
54
52
|
|
|
@@ -56,29 +54,32 @@ ajax.http({
|
|
|
56
54
|
|
|
57
55
|
```ts
|
|
58
56
|
export declare class CustomFetch {
|
|
59
|
-
baseURL:
|
|
57
|
+
baseURL: string
|
|
60
58
|
immutableKey: boolean
|
|
61
|
-
showLogs: boolean
|
|
62
|
-
params: HTTPConfig
|
|
63
|
-
baseHandler: HTTPConfig['handler']
|
|
64
|
-
interceptors: Interceptors
|
|
65
59
|
offline: typeof Noop
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
http<DataT,
|
|
60
|
+
showLogs: boolean
|
|
61
|
+
constructor (config: CustomFetchOptions)
|
|
62
|
+
http<DataT, NuxtErrorDataT = Error | null>(url: NitroFetchRequest, config: CustomFetchOptions & {
|
|
69
63
|
method: FetchMethod
|
|
70
|
-
}, options?: AsyncDataOptions<DataT>): CustomFetchReturnValue<DataT,
|
|
71
|
-
get<DataT,
|
|
72
|
-
post<DataT,
|
|
64
|
+
}, options?: AsyncDataOptions<DataT>): CustomFetchReturnValue<DataT, NuxtErrorDataT>
|
|
65
|
+
get<DataT, NuxtErrorDataT = Error | null>(url: NitroFetchRequest, config?: CustomFetchOptions, options?: AsyncDataOptions<DataT>): CustomFetchReturnValue<DataT, NuxtErrorDataT>
|
|
66
|
+
post<DataT, NuxtErrorDataT = Error | null>(url: NitroFetchRequest, config?: CustomFetchOptions, options?: AsyncDataOptions<DataT>): CustomFetchReturnValue<DataT, NuxtErrorDataT>
|
|
73
67
|
}
|
|
74
68
|
|
|
75
69
|
export type FetchMethod = 'options' | 'GET' | 'POST' | 'get' | 'HEAD' | 'PATCH' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'post' | 'head' | 'patch' | 'put' | 'delete' | 'connect' | 'trace' | undefined
|
|
76
|
-
export interface
|
|
70
|
+
export interface CustomFetchOptions extends Omit<FetchOptions, 'method'> {
|
|
71
|
+
/** unique key for fetch */
|
|
77
72
|
key?: string
|
|
73
|
+
/** hash key for fetch, with [customFetch: + url] without query */
|
|
78
74
|
immutableKey?: boolean
|
|
75
|
+
/** show logs */
|
|
76
|
+
showLogs?: boolean
|
|
79
77
|
baseURL?: string
|
|
78
|
+
/** is use handler to deal with query or pramas */
|
|
80
79
|
useHandler?: boolean
|
|
81
|
-
handler
|
|
80
|
+
/** handler to deal with query or pramas */
|
|
81
|
+
handler?: (mergedObject: FetchOptions['params'] & FetchOptions['query']) => Record<string, any>
|
|
82
|
+
/** offline handler */
|
|
82
83
|
offline?: () => void
|
|
83
84
|
}
|
|
84
85
|
export interface Interceptors {
|
|
@@ -89,7 +90,7 @@ export interface Interceptors {
|
|
|
89
90
|
}
|
|
90
91
|
```
|
|
91
92
|
|
|
92
|
-
##
|
|
93
|
+
## Example
|
|
93
94
|
|
|
94
95
|
```ts
|
|
95
96
|
// api.ts
|
|
@@ -100,7 +101,7 @@ export const getInfo = (params: Record<string, any>) =>
|
|
|
100
101
|
```ts
|
|
101
102
|
// index.vue
|
|
102
103
|
import { getInfo } from './ajax'
|
|
103
|
-
const { data, error
|
|
104
|
+
const { data, error } = await getInfo({
|
|
104
105
|
sign: 123
|
|
105
106
|
})
|
|
106
107
|
console.log(data.value)
|
package/dist/module.d.mts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as nuxt_schema from 'nuxt/schema';
|
|
2
2
|
|
|
3
3
|
interface ModuleOptions {
|
|
4
4
|
}
|
|
5
|
-
declare const _default:
|
|
5
|
+
declare const _default: nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
6
6
|
|
|
7
|
-
export {
|
|
7
|
+
export { _default as default };
|
|
8
|
+
export type { ModuleOptions };
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -4,7 +4,8 @@ import { defineNuxtModule, createResolver, addImports } from '@nuxt/kit';
|
|
|
4
4
|
const module = defineNuxtModule({
|
|
5
5
|
meta: {
|
|
6
6
|
name: "nuxt-custom-fetch",
|
|
7
|
-
configKey: "customFetch"
|
|
7
|
+
configKey: "customFetch",
|
|
8
|
+
version: ">=3.17.0"
|
|
8
9
|
},
|
|
9
10
|
defaults: {},
|
|
10
11
|
setup(options, nuxt) {
|
package/dist/runtime/ajax.d.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import type { NitroFetchRequest } from 'nitro';
|
|
1
|
+
import type { NitroFetchRequest } from 'nitro/types';
|
|
2
2
|
import type { AsyncData, AsyncDataOptions, NuxtError } from 'nuxt/app';
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import type { CustomFetchOptions, FetchMethod, Interceptors, KeysOf, PickFrom } from './type.js';
|
|
4
|
+
import { Noop } from './utils.js';
|
|
5
|
+
type CustomFetchReturnValue<DataT, NuxtErrorDataT> = AsyncData<PickFrom<DataT, KeysOf<DataT>> | undefined, (NuxtErrorDataT extends Error | NuxtError<unknown> ? NuxtErrorDataT : NuxtError<NuxtErrorDataT>) | undefined>;
|
|
6
6
|
export declare class CustomFetch {
|
|
7
|
-
baseURL: string
|
|
7
|
+
baseURL: string;
|
|
8
8
|
immutableKey: boolean;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
_config: CustomFetchOptions;
|
|
10
|
+
_baseHandler: CustomFetchOptions['handler'];
|
|
11
|
+
_interceptors: Interceptors;
|
|
12
12
|
offline: typeof Noop;
|
|
13
13
|
showLogs: boolean;
|
|
14
|
-
constructor(config
|
|
14
|
+
constructor(config: CustomFetchOptions);
|
|
15
15
|
private baseConfig;
|
|
16
|
-
http<DataT,
|
|
16
|
+
http<DataT, NuxtErrorDataT = Error | null>(url: NitroFetchRequest, config: CustomFetchOptions & {
|
|
17
17
|
method: FetchMethod;
|
|
18
|
-
}, options?: AsyncDataOptions<DataT>): CustomFetchReturnValue<DataT,
|
|
19
|
-
get<DataT,
|
|
20
|
-
post<DataT,
|
|
18
|
+
}, options?: AsyncDataOptions<DataT>): CustomFetchReturnValue<DataT, NuxtErrorDataT>;
|
|
19
|
+
get<DataT, NuxtErrorDataT = Error | null>(url: NitroFetchRequest, config?: CustomFetchOptions, options?: AsyncDataOptions<DataT>): CustomFetchReturnValue<DataT, NuxtErrorDataT>;
|
|
20
|
+
post<DataT, NuxtErrorDataT = Error | null>(url: NitroFetchRequest, config?: CustomFetchOptions, options?: AsyncDataOptions<DataT>): CustomFetchReturnValue<DataT, NuxtErrorDataT>;
|
|
21
21
|
}
|
|
22
22
|
export {};
|
package/dist/runtime/ajax.js
CHANGED
|
@@ -1,50 +1,29 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { asyncDataDefaults, pendingWhenIdle } from "#build/nuxt.config.mjs";
|
|
2
|
+
import { clearNuxtData, createError, getCurrentScope, onScopeDispose, reactive, ref, shallowRef, unref, useAsyncData, useRequestFetch, useRuntimeConfig, watch } from "#imports";
|
|
2
3
|
import { hash, serialize } from "ohash";
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
function generateOptionSegments(opts) {
|
|
6
|
-
const segments = [toValue(opts.method)?.toUpperCase() || "GET", toValue(opts.baseURL)];
|
|
7
|
-
for (const _obj of [opts.params || opts.query]) {
|
|
8
|
-
const obj = toValue(_obj);
|
|
9
|
-
if (!obj) {
|
|
10
|
-
continue;
|
|
11
|
-
}
|
|
12
|
-
const unwrapped = {};
|
|
13
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
14
|
-
unwrapped[toValue(key)] = toValue(value);
|
|
15
|
-
}
|
|
16
|
-
segments.push(unwrapped);
|
|
17
|
-
}
|
|
18
|
-
return segments;
|
|
19
|
-
}
|
|
20
|
-
function pick(obj, keys) {
|
|
21
|
-
const newObj = {};
|
|
22
|
-
for (const key of keys) {
|
|
23
|
-
newObj[key] = obj[key];
|
|
24
|
-
}
|
|
25
|
-
return newObj;
|
|
26
|
-
}
|
|
4
|
+
import { generateOptionSegments, Noop, pick } from "./utils.js";
|
|
27
5
|
const _cachedController = /* @__PURE__ */ new Map();
|
|
28
6
|
export class CustomFetch {
|
|
29
7
|
baseURL;
|
|
30
8
|
immutableKey = false;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
9
|
+
_config = {};
|
|
10
|
+
_baseHandler;
|
|
11
|
+
_interceptors = {};
|
|
34
12
|
offline = Noop;
|
|
35
13
|
showLogs = false;
|
|
36
|
-
constructor(config
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
this.
|
|
40
|
-
this.baseURL = config.baseURL;
|
|
14
|
+
constructor(config) {
|
|
15
|
+
const { handler, offline, ...restConfig } = config;
|
|
16
|
+
this._config = restConfig;
|
|
17
|
+
this.baseURL = config.baseURL || "";
|
|
41
18
|
this.immutableKey = config.immutableKey ?? false;
|
|
42
|
-
this.showLogs = config.showLogs ?? import.meta.dev;
|
|
43
|
-
if (
|
|
44
|
-
this.
|
|
19
|
+
this.showLogs = config.showLogs ?? import.meta.dev ?? false;
|
|
20
|
+
if (handler) {
|
|
21
|
+
this._baseHandler = handler || Noop;
|
|
45
22
|
}
|
|
46
|
-
|
|
47
|
-
|
|
23
|
+
if (offline) {
|
|
24
|
+
this.offline = offline;
|
|
25
|
+
}
|
|
26
|
+
this._interceptors = {
|
|
48
27
|
onRequest: config.onRequest || Noop,
|
|
49
28
|
onRequestError: config.onRequestError || Noop,
|
|
50
29
|
onResponse: config.onResponse || Noop,
|
|
@@ -53,11 +32,11 @@ export class CustomFetch {
|
|
|
53
32
|
}
|
|
54
33
|
baseConfig(config) {
|
|
55
34
|
const { useHandler = true, handler, query = {}, params = {} } = config;
|
|
56
|
-
const baseHandler = handler || this.
|
|
35
|
+
const baseHandler = handler || this._baseHandler;
|
|
57
36
|
const _name = Object.keys(query).length ? "query" : "params";
|
|
58
37
|
const mergeObj = {
|
|
59
|
-
...
|
|
60
|
-
...
|
|
38
|
+
...params,
|
|
39
|
+
...query
|
|
61
40
|
};
|
|
62
41
|
if (useHandler && baseHandler && typeof baseHandler === "function") {
|
|
63
42
|
return { [_name]: baseHandler(mergeObj) };
|
|
@@ -65,20 +44,25 @@ export class CustomFetch {
|
|
|
65
44
|
return { [_name]: { ...mergeObj } };
|
|
66
45
|
}
|
|
67
46
|
http(url, config, options = {}) {
|
|
68
|
-
|
|
47
|
+
const app = useRuntimeConfig().app;
|
|
48
|
+
config.baseURL ??= this.baseURL || app.baseURL;
|
|
69
49
|
Object.assign(config, this.baseConfig(config));
|
|
70
50
|
const generateOptionSegmentsWithConfig = generateOptionSegments(config);
|
|
71
51
|
if (this.showLogs && import.meta.client) {
|
|
72
|
-
|
|
52
|
+
let bodyLogs;
|
|
53
|
+
try {
|
|
54
|
+
bodyLogs = serialize(config.body);
|
|
55
|
+
} catch (error) {
|
|
56
|
+
console.warn("[Custom Fetch] couldn't serialize `Body:`", error);
|
|
57
|
+
}
|
|
58
|
+
console.warn("[Custom Fetch] `Request:`", url, " `Query:`", serialize(generateOptionSegmentsWithConfig), " `Body:`", bodyLogs);
|
|
73
59
|
}
|
|
74
|
-
const { onRequest, onRequestError, onResponse, onResponseError, offline, handler, useHandler, immutableKey, ...
|
|
60
|
+
const { onRequest, onRequestError, onResponse, onResponseError, offline, handler, useHandler, showLogs, immutableKey, ...asyncDataOptions } = config;
|
|
75
61
|
if (import.meta.client && navigator && !navigator.onLine) {
|
|
76
|
-
|
|
77
|
-
offline();
|
|
78
|
-
}
|
|
62
|
+
this.offline();
|
|
79
63
|
}
|
|
80
|
-
const interceptors = this.
|
|
81
|
-
const _config = reactive({ ...
|
|
64
|
+
const interceptors = this._interceptors;
|
|
65
|
+
const _config = reactive({ ...asyncDataOptions });
|
|
82
66
|
const defaultOptions = {
|
|
83
67
|
onRequest(ctx) {
|
|
84
68
|
[interceptors.onRequest, onRequest].forEach((fns) => {
|
|
@@ -129,12 +113,15 @@ export class CustomFetch {
|
|
|
129
113
|
});
|
|
130
114
|
}
|
|
131
115
|
};
|
|
116
|
+
let key = config.key;
|
|
132
117
|
const hashValue = ["custom_fetch:", url];
|
|
118
|
+
if (import.meta.dev && !config.key && (this.immutableKey || immutableKey)) {
|
|
119
|
+
console.warn("[Custom Fetch] immutableKey is enabled, the key will be generated by hash([custom_fetch:, url])");
|
|
120
|
+
}
|
|
133
121
|
if (!this.immutableKey && !immutableKey) {
|
|
134
122
|
hashValue.push(...generateOptionSegmentsWithConfig);
|
|
135
123
|
}
|
|
136
|
-
|
|
137
|
-
options.default = options.default ?? (() => null);
|
|
124
|
+
key ??= hash(hashValue).replace(/[-_]/g, "").slice(0, 10);
|
|
138
125
|
const _handler = () => {
|
|
139
126
|
if (_cachedController.get(key)) {
|
|
140
127
|
_cachedController.get(key)?.abort?.();
|
|
@@ -146,15 +133,18 @@ export class CustomFetch {
|
|
|
146
133
|
});
|
|
147
134
|
};
|
|
148
135
|
const controller = typeof AbortController !== "undefined" ? new AbortController() : {};
|
|
149
|
-
|
|
150
|
-
|
|
136
|
+
if (import.meta.client) {
|
|
137
|
+
const _ref = options.deep ? ref : shallowRef;
|
|
151
138
|
const asyncData = {
|
|
152
|
-
data:
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
139
|
+
data: _ref(null),
|
|
140
|
+
error: _ref(null),
|
|
141
|
+
status: _ref("idle"),
|
|
142
|
+
pending: _ref(false),
|
|
143
|
+
clear: () => clearNuxtData(key)
|
|
156
144
|
};
|
|
157
|
-
|
|
145
|
+
if (pendingWhenIdle) {
|
|
146
|
+
asyncData.pending.value = true;
|
|
147
|
+
}
|
|
158
148
|
asyncData.status.value = "pending";
|
|
159
149
|
const promise = new Promise((resolve, reject) => {
|
|
160
150
|
try {
|
|
@@ -172,7 +162,7 @@ export class CustomFetch {
|
|
|
172
162
|
result = pick(result, options.pick);
|
|
173
163
|
}
|
|
174
164
|
asyncData.data.value = result;
|
|
175
|
-
asyncData.error.value =
|
|
165
|
+
asyncData.error.value = asyncDataDefaults.errorValue;
|
|
176
166
|
asyncData.status.value = "success";
|
|
177
167
|
return asyncData;
|
|
178
168
|
}).catch((error) => {
|
|
@@ -181,7 +171,9 @@ export class CustomFetch {
|
|
|
181
171
|
asyncData.status.value = "error";
|
|
182
172
|
return asyncData;
|
|
183
173
|
}).finally(() => {
|
|
184
|
-
|
|
174
|
+
if (pendingWhenIdle) {
|
|
175
|
+
asyncData.pending.value = false;
|
|
176
|
+
}
|
|
185
177
|
_cachedController.delete(key);
|
|
186
178
|
});
|
|
187
179
|
asyncData.refresh = asyncData.execute = () => _handler().then((result) => asyncData.data.value = result);
|
|
@@ -189,14 +181,14 @@ export class CustomFetch {
|
|
|
189
181
|
if (options.watch) {
|
|
190
182
|
const unsub = watch(options.watch, async () => {
|
|
191
183
|
asyncData.refresh();
|
|
192
|
-
});
|
|
184
|
+
}, { flush: "post" });
|
|
193
185
|
if (hasScope) {
|
|
194
186
|
onScopeDispose(unsub);
|
|
195
187
|
}
|
|
196
188
|
}
|
|
197
189
|
return promise;
|
|
198
190
|
}
|
|
199
|
-
return useAsyncData(
|
|
191
|
+
return useAsyncData(key, _handler, options);
|
|
200
192
|
}
|
|
201
193
|
get(url, config = {}, options) {
|
|
202
194
|
return this.http(url, {
|
package/dist/runtime/type.d.ts
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import type { FetchOptions } from 'ofetch';
|
|
2
2
|
export type { FetchContext, FetchResponse } from 'ofetch';
|
|
3
|
+
/** https://github.com/nuxt/nuxt/blob/edeb0759a455dbafd030f0b5ae1d5a39ad0dfc2a/packages/nuxt/src/app/composables/asyncData.ts#L20 */
|
|
3
4
|
export type PickFrom<T, K extends Array<string>> = T extends Array<any> ? T : T extends Record<string, any> ? (keyof T extends K[number] ? T : K[number] extends never ? T : Pick<T, K[number]>) : T;
|
|
4
5
|
export type KeysOf<T> = Array<T extends T ? (keyof T extends string ? keyof T : never) : never>;
|
|
5
6
|
export type FetchMethod = 'options' | 'GET' | 'POST' | 'get' | 'HEAD' | 'PATCH' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'post' | 'head' | 'patch' | 'put' | 'delete' | 'connect' | 'trace' | undefined;
|
|
6
|
-
export interface
|
|
7
|
+
export interface CustomFetchOptions extends Omit<FetchOptions, 'method'> {
|
|
8
|
+
/** unique key for fetch */
|
|
7
9
|
key?: string;
|
|
10
|
+
/** hash key for fetch, with [customFetch: + url] without query */
|
|
8
11
|
immutableKey?: boolean;
|
|
12
|
+
/** show logs */
|
|
9
13
|
showLogs?: boolean;
|
|
10
|
-
interceptors?: Interceptors;
|
|
11
14
|
baseURL?: string;
|
|
15
|
+
/** is use handler to deal with query or pramas */
|
|
12
16
|
useHandler?: boolean;
|
|
13
|
-
handler
|
|
17
|
+
/** handler to deal with query or pramas */
|
|
18
|
+
handler?: (mergedObject: FetchOptions['params'] & FetchOptions['query']) => Record<string, any>;
|
|
19
|
+
/** offline handler */
|
|
14
20
|
offline?: () => void;
|
|
15
21
|
}
|
|
16
22
|
export interface Interceptors {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CustomFetchOptions, FetchMethod } from './type.js';
|
|
2
|
+
export declare function Noop(): void;
|
|
3
|
+
export declare function generateOptionSegments(opts: CustomFetchOptions & {
|
|
4
|
+
method: FetchMethod;
|
|
5
|
+
}): (string | Record<string, string> | undefined)[];
|
|
6
|
+
export declare function pick(obj: Record<string, any>, keys: string[]): any;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { toValue } from "#imports";
|
|
2
|
+
import { hash } from "ohash";
|
|
3
|
+
export function Noop() {
|
|
4
|
+
}
|
|
5
|
+
export function generateOptionSegments(opts) {
|
|
6
|
+
const segments = [toValue(opts.method)?.toUpperCase() || "GET", toValue(opts.baseURL)];
|
|
7
|
+
for (const _obj of [opts.params || opts.query]) {
|
|
8
|
+
const obj = toValue(_obj);
|
|
9
|
+
if (!obj) {
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
const unwrapped = {};
|
|
13
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
14
|
+
unwrapped[toValue(key)] = toValue(value);
|
|
15
|
+
}
|
|
16
|
+
segments.push(unwrapped);
|
|
17
|
+
}
|
|
18
|
+
if (opts.body) {
|
|
19
|
+
segments.push(hash(toValue(opts.body)));
|
|
20
|
+
}
|
|
21
|
+
return segments;
|
|
22
|
+
}
|
|
23
|
+
export function pick(obj, keys) {
|
|
24
|
+
const newObj = {};
|
|
25
|
+
for (const key of keys) {
|
|
26
|
+
newObj[key] = obj[key];
|
|
27
|
+
}
|
|
28
|
+
return newObj;
|
|
29
|
+
}
|
package/dist/types.d.mts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-custom-fetch",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "4.0.0-alpha.1",
|
|
5
|
+
"packageManager": "pnpm@8.15.3+sha1.64838798f519c18029c1e8a1310e16101fc2eda0",
|
|
5
6
|
"license": "MIT",
|
|
6
7
|
"repository": {
|
|
7
8
|
"type": "git",
|
|
@@ -9,12 +10,11 @@
|
|
|
9
10
|
},
|
|
10
11
|
"exports": {
|
|
11
12
|
".": {
|
|
12
|
-
"import": "./dist/module.mjs"
|
|
13
|
-
"require": "./dist/module.cjs"
|
|
13
|
+
"import": "./dist/module.mjs"
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
|
-
"main": "./dist/module.
|
|
17
|
-
"types": "./dist/types.d.
|
|
16
|
+
"main": "./dist/module.mjs",
|
|
17
|
+
"types": "./dist/types.d.mts",
|
|
18
18
|
"files": [
|
|
19
19
|
"dist"
|
|
20
20
|
],
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"lint:fix": "eslint . --fix",
|
|
29
29
|
"prepare": "husky",
|
|
30
30
|
"commit": "git-cz",
|
|
31
|
+
"prerelease": "changelogen --prerelease && pnpm prepack && npm publish --tag alpha",
|
|
31
32
|
"release": "changelogen --release && pnpm prepack && npm publish && git push --follow-tags"
|
|
32
33
|
},
|
|
33
34
|
"config": {
|
|
@@ -36,25 +37,25 @@
|
|
|
36
37
|
}
|
|
37
38
|
},
|
|
38
39
|
"dependencies": {
|
|
39
|
-
"@nuxt/kit": "^3.16.1",
|
|
40
40
|
"ohash": "^2.0.11"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@antfu/eslint-config": "^4.
|
|
43
|
+
"@antfu/eslint-config": "^4.12.0",
|
|
44
44
|
"@commitlint/cli": "^19.8.0",
|
|
45
45
|
"@commitlint/config-conventional": "^19.8.0",
|
|
46
|
-
"@nuxt/
|
|
47
|
-
"@nuxt/
|
|
48
|
-
"@
|
|
46
|
+
"@nuxt/kit": "npm:@nuxt/kit-nightly@4.0.0-29086370.088bcd45",
|
|
47
|
+
"@nuxt/module-builder": "^1.0.1",
|
|
48
|
+
"@nuxt/schema": "npm:@nuxt/schema-nightly@4.0.0-29086370.088bcd45",
|
|
49
|
+
"@types/node": "^22.14.1",
|
|
49
50
|
"changelogen": "^0.6.1",
|
|
50
51
|
"commitizen": "^4.3.1",
|
|
51
52
|
"cz-git": "^1.11.1",
|
|
52
|
-
"eslint": "^9.
|
|
53
|
+
"eslint": "^9.24.0",
|
|
53
54
|
"husky": "^9.1.7",
|
|
54
|
-
"lint-staged": "^15.5.
|
|
55
|
-
"nitro": "npm:
|
|
56
|
-
"nuxt": "
|
|
57
|
-
"typescript": "5.8.
|
|
55
|
+
"lint-staged": "^15.5.1",
|
|
56
|
+
"nitro": "npm:nitro-nightly@latest",
|
|
57
|
+
"nuxt": "npm:nuxt-nightly@4.0.0-29086370.088bcd45",
|
|
58
|
+
"typescript": "5.8.3"
|
|
58
59
|
},
|
|
59
60
|
"husky": {
|
|
60
61
|
"hooks": {
|
package/dist/module.cjs
DELETED
package/dist/module.d.ts
DELETED
package/dist/types.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { type ModuleOptions, default } from './module'
|