@townco/fly 0.1.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/.envrc +11 -0
- package/openapi-ts.config.ts +7 -0
- package/package.json +30 -0
- package/spec.json +5072 -0
- package/src/client/client.gen.ts +301 -0
- package/src/client/index.ts +25 -0
- package/src/client/types.gen.ts +241 -0
- package/src/client/utils.gen.ts +337 -0
- package/src/client.gen.ts +25 -0
- package/src/core/auth.gen.ts +42 -0
- package/src/core/bodySerializer.gen.ts +100 -0
- package/src/core/params.gen.ts +176 -0
- package/src/core/pathSerializer.gen.ts +181 -0
- package/src/core/queryKeySerializer.gen.ts +136 -0
- package/src/core/serverSentEvents.gen.ts +264 -0
- package/src/core/types.gen.ts +118 -0
- package/src/core/utils.gen.ts +143 -0
- package/src/hey-api.ts +8 -0
- package/src/index.ts +4 -0
- package/src/sdk.gen.ts +1163 -0
- package/src/types.gen.ts +2974 -0
- package/tsconfig.json +11 -0
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
|
|
3
|
+
import { createSseClient } from "../core/serverSentEvents.gen";
|
|
4
|
+
import type { HttpMethod } from "../core/types.gen";
|
|
5
|
+
import { getValidRequestBody } from "../core/utils.gen";
|
|
6
|
+
import type {
|
|
7
|
+
Client,
|
|
8
|
+
Config,
|
|
9
|
+
RequestOptions,
|
|
10
|
+
ResolvedRequestOptions,
|
|
11
|
+
} from "./types.gen";
|
|
12
|
+
import {
|
|
13
|
+
buildUrl,
|
|
14
|
+
createConfig,
|
|
15
|
+
createInterceptors,
|
|
16
|
+
getParseAs,
|
|
17
|
+
mergeConfigs,
|
|
18
|
+
mergeHeaders,
|
|
19
|
+
setAuthParams,
|
|
20
|
+
} from "./utils.gen";
|
|
21
|
+
|
|
22
|
+
type ReqInit = Omit<RequestInit, "body" | "headers"> & {
|
|
23
|
+
body?: any;
|
|
24
|
+
headers: ReturnType<typeof mergeHeaders>;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const createClient = (config: Config = {}): Client => {
|
|
28
|
+
let _config = mergeConfigs(createConfig(), config);
|
|
29
|
+
|
|
30
|
+
const getConfig = (): Config => ({ ..._config });
|
|
31
|
+
|
|
32
|
+
const setConfig = (config: Config): Config => {
|
|
33
|
+
_config = mergeConfigs(_config, config);
|
|
34
|
+
return getConfig();
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const interceptors = createInterceptors<
|
|
38
|
+
Request,
|
|
39
|
+
Response,
|
|
40
|
+
unknown,
|
|
41
|
+
ResolvedRequestOptions
|
|
42
|
+
>();
|
|
43
|
+
|
|
44
|
+
const beforeRequest = async (options: RequestOptions) => {
|
|
45
|
+
const opts = {
|
|
46
|
+
..._config,
|
|
47
|
+
...options,
|
|
48
|
+
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
49
|
+
headers: mergeHeaders(_config.headers, options.headers),
|
|
50
|
+
serializedBody: undefined,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
if (opts.security) {
|
|
54
|
+
await setAuthParams({
|
|
55
|
+
...opts,
|
|
56
|
+
security: opts.security,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (opts.requestValidator) {
|
|
61
|
+
await opts.requestValidator(opts);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (opts.body !== undefined && opts.bodySerializer) {
|
|
65
|
+
opts.serializedBody = opts.bodySerializer(opts.body);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// remove Content-Type header if body is empty to avoid sending invalid requests
|
|
69
|
+
if (opts.body === undefined || opts.serializedBody === "") {
|
|
70
|
+
opts.headers.delete("Content-Type");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const url = buildUrl(opts);
|
|
74
|
+
|
|
75
|
+
return { opts, url };
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const request: Client["request"] = async (options) => {
|
|
79
|
+
// @ts-expect-error
|
|
80
|
+
const { opts, url } = await beforeRequest(options);
|
|
81
|
+
const requestInit: ReqInit = {
|
|
82
|
+
redirect: "follow",
|
|
83
|
+
...opts,
|
|
84
|
+
body: getValidRequestBody(opts),
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
let request = new Request(url, requestInit);
|
|
88
|
+
|
|
89
|
+
for (const fn of interceptors.request.fns) {
|
|
90
|
+
if (fn) {
|
|
91
|
+
request = await fn(request, opts);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// fetch must be assigned here, otherwise it would throw the error:
|
|
96
|
+
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
|
|
97
|
+
const _fetch = opts.fetch!;
|
|
98
|
+
let response: Response;
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
response = await _fetch(request);
|
|
102
|
+
} catch (error) {
|
|
103
|
+
// Handle fetch exceptions (AbortError, network errors, etc.)
|
|
104
|
+
let finalError = error;
|
|
105
|
+
|
|
106
|
+
for (const fn of interceptors.error.fns) {
|
|
107
|
+
if (fn) {
|
|
108
|
+
finalError = (await fn(
|
|
109
|
+
error,
|
|
110
|
+
undefined as any,
|
|
111
|
+
request,
|
|
112
|
+
opts,
|
|
113
|
+
)) as unknown;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
finalError = finalError || ({} as unknown);
|
|
118
|
+
|
|
119
|
+
if (opts.throwOnError) {
|
|
120
|
+
throw finalError;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Return error response
|
|
124
|
+
return opts.responseStyle === "data"
|
|
125
|
+
? undefined
|
|
126
|
+
: {
|
|
127
|
+
error: finalError,
|
|
128
|
+
request,
|
|
129
|
+
response: undefined as any,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
for (const fn of interceptors.response.fns) {
|
|
134
|
+
if (fn) {
|
|
135
|
+
response = await fn(response, request, opts);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const result = {
|
|
140
|
+
request,
|
|
141
|
+
response,
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
if (response.ok) {
|
|
145
|
+
const parseAs =
|
|
146
|
+
(opts.parseAs === "auto"
|
|
147
|
+
? getParseAs(response.headers.get("Content-Type"))
|
|
148
|
+
: opts.parseAs) ?? "json";
|
|
149
|
+
|
|
150
|
+
if (
|
|
151
|
+
response.status === 204 ||
|
|
152
|
+
response.headers.get("Content-Length") === "0"
|
|
153
|
+
) {
|
|
154
|
+
let emptyData: any;
|
|
155
|
+
switch (parseAs) {
|
|
156
|
+
case "arrayBuffer":
|
|
157
|
+
case "blob":
|
|
158
|
+
case "text":
|
|
159
|
+
emptyData = await response[parseAs]();
|
|
160
|
+
break;
|
|
161
|
+
case "formData":
|
|
162
|
+
emptyData = new FormData();
|
|
163
|
+
break;
|
|
164
|
+
case "stream":
|
|
165
|
+
emptyData = response.body;
|
|
166
|
+
break;
|
|
167
|
+
case "json":
|
|
168
|
+
default:
|
|
169
|
+
emptyData = {};
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
return opts.responseStyle === "data"
|
|
173
|
+
? emptyData
|
|
174
|
+
: {
|
|
175
|
+
data: emptyData,
|
|
176
|
+
...result,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
let data: any;
|
|
181
|
+
switch (parseAs) {
|
|
182
|
+
case "arrayBuffer":
|
|
183
|
+
case "blob":
|
|
184
|
+
case "formData":
|
|
185
|
+
case "json":
|
|
186
|
+
case "text":
|
|
187
|
+
data = await response[parseAs]();
|
|
188
|
+
break;
|
|
189
|
+
case "stream":
|
|
190
|
+
return opts.responseStyle === "data"
|
|
191
|
+
? response.body
|
|
192
|
+
: {
|
|
193
|
+
data: response.body,
|
|
194
|
+
...result,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (parseAs === "json") {
|
|
199
|
+
if (opts.responseValidator) {
|
|
200
|
+
await opts.responseValidator(data);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (opts.responseTransformer) {
|
|
204
|
+
data = await opts.responseTransformer(data);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return opts.responseStyle === "data"
|
|
209
|
+
? data
|
|
210
|
+
: {
|
|
211
|
+
data,
|
|
212
|
+
...result,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const textError = await response.text();
|
|
217
|
+
let jsonError: unknown;
|
|
218
|
+
|
|
219
|
+
try {
|
|
220
|
+
jsonError = JSON.parse(textError);
|
|
221
|
+
} catch {
|
|
222
|
+
// noop
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const error = jsonError ?? textError;
|
|
226
|
+
let finalError = error;
|
|
227
|
+
|
|
228
|
+
for (const fn of interceptors.error.fns) {
|
|
229
|
+
if (fn) {
|
|
230
|
+
finalError = (await fn(error, response, request, opts)) as string;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
finalError = finalError || ({} as string);
|
|
235
|
+
|
|
236
|
+
if (opts.throwOnError) {
|
|
237
|
+
throw finalError;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// TODO: we probably want to return error and improve types
|
|
241
|
+
return opts.responseStyle === "data"
|
|
242
|
+
? undefined
|
|
243
|
+
: {
|
|
244
|
+
error: finalError,
|
|
245
|
+
...result,
|
|
246
|
+
};
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
const makeMethodFn =
|
|
250
|
+
(method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
|
|
251
|
+
request({ ...options, method });
|
|
252
|
+
|
|
253
|
+
const makeSseFn =
|
|
254
|
+
(method: Uppercase<HttpMethod>) => async (options: RequestOptions) => {
|
|
255
|
+
const { opts, url } = await beforeRequest(options);
|
|
256
|
+
return createSseClient({
|
|
257
|
+
...opts,
|
|
258
|
+
body: opts.body as BodyInit | null | undefined,
|
|
259
|
+
headers: opts.headers as unknown as Record<string, string>,
|
|
260
|
+
method,
|
|
261
|
+
onRequest: async (url, init) => {
|
|
262
|
+
let request = new Request(url, init);
|
|
263
|
+
for (const fn of interceptors.request.fns) {
|
|
264
|
+
if (fn) {
|
|
265
|
+
request = await fn(request, opts);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return request;
|
|
269
|
+
},
|
|
270
|
+
url,
|
|
271
|
+
});
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
return {
|
|
275
|
+
buildUrl,
|
|
276
|
+
connect: makeMethodFn("CONNECT"),
|
|
277
|
+
delete: makeMethodFn("DELETE"),
|
|
278
|
+
get: makeMethodFn("GET"),
|
|
279
|
+
getConfig,
|
|
280
|
+
head: makeMethodFn("HEAD"),
|
|
281
|
+
interceptors,
|
|
282
|
+
options: makeMethodFn("OPTIONS"),
|
|
283
|
+
patch: makeMethodFn("PATCH"),
|
|
284
|
+
post: makeMethodFn("POST"),
|
|
285
|
+
put: makeMethodFn("PUT"),
|
|
286
|
+
request,
|
|
287
|
+
setConfig,
|
|
288
|
+
sse: {
|
|
289
|
+
connect: makeSseFn("CONNECT"),
|
|
290
|
+
delete: makeSseFn("DELETE"),
|
|
291
|
+
get: makeSseFn("GET"),
|
|
292
|
+
head: makeSseFn("HEAD"),
|
|
293
|
+
options: makeSseFn("OPTIONS"),
|
|
294
|
+
patch: makeSseFn("PATCH"),
|
|
295
|
+
post: makeSseFn("POST"),
|
|
296
|
+
put: makeSseFn("PUT"),
|
|
297
|
+
trace: makeSseFn("TRACE"),
|
|
298
|
+
},
|
|
299
|
+
trace: makeMethodFn("TRACE"),
|
|
300
|
+
} as Client;
|
|
301
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
|
|
3
|
+
export type { Auth } from "../core/auth.gen";
|
|
4
|
+
export type { QuerySerializerOptions } from "../core/bodySerializer.gen";
|
|
5
|
+
export {
|
|
6
|
+
formDataBodySerializer,
|
|
7
|
+
jsonBodySerializer,
|
|
8
|
+
urlSearchParamsBodySerializer,
|
|
9
|
+
} from "../core/bodySerializer.gen";
|
|
10
|
+
export { buildClientParams } from "../core/params.gen";
|
|
11
|
+
export { serializeQueryKeyValue } from "../core/queryKeySerializer.gen";
|
|
12
|
+
export { createClient } from "./client.gen";
|
|
13
|
+
export type {
|
|
14
|
+
Client,
|
|
15
|
+
ClientOptions,
|
|
16
|
+
Config,
|
|
17
|
+
CreateClientConfig,
|
|
18
|
+
Options,
|
|
19
|
+
RequestOptions,
|
|
20
|
+
RequestResult,
|
|
21
|
+
ResolvedRequestOptions,
|
|
22
|
+
ResponseStyle,
|
|
23
|
+
TDataShape,
|
|
24
|
+
} from "./types.gen";
|
|
25
|
+
export { createConfig, mergeHeaders } from "./utils.gen";
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
|
|
3
|
+
import type { Auth } from "../core/auth.gen";
|
|
4
|
+
import type {
|
|
5
|
+
ServerSentEventsOptions,
|
|
6
|
+
ServerSentEventsResult,
|
|
7
|
+
} from "../core/serverSentEvents.gen";
|
|
8
|
+
import type {
|
|
9
|
+
Client as CoreClient,
|
|
10
|
+
Config as CoreConfig,
|
|
11
|
+
} from "../core/types.gen";
|
|
12
|
+
import type { Middleware } from "./utils.gen";
|
|
13
|
+
|
|
14
|
+
export type ResponseStyle = "data" | "fields";
|
|
15
|
+
|
|
16
|
+
export interface Config<T extends ClientOptions = ClientOptions>
|
|
17
|
+
extends Omit<RequestInit, "body" | "headers" | "method">,
|
|
18
|
+
CoreConfig {
|
|
19
|
+
/**
|
|
20
|
+
* Base URL for all requests made by this client.
|
|
21
|
+
*/
|
|
22
|
+
baseUrl?: T["baseUrl"];
|
|
23
|
+
/**
|
|
24
|
+
* Fetch API implementation. You can use this option to provide a custom
|
|
25
|
+
* fetch instance.
|
|
26
|
+
*
|
|
27
|
+
* @default globalThis.fetch
|
|
28
|
+
*/
|
|
29
|
+
fetch?: typeof fetch;
|
|
30
|
+
/**
|
|
31
|
+
* Please don't use the Fetch client for Next.js applications. The `next`
|
|
32
|
+
* options won't have any effect.
|
|
33
|
+
*
|
|
34
|
+
* Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead.
|
|
35
|
+
*/
|
|
36
|
+
next?: never;
|
|
37
|
+
/**
|
|
38
|
+
* Return the response data parsed in a specified format. By default, `auto`
|
|
39
|
+
* will infer the appropriate method from the `Content-Type` response header.
|
|
40
|
+
* You can override this behavior with any of the {@link Body} methods.
|
|
41
|
+
* Select `stream` if you don't want to parse response data at all.
|
|
42
|
+
*
|
|
43
|
+
* @default 'auto'
|
|
44
|
+
*/
|
|
45
|
+
parseAs?:
|
|
46
|
+
| "arrayBuffer"
|
|
47
|
+
| "auto"
|
|
48
|
+
| "blob"
|
|
49
|
+
| "formData"
|
|
50
|
+
| "json"
|
|
51
|
+
| "stream"
|
|
52
|
+
| "text";
|
|
53
|
+
/**
|
|
54
|
+
* Should we return only data or multiple fields (data, error, response, etc.)?
|
|
55
|
+
*
|
|
56
|
+
* @default 'fields'
|
|
57
|
+
*/
|
|
58
|
+
responseStyle?: ResponseStyle;
|
|
59
|
+
/**
|
|
60
|
+
* Throw an error instead of returning it in the response?
|
|
61
|
+
*
|
|
62
|
+
* @default false
|
|
63
|
+
*/
|
|
64
|
+
throwOnError?: T["throwOnError"];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface RequestOptions<
|
|
68
|
+
TData = unknown,
|
|
69
|
+
TResponseStyle extends ResponseStyle = "fields",
|
|
70
|
+
ThrowOnError extends boolean = boolean,
|
|
71
|
+
Url extends string = string,
|
|
72
|
+
> extends Config<{
|
|
73
|
+
responseStyle: TResponseStyle;
|
|
74
|
+
throwOnError: ThrowOnError;
|
|
75
|
+
}>,
|
|
76
|
+
Pick<
|
|
77
|
+
ServerSentEventsOptions<TData>,
|
|
78
|
+
| "onSseError"
|
|
79
|
+
| "onSseEvent"
|
|
80
|
+
| "sseDefaultRetryDelay"
|
|
81
|
+
| "sseMaxRetryAttempts"
|
|
82
|
+
| "sseMaxRetryDelay"
|
|
83
|
+
> {
|
|
84
|
+
/**
|
|
85
|
+
* Any body that you want to add to your request.
|
|
86
|
+
*
|
|
87
|
+
* {@link https://developer.mozilla.org/docs/Web/API/fetch#body}
|
|
88
|
+
*/
|
|
89
|
+
body?: unknown;
|
|
90
|
+
path?: Record<string, unknown>;
|
|
91
|
+
query?: Record<string, unknown>;
|
|
92
|
+
/**
|
|
93
|
+
* Security mechanism(s) to use for the request.
|
|
94
|
+
*/
|
|
95
|
+
security?: ReadonlyArray<Auth>;
|
|
96
|
+
url: Url;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface ResolvedRequestOptions<
|
|
100
|
+
TResponseStyle extends ResponseStyle = "fields",
|
|
101
|
+
ThrowOnError extends boolean = boolean,
|
|
102
|
+
Url extends string = string,
|
|
103
|
+
> extends RequestOptions<unknown, TResponseStyle, ThrowOnError, Url> {
|
|
104
|
+
serializedBody?: string;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export type RequestResult<
|
|
108
|
+
TData = unknown,
|
|
109
|
+
TError = unknown,
|
|
110
|
+
ThrowOnError extends boolean = boolean,
|
|
111
|
+
TResponseStyle extends ResponseStyle = "fields",
|
|
112
|
+
> = ThrowOnError extends true
|
|
113
|
+
? Promise<
|
|
114
|
+
TResponseStyle extends "data"
|
|
115
|
+
? TData extends Record<string, unknown>
|
|
116
|
+
? TData[keyof TData]
|
|
117
|
+
: TData
|
|
118
|
+
: {
|
|
119
|
+
data: TData extends Record<string, unknown>
|
|
120
|
+
? TData[keyof TData]
|
|
121
|
+
: TData;
|
|
122
|
+
request: Request;
|
|
123
|
+
response: Response;
|
|
124
|
+
}
|
|
125
|
+
>
|
|
126
|
+
: Promise<
|
|
127
|
+
TResponseStyle extends "data"
|
|
128
|
+
?
|
|
129
|
+
| (TData extends Record<string, unknown>
|
|
130
|
+
? TData[keyof TData]
|
|
131
|
+
: TData)
|
|
132
|
+
| undefined
|
|
133
|
+
: (
|
|
134
|
+
| {
|
|
135
|
+
data: TData extends Record<string, unknown>
|
|
136
|
+
? TData[keyof TData]
|
|
137
|
+
: TData;
|
|
138
|
+
error: undefined;
|
|
139
|
+
}
|
|
140
|
+
| {
|
|
141
|
+
data: undefined;
|
|
142
|
+
error: TError extends Record<string, unknown>
|
|
143
|
+
? TError[keyof TError]
|
|
144
|
+
: TError;
|
|
145
|
+
}
|
|
146
|
+
) & {
|
|
147
|
+
request: Request;
|
|
148
|
+
response: Response;
|
|
149
|
+
}
|
|
150
|
+
>;
|
|
151
|
+
|
|
152
|
+
export interface ClientOptions {
|
|
153
|
+
baseUrl?: string;
|
|
154
|
+
responseStyle?: ResponseStyle;
|
|
155
|
+
throwOnError?: boolean;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
type MethodFn = <
|
|
159
|
+
TData = unknown,
|
|
160
|
+
TError = unknown,
|
|
161
|
+
ThrowOnError extends boolean = false,
|
|
162
|
+
TResponseStyle extends ResponseStyle = "fields",
|
|
163
|
+
>(
|
|
164
|
+
options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, "method">,
|
|
165
|
+
) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
166
|
+
|
|
167
|
+
type SseFn = <
|
|
168
|
+
TData = unknown,
|
|
169
|
+
TError = unknown,
|
|
170
|
+
ThrowOnError extends boolean = false,
|
|
171
|
+
TResponseStyle extends ResponseStyle = "fields",
|
|
172
|
+
>(
|
|
173
|
+
options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, "method">,
|
|
174
|
+
) => Promise<ServerSentEventsResult<TData, TError>>;
|
|
175
|
+
|
|
176
|
+
type RequestFn = <
|
|
177
|
+
TData = unknown,
|
|
178
|
+
TError = unknown,
|
|
179
|
+
ThrowOnError extends boolean = false,
|
|
180
|
+
TResponseStyle extends ResponseStyle = "fields",
|
|
181
|
+
>(
|
|
182
|
+
options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, "method"> &
|
|
183
|
+
Pick<
|
|
184
|
+
Required<RequestOptions<TData, TResponseStyle, ThrowOnError>>,
|
|
185
|
+
"method"
|
|
186
|
+
>,
|
|
187
|
+
) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
188
|
+
|
|
189
|
+
type BuildUrlFn = <
|
|
190
|
+
TData extends {
|
|
191
|
+
body?: unknown;
|
|
192
|
+
path?: Record<string, unknown>;
|
|
193
|
+
query?: Record<string, unknown>;
|
|
194
|
+
url: string;
|
|
195
|
+
},
|
|
196
|
+
>(
|
|
197
|
+
options: TData & Options<TData>,
|
|
198
|
+
) => string;
|
|
199
|
+
|
|
200
|
+
export type Client = CoreClient<
|
|
201
|
+
RequestFn,
|
|
202
|
+
Config,
|
|
203
|
+
MethodFn,
|
|
204
|
+
BuildUrlFn,
|
|
205
|
+
SseFn
|
|
206
|
+
> & {
|
|
207
|
+
interceptors: Middleware<Request, Response, unknown, ResolvedRequestOptions>;
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* The `createClientConfig()` function will be called on client initialization
|
|
212
|
+
* and the returned object will become the client's initial configuration.
|
|
213
|
+
*
|
|
214
|
+
* You may want to initialize your client this way instead of calling
|
|
215
|
+
* `setConfig()`. This is useful for example if you're using Next.js
|
|
216
|
+
* to ensure your client always has the correct values.
|
|
217
|
+
*/
|
|
218
|
+
export type CreateClientConfig<T extends ClientOptions = ClientOptions> = (
|
|
219
|
+
override?: Config<ClientOptions & T>,
|
|
220
|
+
) => Config<Required<ClientOptions> & T>;
|
|
221
|
+
|
|
222
|
+
export interface TDataShape {
|
|
223
|
+
body?: unknown;
|
|
224
|
+
headers?: unknown;
|
|
225
|
+
path?: unknown;
|
|
226
|
+
query?: unknown;
|
|
227
|
+
url: string;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
|
|
231
|
+
|
|
232
|
+
export type Options<
|
|
233
|
+
TData extends TDataShape = TDataShape,
|
|
234
|
+
ThrowOnError extends boolean = boolean,
|
|
235
|
+
TResponse = unknown,
|
|
236
|
+
TResponseStyle extends ResponseStyle = "fields",
|
|
237
|
+
> = OmitKeys<
|
|
238
|
+
RequestOptions<TResponse, TResponseStyle, ThrowOnError>,
|
|
239
|
+
"body" | "path" | "query" | "url"
|
|
240
|
+
> &
|
|
241
|
+
([TData] extends [never] ? unknown : Omit<TData, "url">);
|