@hey-api/openapi-ts 0.91.0 → 0.92.0
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 +7 -7
- package/dist/clients/angular/client.ts +23 -49
- package/dist/clients/angular/types.ts +11 -34
- package/dist/clients/angular/utils.ts +6 -22
- package/dist/clients/axios/client.ts +16 -27
- package/dist/clients/axios/types.ts +17 -54
- package/dist/clients/axios/utils.ts +3 -8
- package/dist/clients/core/auth.ts +1 -2
- package/dist/clients/core/bodySerializer.ts +5 -21
- package/dist/clients/core/params.ts +3 -10
- package/dist/clients/core/pathSerializer.ts +4 -14
- package/dist/clients/core/queryKeySerializer.ts +6 -25
- package/dist/clients/core/serverSentEvents.ts +8 -31
- package/dist/clients/core/types.ts +4 -18
- package/dist/clients/core/utils.ts +1 -4
- package/dist/clients/fetch/client.ts +25 -48
- package/dist/clients/fetch/types.ts +12 -40
- package/dist/clients/fetch/utils.ts +6 -22
- package/dist/clients/ky/client.ts +27 -58
- package/dist/clients/ky/types.ts +14 -45
- package/dist/clients/ky/utils.ts +6 -22
- package/dist/clients/next/client.ts +30 -47
- package/dist/clients/next/types.ts +13 -47
- package/dist/clients/next/utils.ts +8 -31
- package/dist/clients/nuxt/client.ts +18 -37
- package/dist/clients/nuxt/types.ts +12 -31
- package/dist/clients/nuxt/utils.ts +5 -17
- package/dist/clients/ofetch/client.ts +34 -60
- package/dist/clients/ofetch/types.ts +13 -44
- package/dist/clients/ofetch/utils.ts +20 -58
- package/dist/index.d.mts +289 -452
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/{init-kvO44gnv.mjs → init-DlaW5Djq.mjs} +355 -86
- package/dist/init-DlaW5Djq.mjs.map +1 -0
- package/dist/internal.mjs +1 -1
- package/dist/run.mjs +3 -3
- package/dist/run.mjs.map +1 -1
- package/dist/{src-Dmlg6WRV.mjs → src-BYA2YioO.mjs} +5 -8
- package/dist/src-BYA2YioO.mjs.map +1 -0
- package/dist/types-Ba27ofyy.d.mts.map +1 -1
- package/package.json +36 -37
- package/dist/init-kvO44gnv.mjs.map +0 -1
- package/dist/src-Dmlg6WRV.mjs.map +0 -1
package/dist/clients/ky/types.ts
CHANGED
|
@@ -6,10 +6,7 @@ import type {
|
|
|
6
6
|
ServerSentEventsOptions,
|
|
7
7
|
ServerSentEventsResult,
|
|
8
8
|
} from '../core/serverSentEvents';
|
|
9
|
-
import type {
|
|
10
|
-
Client as CoreClient,
|
|
11
|
-
Config as CoreConfig,
|
|
12
|
-
} from '../core/types';
|
|
9
|
+
import type { Client as CoreClient, Config as CoreConfig } from '../core/types';
|
|
13
10
|
import type { Middleware } from './utils';
|
|
14
11
|
|
|
15
12
|
export type ResponseStyle = 'data' | 'fields';
|
|
@@ -26,9 +23,7 @@ export interface RetryOptions {
|
|
|
26
23
|
*
|
|
27
24
|
* @default ['get', 'put', 'head', 'delete', 'options', 'trace']
|
|
28
25
|
*/
|
|
29
|
-
methods?: Array<
|
|
30
|
-
'get' | 'post' | 'put' | 'delete' | 'patch' | 'head' | 'options' | 'trace'
|
|
31
|
-
>;
|
|
26
|
+
methods?: Array<'get' | 'post' | 'put' | 'delete' | 'patch' | 'head' | 'options' | 'trace'>;
|
|
32
27
|
/**
|
|
33
28
|
* HTTP status codes to retry
|
|
34
29
|
*
|
|
@@ -38,10 +33,8 @@ export interface RetryOptions {
|
|
|
38
33
|
}
|
|
39
34
|
|
|
40
35
|
export interface Config<T extends ClientOptions = ClientOptions>
|
|
41
|
-
extends
|
|
42
|
-
|
|
43
|
-
'body' | 'headers' | 'method' | 'prefixUrl' | 'retry' | 'throwHttpErrors'
|
|
44
|
-
>,
|
|
36
|
+
extends
|
|
37
|
+
Omit<KyOptions, 'body' | 'headers' | 'method' | 'prefixUrl' | 'retry' | 'throwHttpErrors'>,
|
|
45
38
|
CoreConfig {
|
|
46
39
|
/**
|
|
47
40
|
* Base URL for all requests made by this client.
|
|
@@ -65,14 +58,7 @@ export interface Config<T extends ClientOptions = ClientOptions>
|
|
|
65
58
|
*
|
|
66
59
|
* @default 'auto'
|
|
67
60
|
*/
|
|
68
|
-
parseAs?:
|
|
69
|
-
| 'arrayBuffer'
|
|
70
|
-
| 'auto'
|
|
71
|
-
| 'blob'
|
|
72
|
-
| 'formData'
|
|
73
|
-
| 'json'
|
|
74
|
-
| 'stream'
|
|
75
|
-
| 'text';
|
|
61
|
+
parseAs?: 'arrayBuffer' | 'auto' | 'blob' | 'formData' | 'json' | 'stream' | 'text';
|
|
76
62
|
/**
|
|
77
63
|
* Should we return only data or multiple fields (data, error, response, etc.)?
|
|
78
64
|
*
|
|
@@ -102,7 +88,9 @@ export interface RequestOptions<
|
|
|
102
88
|
TResponseStyle extends ResponseStyle = 'fields',
|
|
103
89
|
ThrowOnError extends boolean = boolean,
|
|
104
90
|
Url extends string = string,
|
|
105
|
-
>
|
|
91
|
+
>
|
|
92
|
+
extends
|
|
93
|
+
Config<{
|
|
106
94
|
responseStyle: TResponseStyle;
|
|
107
95
|
throwOnError: ThrowOnError;
|
|
108
96
|
}>,
|
|
@@ -149,32 +137,22 @@ export type RequestResult<
|
|
|
149
137
|
? TData[keyof TData]
|
|
150
138
|
: TData
|
|
151
139
|
: {
|
|
152
|
-
data: TData extends Record<string, unknown>
|
|
153
|
-
? TData[keyof TData]
|
|
154
|
-
: TData;
|
|
140
|
+
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
|
|
155
141
|
request: Request;
|
|
156
142
|
response: Response;
|
|
157
143
|
}
|
|
158
144
|
>
|
|
159
145
|
: Promise<
|
|
160
146
|
TResponseStyle extends 'data'
|
|
161
|
-
?
|
|
162
|
-
| (TData extends Record<string, unknown>
|
|
163
|
-
? TData[keyof TData]
|
|
164
|
-
: TData)
|
|
165
|
-
| undefined
|
|
147
|
+
? (TData extends Record<string, unknown> ? TData[keyof TData] : TData) | undefined
|
|
166
148
|
: (
|
|
167
149
|
| {
|
|
168
|
-
data: TData extends Record<string, unknown>
|
|
169
|
-
? TData[keyof TData]
|
|
170
|
-
: TData;
|
|
150
|
+
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
|
|
171
151
|
error: undefined;
|
|
172
152
|
}
|
|
173
153
|
| {
|
|
174
154
|
data: undefined;
|
|
175
|
-
error: TError extends Record<string, unknown>
|
|
176
|
-
? TError[keyof TError]
|
|
177
|
-
: TError;
|
|
155
|
+
error: TError extends Record<string, unknown> ? TError[keyof TError] : TError;
|
|
178
156
|
}
|
|
179
157
|
) & {
|
|
180
158
|
request: Request;
|
|
@@ -213,10 +191,7 @@ type RequestFn = <
|
|
|
213
191
|
TResponseStyle extends ResponseStyle = 'fields',
|
|
214
192
|
>(
|
|
215
193
|
options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'> &
|
|
216
|
-
Pick<
|
|
217
|
-
Required<RequestOptions<TData, TResponseStyle, ThrowOnError>>,
|
|
218
|
-
'method'
|
|
219
|
-
>,
|
|
194
|
+
Pick<Required<RequestOptions<TData, TResponseStyle, ThrowOnError>>, 'method'>,
|
|
220
195
|
) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
221
196
|
|
|
222
197
|
type BuildUrlFn = <
|
|
@@ -230,13 +205,7 @@ type BuildUrlFn = <
|
|
|
230
205
|
options: TData & Options<TData>,
|
|
231
206
|
) => string;
|
|
232
207
|
|
|
233
|
-
export type Client = CoreClient<
|
|
234
|
-
RequestFn,
|
|
235
|
-
Config,
|
|
236
|
-
MethodFn,
|
|
237
|
-
BuildUrlFn,
|
|
238
|
-
SseFn
|
|
239
|
-
> & {
|
|
208
|
+
export type Client = CoreClient<RequestFn, Config, MethodFn, BuildUrlFn, SseFn> & {
|
|
240
209
|
interceptors: Middleware<Request, Response, unknown, ResolvedRequestOptions>;
|
|
241
210
|
};
|
|
242
211
|
|
package/dist/clients/ky/utils.ts
CHANGED
|
@@ -63,9 +63,7 @@ export const createQuerySerializer = <T = unknown>({
|
|
|
63
63
|
/**
|
|
64
64
|
* Infers parseAs value from provided Content-Type header.
|
|
65
65
|
*/
|
|
66
|
-
export const getParseAs = (
|
|
67
|
-
contentType: string | null,
|
|
68
|
-
): Exclude<Config['parseAs'], 'auto'> => {
|
|
66
|
+
export const getParseAs = (contentType: string | null): Exclude<Config['parseAs'], 'auto'> => {
|
|
69
67
|
if (!contentType) {
|
|
70
68
|
return 'stream';
|
|
71
69
|
}
|
|
@@ -76,10 +74,7 @@ export const getParseAs = (
|
|
|
76
74
|
return;
|
|
77
75
|
}
|
|
78
76
|
|
|
79
|
-
if (
|
|
80
|
-
cleanContent.startsWith('application/json') ||
|
|
81
|
-
cleanContent.endsWith('+json')
|
|
82
|
-
) {
|
|
77
|
+
if (cleanContent.startsWith('application/json') || cleanContent.endsWith('+json')) {
|
|
83
78
|
return 'json';
|
|
84
79
|
}
|
|
85
80
|
|
|
@@ -88,9 +83,7 @@ export const getParseAs = (
|
|
|
88
83
|
}
|
|
89
84
|
|
|
90
85
|
if (
|
|
91
|
-
['application/', 'audio/', 'image/', 'video/'].some((type) =>
|
|
92
|
-
cleanContent.startsWith(type),
|
|
93
|
-
)
|
|
86
|
+
['application/', 'audio/', 'image/', 'video/'].some((type) => cleanContent.startsWith(type))
|
|
94
87
|
) {
|
|
95
88
|
return 'blob';
|
|
96
89
|
}
|
|
@@ -197,10 +190,7 @@ export const mergeHeaders = (
|
|
|
197
190
|
continue;
|
|
198
191
|
}
|
|
199
192
|
|
|
200
|
-
const iterator =
|
|
201
|
-
header instanceof Headers
|
|
202
|
-
? headersEntries(header)
|
|
203
|
-
: Object.entries(header);
|
|
193
|
+
const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
|
|
204
194
|
|
|
205
195
|
for (const [key, value] of iterator) {
|
|
206
196
|
if (value === null) {
|
|
@@ -227,10 +217,7 @@ type ErrInterceptor<Err, Res, Req, Options> = (
|
|
|
227
217
|
options: Options,
|
|
228
218
|
) => Err | Promise<Err>;
|
|
229
219
|
|
|
230
|
-
type ReqInterceptor<Req, Options> = (
|
|
231
|
-
request: Req,
|
|
232
|
-
options: Options,
|
|
233
|
-
) => Req | Promise<Req>;
|
|
220
|
+
type ReqInterceptor<Req, Options> = (request: Req, options: Options) => Req | Promise<Req>;
|
|
234
221
|
|
|
235
222
|
type ResInterceptor<Res, Req, Options> = (
|
|
236
223
|
response: Res,
|
|
@@ -264,10 +251,7 @@ class Interceptors<Interceptor> {
|
|
|
264
251
|
return this.fns.indexOf(id);
|
|
265
252
|
}
|
|
266
253
|
|
|
267
|
-
update(
|
|
268
|
-
id: number | Interceptor,
|
|
269
|
-
fn: Interceptor,
|
|
270
|
-
): number | Interceptor | false {
|
|
254
|
+
update(id: number | Interceptor, fn: Interceptor): number | Interceptor | false {
|
|
271
255
|
const index = this.getInterceptorIndex(id);
|
|
272
256
|
if (this.fns[index]) {
|
|
273
257
|
this.fns[index] = fn;
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import { createSseClient } from '../core/serverSentEvents';
|
|
2
2
|
import type { HttpMethod } from '../core/types';
|
|
3
3
|
import { getValidRequestBody } from '../core/utils';
|
|
4
|
-
import type {
|
|
5
|
-
Client,
|
|
6
|
-
Config,
|
|
7
|
-
RequestOptions,
|
|
8
|
-
ResolvedRequestOptions,
|
|
9
|
-
} from './types';
|
|
4
|
+
import type { Client, Config, RequestOptions, ResolvedRequestOptions } from './types';
|
|
10
5
|
import {
|
|
11
6
|
buildUrl,
|
|
12
7
|
createConfig,
|
|
@@ -32,11 +27,7 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
32
27
|
return getConfig();
|
|
33
28
|
};
|
|
34
29
|
|
|
35
|
-
const interceptors = createInterceptors<
|
|
36
|
-
Response,
|
|
37
|
-
unknown,
|
|
38
|
-
ResolvedRequestOptions
|
|
39
|
-
>();
|
|
30
|
+
const interceptors = createInterceptors<Response, unknown, ResolvedRequestOptions>();
|
|
40
31
|
|
|
41
32
|
const beforeRequest = async (options: RequestOptions) => {
|
|
42
33
|
const opts = {
|
|
@@ -109,10 +100,7 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
109
100
|
? getParseAs(response.headers.get('Content-Type'))
|
|
110
101
|
: opts.parseAs) ?? 'json';
|
|
111
102
|
|
|
112
|
-
if (
|
|
113
|
-
response.status === 204 ||
|
|
114
|
-
response.headers.get('Content-Length') === '0'
|
|
115
|
-
) {
|
|
103
|
+
if (response.status === 204 || response.headers.get('Content-Length') === '0') {
|
|
116
104
|
let emptyData: any;
|
|
117
105
|
switch (parseAs) {
|
|
118
106
|
case 'arrayBuffer':
|
|
@@ -205,40 +193,35 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
205
193
|
};
|
|
206
194
|
};
|
|
207
195
|
|
|
208
|
-
const makeMethodFn =
|
|
209
|
-
(
|
|
210
|
-
request({ ...options, method });
|
|
196
|
+
const makeMethodFn = (method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
|
|
197
|
+
request({ ...options, method });
|
|
211
198
|
|
|
212
|
-
const makeSseFn =
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
request = new Request(requestInit.url, requestInit);
|
|
231
|
-
}
|
|
199
|
+
const makeSseFn = (method: Uppercase<HttpMethod>) => async (options: RequestOptions) => {
|
|
200
|
+
const { opts, url } = await beforeRequest(options);
|
|
201
|
+
return createSseClient({
|
|
202
|
+
...opts,
|
|
203
|
+
body: opts.body as BodyInit | null | undefined,
|
|
204
|
+
headers: opts.headers as unknown as Record<string, string>,
|
|
205
|
+
method,
|
|
206
|
+
onRequest: async (url, init) => {
|
|
207
|
+
let request = new Request(url, init);
|
|
208
|
+
const requestInit = {
|
|
209
|
+
...init,
|
|
210
|
+
method: init.method as Config['method'],
|
|
211
|
+
url,
|
|
212
|
+
};
|
|
213
|
+
for (const fn of interceptors.request.fns) {
|
|
214
|
+
if (fn) {
|
|
215
|
+
await fn(requestInit);
|
|
216
|
+
request = new Request(requestInit.url, requestInit);
|
|
232
217
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
});
|
|
241
|
-
};
|
|
218
|
+
}
|
|
219
|
+
return request;
|
|
220
|
+
},
|
|
221
|
+
serializedBody: getValidRequestBody(opts) as BodyInit | null | undefined,
|
|
222
|
+
url,
|
|
223
|
+
});
|
|
224
|
+
};
|
|
242
225
|
|
|
243
226
|
return {
|
|
244
227
|
buildUrl,
|
|
@@ -3,15 +3,11 @@ import type {
|
|
|
3
3
|
ServerSentEventsOptions,
|
|
4
4
|
ServerSentEventsResult,
|
|
5
5
|
} from '../core/serverSentEvents';
|
|
6
|
-
import type {
|
|
7
|
-
Client as CoreClient,
|
|
8
|
-
Config as CoreConfig,
|
|
9
|
-
} from '../core/types';
|
|
6
|
+
import type { Client as CoreClient, Config as CoreConfig } from '../core/types';
|
|
10
7
|
import type { Middleware } from './utils';
|
|
11
8
|
|
|
12
9
|
export interface Config<T extends ClientOptions = ClientOptions>
|
|
13
|
-
extends Omit<RequestInit, 'body' | 'headers' | 'method'>,
|
|
14
|
-
CoreConfig {
|
|
10
|
+
extends Omit<RequestInit, 'body' | 'headers' | 'method'>, CoreConfig {
|
|
15
11
|
/**
|
|
16
12
|
* Base URL for all requests made by this client.
|
|
17
13
|
*/
|
|
@@ -31,14 +27,7 @@ export interface Config<T extends ClientOptions = ClientOptions>
|
|
|
31
27
|
*
|
|
32
28
|
* @default 'auto'
|
|
33
29
|
*/
|
|
34
|
-
parseAs?:
|
|
35
|
-
| 'arrayBuffer'
|
|
36
|
-
| 'auto'
|
|
37
|
-
| 'blob'
|
|
38
|
-
| 'formData'
|
|
39
|
-
| 'json'
|
|
40
|
-
| 'stream'
|
|
41
|
-
| 'text';
|
|
30
|
+
parseAs?: 'arrayBuffer' | 'auto' | 'blob' | 'formData' | 'json' | 'stream' | 'text';
|
|
42
31
|
/**
|
|
43
32
|
* Throw an error instead of returning it in the response?
|
|
44
33
|
*
|
|
@@ -51,7 +40,9 @@ export interface RequestOptions<
|
|
|
51
40
|
TData = unknown,
|
|
52
41
|
ThrowOnError extends boolean = boolean,
|
|
53
42
|
Url extends string = string,
|
|
54
|
-
>
|
|
43
|
+
>
|
|
44
|
+
extends
|
|
45
|
+
Config<{
|
|
55
46
|
throwOnError: ThrowOnError;
|
|
56
47
|
}>,
|
|
57
48
|
Pick<
|
|
@@ -96,16 +87,12 @@ export type RequestResult<
|
|
|
96
87
|
: Promise<
|
|
97
88
|
(
|
|
98
89
|
| {
|
|
99
|
-
data: TData extends Record<string, unknown>
|
|
100
|
-
? TData[keyof TData]
|
|
101
|
-
: TData;
|
|
90
|
+
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
|
|
102
91
|
error: undefined;
|
|
103
92
|
}
|
|
104
93
|
| {
|
|
105
94
|
data: undefined;
|
|
106
|
-
error: TError extends Record<string, unknown>
|
|
107
|
-
? TError[keyof TError]
|
|
108
|
-
: TError;
|
|
95
|
+
error: TError extends Record<string, unknown> ? TError[keyof TError] : TError;
|
|
109
96
|
}
|
|
110
97
|
) & {
|
|
111
98
|
response: Response;
|
|
@@ -117,27 +104,15 @@ export interface ClientOptions {
|
|
|
117
104
|
throwOnError?: boolean;
|
|
118
105
|
}
|
|
119
106
|
|
|
120
|
-
type MethodFn = <
|
|
121
|
-
TData = unknown,
|
|
122
|
-
TError = unknown,
|
|
123
|
-
ThrowOnError extends boolean = false,
|
|
124
|
-
>(
|
|
107
|
+
type MethodFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(
|
|
125
108
|
options: Omit<RequestOptions<TData, ThrowOnError>, 'method'>,
|
|
126
109
|
) => RequestResult<TData, TError, ThrowOnError>;
|
|
127
110
|
|
|
128
|
-
type SseFn = <
|
|
129
|
-
TData = unknown,
|
|
130
|
-
TError = unknown,
|
|
131
|
-
ThrowOnError extends boolean = false,
|
|
132
|
-
>(
|
|
111
|
+
type SseFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(
|
|
133
112
|
options: Omit<RequestOptions<TData, ThrowOnError>, 'method'>,
|
|
134
113
|
) => Promise<ServerSentEventsResult<TData, TError>>;
|
|
135
114
|
|
|
136
|
-
type RequestFn = <
|
|
137
|
-
TData = unknown,
|
|
138
|
-
TError = unknown,
|
|
139
|
-
ThrowOnError extends boolean = false,
|
|
140
|
-
>(
|
|
115
|
+
type RequestFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(
|
|
141
116
|
options: Omit<RequestOptions<TData, ThrowOnError>, 'method'> &
|
|
142
117
|
Pick<Required<RequestOptions<TData, ThrowOnError>>, 'method'>,
|
|
143
118
|
) => RequestResult<TData, TError, ThrowOnError>;
|
|
@@ -153,13 +128,7 @@ type BuildUrlFn = <
|
|
|
153
128
|
options: TData & Options<TData>,
|
|
154
129
|
) => string;
|
|
155
130
|
|
|
156
|
-
export type Client = CoreClient<
|
|
157
|
-
RequestFn,
|
|
158
|
-
Config,
|
|
159
|
-
MethodFn,
|
|
160
|
-
BuildUrlFn,
|
|
161
|
-
SseFn
|
|
162
|
-
> & {
|
|
131
|
+
export type Client = CoreClient<RequestFn, Config, MethodFn, BuildUrlFn, SseFn> & {
|
|
163
132
|
interceptors: Middleware<Response, unknown, ResolvedRequestOptions>;
|
|
164
133
|
};
|
|
165
134
|
|
|
@@ -189,8 +158,5 @@ export type Options<
|
|
|
189
158
|
TData extends TDataShape = TDataShape,
|
|
190
159
|
ThrowOnError extends boolean = boolean,
|
|
191
160
|
TResponse = unknown,
|
|
192
|
-
> = OmitKeys<
|
|
193
|
-
RequestOptions<TResponse, ThrowOnError>,
|
|
194
|
-
'body' | 'path' | 'query' | 'url'
|
|
195
|
-
> &
|
|
161
|
+
> = OmitKeys<RequestOptions<TResponse, ThrowOnError>, 'body' | 'path' | 'query' | 'url'> &
|
|
196
162
|
([TData] extends [never] ? unknown : Omit<TData, 'url'>);
|
|
@@ -51,10 +51,7 @@ const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
if (Array.isArray(value)) {
|
|
54
|
-
url = url.replace(
|
|
55
|
-
match,
|
|
56
|
-
serializeArrayParam({ explode, name, style, value }),
|
|
57
|
-
);
|
|
54
|
+
url = url.replace(match, serializeArrayParam({ explode, name, style, value }));
|
|
58
55
|
continue;
|
|
59
56
|
}
|
|
60
57
|
|
|
@@ -146,9 +143,7 @@ export const createQuerySerializer = <T = unknown>({
|
|
|
146
143
|
/**
|
|
147
144
|
* Infers parseAs value from provided Content-Type header.
|
|
148
145
|
*/
|
|
149
|
-
export const getParseAs = (
|
|
150
|
-
contentType: string | null,
|
|
151
|
-
): Exclude<Config['parseAs'], 'auto'> => {
|
|
146
|
+
export const getParseAs = (contentType: string | null): Exclude<Config['parseAs'], 'auto'> => {
|
|
152
147
|
if (!contentType) {
|
|
153
148
|
// If no Content-Type header is provided, the best we can do is return the raw response body,
|
|
154
149
|
// which is effectively the same as the 'stream' option.
|
|
@@ -161,10 +156,7 @@ export const getParseAs = (
|
|
|
161
156
|
return;
|
|
162
157
|
}
|
|
163
158
|
|
|
164
|
-
if (
|
|
165
|
-
cleanContent.startsWith('application/json') ||
|
|
166
|
-
cleanContent.endsWith('+json')
|
|
167
|
-
) {
|
|
159
|
+
if (cleanContent.startsWith('application/json') || cleanContent.endsWith('+json')) {
|
|
168
160
|
return 'json';
|
|
169
161
|
}
|
|
170
162
|
|
|
@@ -173,9 +165,7 @@ export const getParseAs = (
|
|
|
173
165
|
}
|
|
174
166
|
|
|
175
167
|
if (
|
|
176
|
-
['application/', 'audio/', 'image/', 'video/'].some((type) =>
|
|
177
|
-
cleanContent.startsWith(type),
|
|
178
|
-
)
|
|
168
|
+
['application/', 'audio/', 'image/', 'video/'].some((type) => cleanContent.startsWith(type))
|
|
179
169
|
) {
|
|
180
170
|
return 'blob';
|
|
181
171
|
}
|
|
@@ -311,10 +301,7 @@ export const mergeHeaders = (
|
|
|
311
301
|
continue;
|
|
312
302
|
}
|
|
313
303
|
|
|
314
|
-
const iterator =
|
|
315
|
-
header instanceof Headers
|
|
316
|
-
? headersEntries(header)
|
|
317
|
-
: Object.entries(header);
|
|
304
|
+
const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
|
|
318
305
|
|
|
319
306
|
for (const [key, value] of iterator) {
|
|
320
307
|
if (value === null) {
|
|
@@ -344,10 +331,7 @@ type ErrInterceptor<Err, Res, Options> = (
|
|
|
344
331
|
|
|
345
332
|
type ReqInterceptor<Options> = (options: Options) => void | Promise<void>;
|
|
346
333
|
|
|
347
|
-
type ResInterceptor<Res, Options> = (
|
|
348
|
-
response: Res,
|
|
349
|
-
options: Options,
|
|
350
|
-
) => Res | Promise<Res>;
|
|
334
|
+
type ResInterceptor<Res, Options> = (response: Res, options: Options) => Res | Promise<Res>;
|
|
351
335
|
|
|
352
336
|
class Interceptors<Interceptor> {
|
|
353
337
|
fns: Array<Interceptor | null> = [];
|
|
@@ -375,10 +359,7 @@ class Interceptors<Interceptor> {
|
|
|
375
359
|
return this.fns.indexOf(id);
|
|
376
360
|
}
|
|
377
361
|
|
|
378
|
-
update(
|
|
379
|
-
id: number | Interceptor,
|
|
380
|
-
fn: Interceptor,
|
|
381
|
-
): number | Interceptor | false {
|
|
362
|
+
update(id: number | Interceptor, fn: Interceptor): number | Interceptor | false {
|
|
382
363
|
const index = this.getInterceptorIndex(id);
|
|
383
364
|
if (this.fns[index]) {
|
|
384
365
|
this.fns[index] = fn;
|
|
@@ -399,11 +380,7 @@ export interface Middleware<Res, Err, Options> {
|
|
|
399
380
|
response: Interceptors<ResInterceptor<Res, Options>>;
|
|
400
381
|
}
|
|
401
382
|
|
|
402
|
-
export const createInterceptors = <Res, Err, Options>(): Middleware<
|
|
403
|
-
Res,
|
|
404
|
-
Err,
|
|
405
|
-
Options
|
|
406
|
-
> => ({
|
|
383
|
+
export const createInterceptors = <Res, Err, Options>(): Middleware<Res, Err, Options> => ({
|
|
407
384
|
error: new Interceptors<ErrInterceptor<Err, Res, Options>>(),
|
|
408
385
|
request: new Interceptors<ReqInterceptor<Options>>(),
|
|
409
386
|
response: new Interceptors<ResInterceptor<Res, Options>>(),
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
useAsyncData,
|
|
3
|
-
useFetch,
|
|
4
|
-
useLazyAsyncData,
|
|
5
|
-
useLazyFetch,
|
|
6
|
-
} from 'nuxt/app';
|
|
1
|
+
import { useAsyncData, useFetch, useLazyAsyncData, useLazyFetch } from 'nuxt/app';
|
|
7
2
|
import { reactive, ref, watch } from 'vue';
|
|
8
3
|
|
|
9
4
|
import { createSseClient } from '../core/serverSentEvents';
|
|
@@ -58,11 +53,7 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
58
53
|
return { opts, url };
|
|
59
54
|
};
|
|
60
55
|
|
|
61
|
-
const request: Client['request'] = ({
|
|
62
|
-
asyncDataOptions,
|
|
63
|
-
composable = '$fetch',
|
|
64
|
-
...options
|
|
65
|
-
}) => {
|
|
56
|
+
const request: Client['request'] = ({ asyncDataOptions, composable = '$fetch', ...options }) => {
|
|
66
57
|
const key = options.key;
|
|
67
58
|
const opts = {
|
|
68
59
|
..._config,
|
|
@@ -73,12 +64,7 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
73
64
|
onResponse: mergeInterceptors(_config.onResponse, options.onResponse),
|
|
74
65
|
};
|
|
75
66
|
|
|
76
|
-
const {
|
|
77
|
-
requestValidator,
|
|
78
|
-
responseTransformer,
|
|
79
|
-
responseValidator,
|
|
80
|
-
security,
|
|
81
|
-
} = opts;
|
|
67
|
+
const { requestValidator, responseTransformer, responseValidator, security } = opts;
|
|
82
68
|
if (requestValidator || security) {
|
|
83
69
|
// auth must happen in interceptors otherwise we'd need to require
|
|
84
70
|
// asyncContext enabled
|
|
@@ -182,26 +168,21 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
182
168
|
return undefined as any;
|
|
183
169
|
};
|
|
184
170
|
|
|
185
|
-
const makeMethodFn =
|
|
186
|
-
(
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
| undefined,
|
|
201
|
-
signal: unwrapRefs(opts.signal) as AbortSignal,
|
|
202
|
-
url,
|
|
203
|
-
});
|
|
204
|
-
};
|
|
171
|
+
const makeMethodFn = (method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
|
|
172
|
+
request({ ...options, method });
|
|
173
|
+
|
|
174
|
+
const makeSseFn = (method: Uppercase<HttpMethod>) => async (options: RequestOptions) => {
|
|
175
|
+
const { opts, url } = await beforeRequest(options);
|
|
176
|
+
return createSseClient({
|
|
177
|
+
...unwrapRefs(opts),
|
|
178
|
+
body: opts.body as BodyInit | null | undefined,
|
|
179
|
+
method,
|
|
180
|
+
onRequest: undefined,
|
|
181
|
+
serializedBody: getValidRequestBody(opts) as BodyInit | null | undefined,
|
|
182
|
+
signal: unwrapRefs(opts.signal) as AbortSignal,
|
|
183
|
+
url,
|
|
184
|
+
});
|
|
185
|
+
};
|
|
205
186
|
|
|
206
187
|
return {
|
|
207
188
|
buildUrl,
|
|
@@ -14,10 +14,7 @@ import type {
|
|
|
14
14
|
ServerSentEventsOptions,
|
|
15
15
|
ServerSentEventsResult,
|
|
16
16
|
} from '../core/serverSentEvents';
|
|
17
|
-
import type {
|
|
18
|
-
Client as CoreClient,
|
|
19
|
-
Config as CoreConfig,
|
|
20
|
-
} from '../core/types';
|
|
17
|
+
import type { Client as CoreClient, Config as CoreConfig } from '../core/types';
|
|
21
18
|
|
|
22
19
|
export type ArraySeparatorStyle = ArrayStyle | MatrixStyle;
|
|
23
20
|
type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited';
|
|
@@ -25,32 +22,20 @@ type MatrixStyle = 'label' | 'matrix' | 'simple';
|
|
|
25
22
|
export type ObjectSeparatorStyle = ObjectStyle | MatrixStyle;
|
|
26
23
|
type ObjectStyle = 'form' | 'deepObject';
|
|
27
24
|
|
|
28
|
-
export type QuerySerializer = (
|
|
29
|
-
query: Parameters<Client['buildUrl']>[0]['query'],
|
|
30
|
-
) => string;
|
|
25
|
+
export type QuerySerializer = (query: Parameters<Client['buildUrl']>[0]['query']) => string;
|
|
31
26
|
|
|
32
27
|
type WithRefs<TData> = {
|
|
33
28
|
[K in keyof TData]: NonNullable<TData[K]> extends object
|
|
34
|
-
?
|
|
35
|
-
|
|
36
|
-
| Ref<NonNullable<TData[K]>>
|
|
37
|
-
| Extract<TData[K], null>
|
|
38
|
-
:
|
|
39
|
-
| NonNullable<TData[K]>
|
|
40
|
-
| Ref<NonNullable<TData[K]>>
|
|
41
|
-
| Extract<TData[K], null>;
|
|
29
|
+
? WithRefs<NonNullable<TData[K]>> | Ref<NonNullable<TData[K]>> | Extract<TData[K], null>
|
|
30
|
+
: NonNullable<TData[K]> | Ref<NonNullable<TData[K]>> | Extract<TData[K], null>;
|
|
42
31
|
};
|
|
43
32
|
|
|
44
33
|
// copied from Nuxt
|
|
45
|
-
export type KeysOf<T> = Array<
|
|
46
|
-
T extends T ? (keyof T extends string ? keyof T : never) : never
|
|
47
|
-
>;
|
|
34
|
+
export type KeysOf<T> = Array<T extends T ? (keyof T extends string ? keyof T : never) : never>;
|
|
48
35
|
|
|
49
36
|
export interface Config<T extends ClientOptions = ClientOptions>
|
|
50
|
-
extends
|
|
51
|
-
|
|
52
|
-
'baseURL' | 'body' | 'headers' | 'method' | 'query'
|
|
53
|
-
>,
|
|
37
|
+
extends
|
|
38
|
+
Omit<FetchOptions<unknown>, 'baseURL' | 'body' | 'headers' | 'method' | 'query'>,
|
|
54
39
|
WithRefs<Pick<FetchOptions<unknown>, 'query'>>,
|
|
55
40
|
Omit<CoreConfig, 'querySerializer'> {
|
|
56
41
|
/**
|
|
@@ -72,7 +57,9 @@ export interface RequestOptions<
|
|
|
72
57
|
ResT = unknown,
|
|
73
58
|
DefaultT = undefined,
|
|
74
59
|
Url extends string = string,
|
|
75
|
-
>
|
|
60
|
+
>
|
|
61
|
+
extends
|
|
62
|
+
Config,
|
|
76
63
|
WithRefs<{
|
|
77
64
|
path?: FetchOptions<unknown>['query'];
|
|
78
65
|
query?: FetchOptions<unknown>['query'];
|
|
@@ -189,16 +176,10 @@ export type Options<
|
|
|
189
176
|
TData extends TDataShape = TDataShape,
|
|
190
177
|
ResT = unknown,
|
|
191
178
|
DefaultT = undefined,
|
|
192
|
-
> = OmitKeys<
|
|
193
|
-
RequestOptions<TComposable, ResT, DefaultT>,
|
|
194
|
-
'body' | 'path' | 'query' | 'url'
|
|
195
|
-
> &
|
|
179
|
+
> = OmitKeys<RequestOptions<TComposable, ResT, DefaultT>, 'body' | 'path' | 'query' | 'url'> &
|
|
196
180
|
([TData] extends [never] ? unknown : WithRefs<Omit<TData, 'url'>>);
|
|
197
181
|
|
|
198
|
-
type FetchOptions<TData> = Omit<
|
|
199
|
-
UseFetchOptions<TData, TData>,
|
|
200
|
-
keyof AsyncDataOptions<TData>
|
|
201
|
-
>;
|
|
182
|
+
type FetchOptions<TData> = Omit<UseFetchOptions<TData, TData>, keyof AsyncDataOptions<TData>>;
|
|
202
183
|
|
|
203
184
|
export type Composable =
|
|
204
185
|
| '$fetch'
|