@hey-api/openapi-ts 0.81.0 → 0.81.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/chunk-A2YBSPFD.js +43 -0
- package/dist/chunk-A2YBSPFD.js.map +1 -0
- package/dist/clients/angular/client.ts +27 -14
- package/dist/clients/angular/types.ts +9 -7
- package/dist/clients/axios/client.ts +27 -14
- package/dist/clients/axios/types.ts +9 -7
- package/dist/clients/core/types.ts +20 -22
- package/dist/clients/fetch/client.ts +27 -14
- package/dist/clients/fetch/types.ts +9 -7
- package/dist/clients/next/client.ts +27 -14
- package/dist/clients/next/types.ts +9 -7
- package/dist/clients/nuxt/client.ts +27 -14
- package/dist/clients/nuxt/types.ts +3 -7
- package/dist/index.cjs +68 -68
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/internal.cjs +13 -13
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.d.cts +1 -1
- package/dist/internal.d.ts +1 -1
- package/dist/internal.js +1 -1
- package/dist/{types.d-CFCN8diW.d.cts → types.d-BGYcYtD8.d.cts} +272 -3
- package/dist/{types.d-CFCN8diW.d.ts → types.d-BGYcYtD8.d.ts} +272 -3
- package/package.json +1 -1
- package/dist/chunk-Z7FL5BGA.js +0 -43
- package/dist/chunk-Z7FL5BGA.js.map +0 -1
|
@@ -15,6 +15,7 @@ import { firstValueFrom } from 'rxjs';
|
|
|
15
15
|
import { filter } from 'rxjs/operators';
|
|
16
16
|
|
|
17
17
|
import { createSseClient } from '../core/serverSentEvents';
|
|
18
|
+
import type { HttpMethod } from '../core/types';
|
|
18
19
|
import type {
|
|
19
20
|
Client,
|
|
20
21
|
Config,
|
|
@@ -198,9 +199,12 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
198
199
|
}
|
|
199
200
|
};
|
|
200
201
|
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
|
|
202
|
+
const makeMethodFn =
|
|
203
|
+
(method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
|
|
204
|
+
request({ ...options, method });
|
|
205
|
+
|
|
206
|
+
const makeSseFn =
|
|
207
|
+
(method: Uppercase<HttpMethod>) => async (options: RequestOptions) => {
|
|
204
208
|
const { opts, url } = await beforeRequest(options);
|
|
205
209
|
return createSseClient({
|
|
206
210
|
...opts,
|
|
@@ -210,21 +214,19 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
210
214
|
url,
|
|
211
215
|
});
|
|
212
216
|
};
|
|
213
|
-
return fn;
|
|
214
|
-
};
|
|
215
217
|
|
|
216
218
|
return {
|
|
217
219
|
buildUrl,
|
|
218
|
-
connect:
|
|
219
|
-
delete:
|
|
220
|
-
get:
|
|
220
|
+
connect: makeMethodFn('CONNECT'),
|
|
221
|
+
delete: makeMethodFn('DELETE'),
|
|
222
|
+
get: makeMethodFn('GET'),
|
|
221
223
|
getConfig,
|
|
222
|
-
head:
|
|
224
|
+
head: makeMethodFn('HEAD'),
|
|
223
225
|
interceptors,
|
|
224
|
-
options:
|
|
225
|
-
patch:
|
|
226
|
-
post:
|
|
227
|
-
put:
|
|
226
|
+
options: makeMethodFn('OPTIONS'),
|
|
227
|
+
patch: makeMethodFn('PATCH'),
|
|
228
|
+
post: makeMethodFn('POST'),
|
|
229
|
+
put: makeMethodFn('PUT'),
|
|
228
230
|
request,
|
|
229
231
|
requestOptions: (options) => {
|
|
230
232
|
if (options.security) {
|
|
@@ -240,6 +242,17 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
240
242
|
return requestOptions(options).req;
|
|
241
243
|
},
|
|
242
244
|
setConfig,
|
|
243
|
-
|
|
245
|
+
sse: {
|
|
246
|
+
connect: makeSseFn('CONNECT'),
|
|
247
|
+
delete: makeSseFn('DELETE'),
|
|
248
|
+
get: makeSseFn('GET'),
|
|
249
|
+
head: makeSseFn('HEAD'),
|
|
250
|
+
options: makeSseFn('OPTIONS'),
|
|
251
|
+
patch: makeSseFn('PATCH'),
|
|
252
|
+
post: makeSseFn('POST'),
|
|
253
|
+
put: makeSseFn('PUT'),
|
|
254
|
+
trace: makeSseFn('TRACE'),
|
|
255
|
+
},
|
|
256
|
+
trace: makeMethodFn('TRACE'),
|
|
244
257
|
} as Client;
|
|
245
258
|
};
|
|
@@ -155,7 +155,7 @@ export interface ClientOptions {
|
|
|
155
155
|
throwOnError?: boolean;
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
-
type
|
|
158
|
+
type MethodFn = <
|
|
159
159
|
TData = unknown,
|
|
160
160
|
TError = unknown,
|
|
161
161
|
ThrowOnError extends boolean = false,
|
|
@@ -164,7 +164,7 @@ type MethodFnBase = <
|
|
|
164
164
|
options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'>,
|
|
165
165
|
) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
166
166
|
|
|
167
|
-
type
|
|
167
|
+
type SseFn = <
|
|
168
168
|
TData = unknown,
|
|
169
169
|
TError = unknown,
|
|
170
170
|
ThrowOnError extends boolean = false,
|
|
@@ -173,10 +173,6 @@ type MethodFnServerSentEvents = <
|
|
|
173
173
|
options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'>,
|
|
174
174
|
) => Promise<ServerSentEventsResult<TData, TError>>;
|
|
175
175
|
|
|
176
|
-
type MethodFn = MethodFnBase & {
|
|
177
|
-
sse: MethodFnServerSentEvents;
|
|
178
|
-
};
|
|
179
|
-
|
|
180
176
|
type RequestFn = <
|
|
181
177
|
TData = unknown,
|
|
182
178
|
TError = unknown,
|
|
@@ -208,7 +204,13 @@ type BuildUrlFn = <
|
|
|
208
204
|
options: Pick<TData, 'url'> & Options<TData>,
|
|
209
205
|
) => string;
|
|
210
206
|
|
|
211
|
-
export type Client = CoreClient<
|
|
207
|
+
export type Client = CoreClient<
|
|
208
|
+
RequestFn,
|
|
209
|
+
Config,
|
|
210
|
+
MethodFn,
|
|
211
|
+
BuildUrlFn,
|
|
212
|
+
SseFn
|
|
213
|
+
> & {
|
|
212
214
|
interceptors: Middleware<
|
|
213
215
|
HttpRequest<unknown>,
|
|
214
216
|
HttpResponse<unknown>,
|
|
@@ -2,6 +2,7 @@ import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios';
|
|
|
2
2
|
import axios from 'axios';
|
|
3
3
|
|
|
4
4
|
import { createSseClient } from '../core/serverSentEvents';
|
|
5
|
+
import type { HttpMethod } from '../core/types';
|
|
5
6
|
import type { Client, Config, RequestOptions } from './types';
|
|
6
7
|
import {
|
|
7
8
|
buildUrl,
|
|
@@ -111,9 +112,12 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
111
112
|
}
|
|
112
113
|
};
|
|
113
114
|
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
const makeMethodFn =
|
|
116
|
+
(method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
|
|
117
|
+
request({ ...options, method });
|
|
118
|
+
|
|
119
|
+
const makeSseFn =
|
|
120
|
+
(method: Uppercase<HttpMethod>) => async (options: RequestOptions) => {
|
|
117
121
|
const { opts, url } = await beforeRequest(options);
|
|
118
122
|
return createSseClient({
|
|
119
123
|
...opts,
|
|
@@ -125,23 +129,32 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
125
129
|
url,
|
|
126
130
|
});
|
|
127
131
|
};
|
|
128
|
-
return fn;
|
|
129
|
-
};
|
|
130
132
|
|
|
131
133
|
return {
|
|
132
134
|
buildUrl,
|
|
133
|
-
connect:
|
|
134
|
-
delete:
|
|
135
|
-
get:
|
|
135
|
+
connect: makeMethodFn('CONNECT'),
|
|
136
|
+
delete: makeMethodFn('DELETE'),
|
|
137
|
+
get: makeMethodFn('GET'),
|
|
136
138
|
getConfig,
|
|
137
|
-
head:
|
|
139
|
+
head: makeMethodFn('HEAD'),
|
|
138
140
|
instance,
|
|
139
|
-
options:
|
|
140
|
-
patch:
|
|
141
|
-
post:
|
|
142
|
-
put:
|
|
141
|
+
options: makeMethodFn('OPTIONS'),
|
|
142
|
+
patch: makeMethodFn('PATCH'),
|
|
143
|
+
post: makeMethodFn('POST'),
|
|
144
|
+
put: makeMethodFn('PUT'),
|
|
143
145
|
request,
|
|
144
146
|
setConfig,
|
|
145
|
-
|
|
147
|
+
sse: {
|
|
148
|
+
connect: makeSseFn('CONNECT'),
|
|
149
|
+
delete: makeSseFn('DELETE'),
|
|
150
|
+
get: makeSseFn('GET'),
|
|
151
|
+
head: makeSseFn('HEAD'),
|
|
152
|
+
options: makeSseFn('OPTIONS'),
|
|
153
|
+
patch: makeSseFn('PATCH'),
|
|
154
|
+
post: makeSseFn('POST'),
|
|
155
|
+
put: makeSseFn('PUT'),
|
|
156
|
+
trace: makeSseFn('TRACE'),
|
|
157
|
+
},
|
|
158
|
+
trace: makeMethodFn('TRACE'),
|
|
146
159
|
} as Client;
|
|
147
160
|
};
|
|
@@ -116,7 +116,7 @@ export type RequestResult<
|
|
|
116
116
|
})
|
|
117
117
|
>;
|
|
118
118
|
|
|
119
|
-
type
|
|
119
|
+
type MethodFn = <
|
|
120
120
|
TData = unknown,
|
|
121
121
|
TError = unknown,
|
|
122
122
|
ThrowOnError extends boolean = false,
|
|
@@ -124,7 +124,7 @@ type MethodFnBase = <
|
|
|
124
124
|
options: Omit<RequestOptions<TData, ThrowOnError>, 'method'>,
|
|
125
125
|
) => RequestResult<TData, TError, ThrowOnError>;
|
|
126
126
|
|
|
127
|
-
type
|
|
127
|
+
type SseFn = <
|
|
128
128
|
TData = unknown,
|
|
129
129
|
TError = unknown,
|
|
130
130
|
ThrowOnError extends boolean = false,
|
|
@@ -132,10 +132,6 @@ type MethodFnServerSentEvents = <
|
|
|
132
132
|
options: Omit<RequestOptions<TData, ThrowOnError>, 'method'>,
|
|
133
133
|
) => Promise<ServerSentEventsResult<TData, TError>>;
|
|
134
134
|
|
|
135
|
-
type MethodFn = MethodFnBase & {
|
|
136
|
-
sse: MethodFnServerSentEvents;
|
|
137
|
-
};
|
|
138
|
-
|
|
139
135
|
type RequestFn = <
|
|
140
136
|
TData = unknown,
|
|
141
137
|
TError = unknown,
|
|
@@ -156,7 +152,13 @@ type BuildUrlFn = <
|
|
|
156
152
|
options: Pick<TData, 'url'> & Omit<Options<TData>, 'axios'>,
|
|
157
153
|
) => string;
|
|
158
154
|
|
|
159
|
-
export type Client = CoreClient<
|
|
155
|
+
export type Client = CoreClient<
|
|
156
|
+
RequestFn,
|
|
157
|
+
Config,
|
|
158
|
+
MethodFn,
|
|
159
|
+
BuildUrlFn,
|
|
160
|
+
SseFn
|
|
161
|
+
> & {
|
|
160
162
|
instance: AxiosInstance;
|
|
161
163
|
};
|
|
162
164
|
|
|
@@ -5,29 +5,36 @@ import type {
|
|
|
5
5
|
QuerySerializerOptions,
|
|
6
6
|
} from './bodySerializer';
|
|
7
7
|
|
|
8
|
-
export
|
|
8
|
+
export type HttpMethod =
|
|
9
|
+
| 'connect'
|
|
10
|
+
| 'delete'
|
|
11
|
+
| 'get'
|
|
12
|
+
| 'head'
|
|
13
|
+
| 'options'
|
|
14
|
+
| 'patch'
|
|
15
|
+
| 'post'
|
|
16
|
+
| 'put'
|
|
17
|
+
| 'trace';
|
|
18
|
+
|
|
19
|
+
export type Client<
|
|
9
20
|
RequestFn = never,
|
|
10
21
|
Config = unknown,
|
|
11
22
|
MethodFn = never,
|
|
12
23
|
BuildUrlFn = never,
|
|
13
|
-
|
|
24
|
+
SseFn = never,
|
|
25
|
+
> = {
|
|
14
26
|
/**
|
|
15
27
|
* Returns the final request URL.
|
|
16
28
|
*/
|
|
17
29
|
buildUrl: BuildUrlFn;
|
|
18
|
-
connect: MethodFn;
|
|
19
|
-
delete: MethodFn;
|
|
20
|
-
get: MethodFn;
|
|
21
30
|
getConfig: () => Config;
|
|
22
|
-
head: MethodFn;
|
|
23
|
-
options: MethodFn;
|
|
24
|
-
patch: MethodFn;
|
|
25
|
-
post: MethodFn;
|
|
26
|
-
put: MethodFn;
|
|
27
31
|
request: RequestFn;
|
|
28
32
|
setConfig: (config: Config) => Config;
|
|
29
|
-
|
|
30
|
-
|
|
33
|
+
} & {
|
|
34
|
+
[K in HttpMethod]: MethodFn;
|
|
35
|
+
} & ([SseFn] extends [never]
|
|
36
|
+
? { sse?: never }
|
|
37
|
+
: { sse: { [K in HttpMethod]: SseFn } });
|
|
31
38
|
|
|
32
39
|
export interface Config {
|
|
33
40
|
/**
|
|
@@ -63,16 +70,7 @@ export interface Config {
|
|
|
63
70
|
*
|
|
64
71
|
* {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more}
|
|
65
72
|
*/
|
|
66
|
-
method?:
|
|
67
|
-
| 'CONNECT'
|
|
68
|
-
| 'DELETE'
|
|
69
|
-
| 'GET'
|
|
70
|
-
| 'HEAD'
|
|
71
|
-
| 'OPTIONS'
|
|
72
|
-
| 'PATCH'
|
|
73
|
-
| 'POST'
|
|
74
|
-
| 'PUT'
|
|
75
|
-
| 'TRACE';
|
|
73
|
+
method?: Uppercase<HttpMethod>;
|
|
76
74
|
/**
|
|
77
75
|
* A function for serializing request query parameters. By default, arrays
|
|
78
76
|
* will be exploded in form style, objects will be exploded in deepObject
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createSseClient } from '../core/serverSentEvents';
|
|
2
|
+
import type { HttpMethod } from '../core/types';
|
|
2
3
|
import type {
|
|
3
4
|
Client,
|
|
4
5
|
Config,
|
|
@@ -191,9 +192,12 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
191
192
|
};
|
|
192
193
|
};
|
|
193
194
|
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
|
|
195
|
+
const makeMethodFn =
|
|
196
|
+
(method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
|
|
197
|
+
request({ ...options, method });
|
|
198
|
+
|
|
199
|
+
const makeSseFn =
|
|
200
|
+
(method: Uppercase<HttpMethod>) => async (options: RequestOptions) => {
|
|
197
201
|
const { opts, url } = await beforeRequest(options);
|
|
198
202
|
return createSseClient({
|
|
199
203
|
...opts,
|
|
@@ -203,23 +207,32 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
203
207
|
url,
|
|
204
208
|
});
|
|
205
209
|
};
|
|
206
|
-
return fn;
|
|
207
|
-
};
|
|
208
210
|
|
|
209
211
|
return {
|
|
210
212
|
buildUrl,
|
|
211
|
-
connect:
|
|
212
|
-
delete:
|
|
213
|
-
get:
|
|
213
|
+
connect: makeMethodFn('CONNECT'),
|
|
214
|
+
delete: makeMethodFn('DELETE'),
|
|
215
|
+
get: makeMethodFn('GET'),
|
|
214
216
|
getConfig,
|
|
215
|
-
head:
|
|
217
|
+
head: makeMethodFn('HEAD'),
|
|
216
218
|
interceptors,
|
|
217
|
-
options:
|
|
218
|
-
patch:
|
|
219
|
-
post:
|
|
220
|
-
put:
|
|
219
|
+
options: makeMethodFn('OPTIONS'),
|
|
220
|
+
patch: makeMethodFn('PATCH'),
|
|
221
|
+
post: makeMethodFn('POST'),
|
|
222
|
+
put: makeMethodFn('PUT'),
|
|
221
223
|
request,
|
|
222
224
|
setConfig,
|
|
223
|
-
|
|
225
|
+
sse: {
|
|
226
|
+
connect: makeSseFn('CONNECT'),
|
|
227
|
+
delete: makeSseFn('DELETE'),
|
|
228
|
+
get: makeSseFn('GET'),
|
|
229
|
+
head: makeSseFn('HEAD'),
|
|
230
|
+
options: makeSseFn('OPTIONS'),
|
|
231
|
+
patch: makeSseFn('PATCH'),
|
|
232
|
+
post: makeSseFn('POST'),
|
|
233
|
+
put: makeSseFn('PUT'),
|
|
234
|
+
trace: makeSseFn('TRACE'),
|
|
235
|
+
},
|
|
236
|
+
trace: makeMethodFn('TRACE'),
|
|
224
237
|
} as Client;
|
|
225
238
|
};
|
|
@@ -153,7 +153,7 @@ export interface ClientOptions {
|
|
|
153
153
|
throwOnError?: boolean;
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
type
|
|
156
|
+
type MethodFn = <
|
|
157
157
|
TData = unknown,
|
|
158
158
|
TError = unknown,
|
|
159
159
|
ThrowOnError extends boolean = false,
|
|
@@ -162,7 +162,7 @@ type MethodFnBase = <
|
|
|
162
162
|
options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'>,
|
|
163
163
|
) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
164
164
|
|
|
165
|
-
type
|
|
165
|
+
type SseFn = <
|
|
166
166
|
TData = unknown,
|
|
167
167
|
TError = unknown,
|
|
168
168
|
ThrowOnError extends boolean = false,
|
|
@@ -171,10 +171,6 @@ type MethodFnServerSentEvents = <
|
|
|
171
171
|
options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'>,
|
|
172
172
|
) => Promise<ServerSentEventsResult<TData, TError>>;
|
|
173
173
|
|
|
174
|
-
type MethodFn = MethodFnBase & {
|
|
175
|
-
sse: MethodFnServerSentEvents;
|
|
176
|
-
};
|
|
177
|
-
|
|
178
174
|
type RequestFn = <
|
|
179
175
|
TData = unknown,
|
|
180
176
|
TError = unknown,
|
|
@@ -199,7 +195,13 @@ type BuildUrlFn = <
|
|
|
199
195
|
options: Pick<TData, 'url'> & Options<TData>,
|
|
200
196
|
) => string;
|
|
201
197
|
|
|
202
|
-
export type Client = CoreClient<
|
|
198
|
+
export type Client = CoreClient<
|
|
199
|
+
RequestFn,
|
|
200
|
+
Config,
|
|
201
|
+
MethodFn,
|
|
202
|
+
BuildUrlFn,
|
|
203
|
+
SseFn
|
|
204
|
+
> & {
|
|
203
205
|
interceptors: Middleware<Request, Response, unknown, ResolvedRequestOptions>;
|
|
204
206
|
};
|
|
205
207
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createSseClient } from '../core/serverSentEvents';
|
|
2
|
+
import type { HttpMethod } from '../core/types';
|
|
2
3
|
import type {
|
|
3
4
|
Client,
|
|
4
5
|
Config,
|
|
@@ -177,9 +178,12 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
177
178
|
};
|
|
178
179
|
};
|
|
179
180
|
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
|
|
181
|
+
const makeMethodFn =
|
|
182
|
+
(method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
|
|
183
|
+
request({ ...options, method });
|
|
184
|
+
|
|
185
|
+
const makeSseFn =
|
|
186
|
+
(method: Uppercase<HttpMethod>) => async (options: RequestOptions) => {
|
|
183
187
|
const { opts, url } = await beforeRequest(options);
|
|
184
188
|
return createSseClient({
|
|
185
189
|
...opts,
|
|
@@ -189,23 +193,32 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
189
193
|
url,
|
|
190
194
|
});
|
|
191
195
|
};
|
|
192
|
-
return fn;
|
|
193
|
-
};
|
|
194
196
|
|
|
195
197
|
return {
|
|
196
198
|
buildUrl,
|
|
197
|
-
connect:
|
|
198
|
-
delete:
|
|
199
|
-
get:
|
|
199
|
+
connect: makeMethodFn('CONNECT'),
|
|
200
|
+
delete: makeMethodFn('DELETE'),
|
|
201
|
+
get: makeMethodFn('GET'),
|
|
200
202
|
getConfig,
|
|
201
|
-
head:
|
|
203
|
+
head: makeMethodFn('HEAD'),
|
|
202
204
|
interceptors,
|
|
203
|
-
options:
|
|
204
|
-
patch:
|
|
205
|
-
post:
|
|
206
|
-
put:
|
|
205
|
+
options: makeMethodFn('OPTIONS'),
|
|
206
|
+
patch: makeMethodFn('PATCH'),
|
|
207
|
+
post: makeMethodFn('POST'),
|
|
208
|
+
put: makeMethodFn('PUT'),
|
|
207
209
|
request,
|
|
208
210
|
setConfig,
|
|
209
|
-
|
|
211
|
+
sse: {
|
|
212
|
+
connect: makeSseFn('CONNECT'),
|
|
213
|
+
delete: makeSseFn('DELETE'),
|
|
214
|
+
get: makeSseFn('GET'),
|
|
215
|
+
head: makeSseFn('HEAD'),
|
|
216
|
+
options: makeSseFn('OPTIONS'),
|
|
217
|
+
patch: makeSseFn('PATCH'),
|
|
218
|
+
post: makeSseFn('POST'),
|
|
219
|
+
put: makeSseFn('PUT'),
|
|
220
|
+
trace: makeSseFn('TRACE'),
|
|
221
|
+
},
|
|
222
|
+
trace: makeMethodFn('TRACE'),
|
|
210
223
|
} as Client;
|
|
211
224
|
};
|
|
@@ -117,7 +117,7 @@ export interface ClientOptions {
|
|
|
117
117
|
throwOnError?: boolean;
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
type
|
|
120
|
+
type MethodFn = <
|
|
121
121
|
TData = unknown,
|
|
122
122
|
TError = unknown,
|
|
123
123
|
ThrowOnError extends boolean = false,
|
|
@@ -125,7 +125,7 @@ type MethodFnBase = <
|
|
|
125
125
|
options: Omit<RequestOptions<TData, ThrowOnError>, 'method'>,
|
|
126
126
|
) => RequestResult<TData, TError, ThrowOnError>;
|
|
127
127
|
|
|
128
|
-
type
|
|
128
|
+
type SseFn = <
|
|
129
129
|
TData = unknown,
|
|
130
130
|
TError = unknown,
|
|
131
131
|
ThrowOnError extends boolean = false,
|
|
@@ -133,10 +133,6 @@ type MethodFnServerSentEvents = <
|
|
|
133
133
|
options: Omit<RequestOptions<TData, ThrowOnError>, 'method'>,
|
|
134
134
|
) => Promise<ServerSentEventsResult<TData, TError>>;
|
|
135
135
|
|
|
136
|
-
type MethodFn = MethodFnBase & {
|
|
137
|
-
sse: MethodFnServerSentEvents;
|
|
138
|
-
};
|
|
139
|
-
|
|
140
136
|
type RequestFn = <
|
|
141
137
|
TData = unknown,
|
|
142
138
|
TError = unknown,
|
|
@@ -157,7 +153,13 @@ type BuildUrlFn = <
|
|
|
157
153
|
options: Pick<TData, 'url'> & Options<TData>,
|
|
158
154
|
) => string;
|
|
159
155
|
|
|
160
|
-
export type Client = CoreClient<
|
|
156
|
+
export type Client = CoreClient<
|
|
157
|
+
RequestFn,
|
|
158
|
+
Config,
|
|
159
|
+
MethodFn,
|
|
160
|
+
BuildUrlFn,
|
|
161
|
+
SseFn
|
|
162
|
+
> & {
|
|
161
163
|
interceptors: Middleware<Response, unknown, ResolvedRequestOptions>;
|
|
162
164
|
};
|
|
163
165
|
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
import { reactive, ref, watch } from 'vue';
|
|
8
8
|
|
|
9
9
|
import { createSseClient } from '../core/serverSentEvents';
|
|
10
|
+
import type { HttpMethod } from '../core/types';
|
|
10
11
|
import type { Client, Config, RequestOptions } from './types';
|
|
11
12
|
import {
|
|
12
13
|
buildUrl,
|
|
@@ -180,9 +181,12 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
180
181
|
return undefined as any;
|
|
181
182
|
};
|
|
182
183
|
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
|
|
184
|
+
const makeMethodFn =
|
|
185
|
+
(method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
|
|
186
|
+
request({ ...options, method });
|
|
187
|
+
|
|
188
|
+
const makeSseFn =
|
|
189
|
+
(method: Uppercase<HttpMethod>) => async (options: RequestOptions) => {
|
|
186
190
|
const { opts, url } = await beforeRequest(options);
|
|
187
191
|
return createSseClient({
|
|
188
192
|
...unwrapRefs(opts),
|
|
@@ -192,22 +196,31 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
192
196
|
url,
|
|
193
197
|
});
|
|
194
198
|
};
|
|
195
|
-
return fn;
|
|
196
|
-
};
|
|
197
199
|
|
|
198
200
|
return {
|
|
199
201
|
buildUrl,
|
|
200
|
-
connect:
|
|
201
|
-
delete:
|
|
202
|
-
get:
|
|
202
|
+
connect: makeMethodFn('CONNECT'),
|
|
203
|
+
delete: makeMethodFn('DELETE'),
|
|
204
|
+
get: makeMethodFn('GET'),
|
|
203
205
|
getConfig,
|
|
204
|
-
head:
|
|
205
|
-
options:
|
|
206
|
-
patch:
|
|
207
|
-
post:
|
|
208
|
-
put:
|
|
206
|
+
head: makeMethodFn('HEAD'),
|
|
207
|
+
options: makeMethodFn('OPTIONS'),
|
|
208
|
+
patch: makeMethodFn('PATCH'),
|
|
209
|
+
post: makeMethodFn('POST'),
|
|
210
|
+
put: makeMethodFn('PUT'),
|
|
209
211
|
request,
|
|
210
212
|
setConfig,
|
|
211
|
-
|
|
213
|
+
sse: {
|
|
214
|
+
connect: makeSseFn('CONNECT'),
|
|
215
|
+
delete: makeSseFn('DELETE'),
|
|
216
|
+
get: makeSseFn('GET'),
|
|
217
|
+
head: makeSseFn('HEAD'),
|
|
218
|
+
options: makeSseFn('OPTIONS'),
|
|
219
|
+
patch: makeSseFn('PATCH'),
|
|
220
|
+
post: makeSseFn('POST'),
|
|
221
|
+
put: makeSseFn('PUT'),
|
|
222
|
+
trace: makeSseFn('TRACE'),
|
|
223
|
+
},
|
|
224
|
+
trace: makeMethodFn('TRACE'),
|
|
212
225
|
} as Client;
|
|
213
226
|
};
|
|
@@ -116,7 +116,7 @@ export interface ClientOptions {
|
|
|
116
116
|
baseURL?: string;
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
type
|
|
119
|
+
type MethodFn = <
|
|
120
120
|
TComposable extends Composable,
|
|
121
121
|
ResT = unknown,
|
|
122
122
|
TError = unknown,
|
|
@@ -125,7 +125,7 @@ type MethodFnBase = <
|
|
|
125
125
|
options: Omit<RequestOptions<TComposable, ResT, DefaultT>, 'method'>,
|
|
126
126
|
) => RequestResult<TComposable, ResT, TError>;
|
|
127
127
|
|
|
128
|
-
type
|
|
128
|
+
type SseFn = <
|
|
129
129
|
TComposable extends Composable,
|
|
130
130
|
ResT = unknown,
|
|
131
131
|
TError = unknown,
|
|
@@ -134,10 +134,6 @@ type MethodFnServerSentEvents = <
|
|
|
134
134
|
options: Omit<RequestOptions<TComposable, ResT, DefaultT>, 'method'>,
|
|
135
135
|
) => Promise<ServerSentEventsResult<RequestResult<TComposable, ResT, TError>>>;
|
|
136
136
|
|
|
137
|
-
type MethodFn = MethodFnBase & {
|
|
138
|
-
sse: MethodFnServerSentEvents;
|
|
139
|
-
};
|
|
140
|
-
|
|
141
137
|
type RequestFn = <
|
|
142
138
|
TComposable extends Composable,
|
|
143
139
|
ResT = unknown,
|
|
@@ -178,7 +174,7 @@ type BuildUrlFn = <TData extends Omit<TDataShape, 'headers'>>(
|
|
|
178
174
|
options: BuildUrlOptions<TData>,
|
|
179
175
|
) => string;
|
|
180
176
|
|
|
181
|
-
export type Client = CoreClient<RequestFn, Config, MethodFn, BuildUrlFn>;
|
|
177
|
+
export type Client = CoreClient<RequestFn, Config, MethodFn, BuildUrlFn, SseFn>;
|
|
182
178
|
|
|
183
179
|
type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
|
|
184
180
|
|