@hey-api/openapi-ts 0.0.0-next-20260205083026
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/LICENSE.md +21 -0
- package/README.md +381 -0
- package/bin/run.cmd +3 -0
- package/bin/run.js +18 -0
- package/dist/clients/angular/client.ts +237 -0
- package/dist/clients/angular/index.ts +23 -0
- package/dist/clients/angular/types.ts +231 -0
- package/dist/clients/angular/utils.ts +408 -0
- package/dist/clients/axios/client.ts +154 -0
- package/dist/clients/axios/index.ts +21 -0
- package/dist/clients/axios/types.ts +158 -0
- package/dist/clients/axios/utils.ts +206 -0
- package/dist/clients/core/auth.ts +39 -0
- package/dist/clients/core/bodySerializer.ts +82 -0
- package/dist/clients/core/params.ts +167 -0
- package/dist/clients/core/pathSerializer.ts +169 -0
- package/dist/clients/core/queryKeySerializer.ts +115 -0
- package/dist/clients/core/serverSentEvents.ts +241 -0
- package/dist/clients/core/types.ts +102 -0
- package/dist/clients/core/utils.ts +138 -0
- package/dist/clients/fetch/client.ts +286 -0
- package/dist/clients/fetch/index.ts +23 -0
- package/dist/clients/fetch/types.ts +211 -0
- package/dist/clients/fetch/utils.ts +314 -0
- package/dist/clients/ky/client.ts +318 -0
- package/dist/clients/ky/index.ts +24 -0
- package/dist/clients/ky/types.ts +243 -0
- package/dist/clients/ky/utils.ts +312 -0
- package/dist/clients/next/client.ts +253 -0
- package/dist/clients/next/index.ts +21 -0
- package/dist/clients/next/types.ts +162 -0
- package/dist/clients/next/utils.ts +413 -0
- package/dist/clients/nuxt/client.ts +213 -0
- package/dist/clients/nuxt/index.ts +22 -0
- package/dist/clients/nuxt/types.ts +189 -0
- package/dist/clients/nuxt/utils.ts +384 -0
- package/dist/clients/ofetch/client.ts +259 -0
- package/dist/clients/ofetch/index.ts +23 -0
- package/dist/clients/ofetch/types.ts +275 -0
- package/dist/clients/ofetch/utils.ts +504 -0
- package/dist/index.d.mts +8634 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +4 -0
- package/dist/init-DlaW5Djq.mjs +13832 -0
- package/dist/init-DlaW5Djq.mjs.map +1 -0
- package/dist/internal.d.mts +33 -0
- package/dist/internal.d.mts.map +1 -0
- package/dist/internal.mjs +4 -0
- package/dist/run.d.mts +1 -0
- package/dist/run.mjs +60 -0
- package/dist/run.mjs.map +1 -0
- package/dist/src-BYA2YioO.mjs +225 -0
- package/dist/src-BYA2YioO.mjs.map +1 -0
- package/dist/types-Ba27ofyy.d.mts +157 -0
- package/dist/types-Ba27ofyy.d.mts.map +1 -0
- package/package.json +109 -0
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import type { FetchOptions as OfetchOptions, ResponseType as OfetchResponseType } from 'ofetch';
|
|
2
|
+
import type { ofetch } from 'ofetch';
|
|
3
|
+
|
|
4
|
+
import type { Auth } from '../core/auth';
|
|
5
|
+
import type {
|
|
6
|
+
ServerSentEventsOptions,
|
|
7
|
+
ServerSentEventsResult,
|
|
8
|
+
} from '../core/serverSentEvents';
|
|
9
|
+
import type { Client as CoreClient, Config as CoreConfig } from '../core/types';
|
|
10
|
+
import type { Middleware } from './utils';
|
|
11
|
+
|
|
12
|
+
export type ResponseStyle = 'data' | 'fields';
|
|
13
|
+
|
|
14
|
+
export interface Config<T extends ClientOptions = ClientOptions>
|
|
15
|
+
extends Omit<RequestInit, 'body' | 'headers' | 'method'>, CoreConfig {
|
|
16
|
+
/**
|
|
17
|
+
* HTTP(S) agent configuration (Node.js only). Passed through to ofetch.
|
|
18
|
+
*/
|
|
19
|
+
agent?: OfetchOptions['agent'];
|
|
20
|
+
/**
|
|
21
|
+
* Base URL for all requests made by this client.
|
|
22
|
+
*/
|
|
23
|
+
baseUrl?: T['baseUrl'];
|
|
24
|
+
/**
|
|
25
|
+
* Node-only proxy/agent options.
|
|
26
|
+
*/
|
|
27
|
+
dispatcher?: OfetchOptions['dispatcher'];
|
|
28
|
+
/**
|
|
29
|
+
* Fetch API implementation. Used for SSE streaming. You can use this option
|
|
30
|
+
* to provide a custom fetch instance.
|
|
31
|
+
*
|
|
32
|
+
* @default globalThis.fetch
|
|
33
|
+
*/
|
|
34
|
+
fetch?: typeof fetch;
|
|
35
|
+
/**
|
|
36
|
+
* Controls the native ofetch behaviour that throws `FetchError` when
|
|
37
|
+
* `response.ok === false`. We default to suppressing it to match the fetch
|
|
38
|
+
* client semantics and let `throwOnError` drive the outcome.
|
|
39
|
+
*/
|
|
40
|
+
ignoreResponseError?: OfetchOptions['ignoreResponseError'];
|
|
41
|
+
// No custom fetch option: provide custom instance via `ofetch` instead
|
|
42
|
+
/**
|
|
43
|
+
* Please don't use the Fetch client for Next.js applications. The `next`
|
|
44
|
+
* options won't have any effect.
|
|
45
|
+
*
|
|
46
|
+
* Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead.
|
|
47
|
+
*/
|
|
48
|
+
next?: never;
|
|
49
|
+
/**
|
|
50
|
+
* Custom ofetch instance created via `ofetch.create()`. If provided, it will
|
|
51
|
+
* be used for requests instead of the default `ofetch` export.
|
|
52
|
+
*/
|
|
53
|
+
ofetch?: typeof ofetch;
|
|
54
|
+
/**
|
|
55
|
+
* ofetch hook called before a request is sent.
|
|
56
|
+
*/
|
|
57
|
+
onRequest?: OfetchOptions['onRequest'];
|
|
58
|
+
/**
|
|
59
|
+
* ofetch hook called when a request fails before receiving a response
|
|
60
|
+
* (e.g., network errors or aborted requests).
|
|
61
|
+
*/
|
|
62
|
+
onRequestError?: OfetchOptions['onRequestError'];
|
|
63
|
+
/**
|
|
64
|
+
* ofetch hook called after a successful response is received and parsed.
|
|
65
|
+
*/
|
|
66
|
+
onResponse?: OfetchOptions['onResponse'];
|
|
67
|
+
/**
|
|
68
|
+
* ofetch hook called when the response indicates an error (non-ok status)
|
|
69
|
+
* or when response parsing fails.
|
|
70
|
+
*/
|
|
71
|
+
onResponseError?: OfetchOptions['onResponseError'];
|
|
72
|
+
/**
|
|
73
|
+
* Return the response data parsed in a specified format. By default, `auto`
|
|
74
|
+
* will infer the appropriate method from the `Content-Type` response header.
|
|
75
|
+
* You can override this behavior with any of the {@link Body} methods.
|
|
76
|
+
* Select `stream` if you don't want to parse response data at all.
|
|
77
|
+
*
|
|
78
|
+
* @default 'auto'
|
|
79
|
+
*/
|
|
80
|
+
parseAs?: 'arrayBuffer' | 'auto' | 'blob' | 'formData' | 'json' | 'stream' | 'text';
|
|
81
|
+
/** Custom response parser (ofetch). */
|
|
82
|
+
parseResponse?: OfetchOptions['parseResponse'];
|
|
83
|
+
/**
|
|
84
|
+
* Should we return only data or multiple fields (data, error, response, etc.)?
|
|
85
|
+
*
|
|
86
|
+
* @default 'fields'
|
|
87
|
+
*/
|
|
88
|
+
responseStyle?: ResponseStyle;
|
|
89
|
+
/**
|
|
90
|
+
* ofetch responseType override. If provided, it will be passed directly to
|
|
91
|
+
* ofetch and take precedence over `parseAs`.
|
|
92
|
+
*/
|
|
93
|
+
responseType?: OfetchResponseType;
|
|
94
|
+
/**
|
|
95
|
+
* Automatically retry failed requests.
|
|
96
|
+
*/
|
|
97
|
+
retry?: OfetchOptions['retry'];
|
|
98
|
+
/**
|
|
99
|
+
* Delay (in ms) between retry attempts.
|
|
100
|
+
*/
|
|
101
|
+
retryDelay?: OfetchOptions['retryDelay'];
|
|
102
|
+
/**
|
|
103
|
+
* HTTP status codes that should trigger a retry.
|
|
104
|
+
*/
|
|
105
|
+
retryStatusCodes?: OfetchOptions['retryStatusCodes'];
|
|
106
|
+
/**
|
|
107
|
+
* Throw an error instead of returning it in the response?
|
|
108
|
+
*
|
|
109
|
+
* @default false
|
|
110
|
+
*/
|
|
111
|
+
throwOnError?: T['throwOnError'];
|
|
112
|
+
/**
|
|
113
|
+
* Abort the request after the given milliseconds.
|
|
114
|
+
*/
|
|
115
|
+
timeout?: number;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export interface RequestOptions<
|
|
119
|
+
TData = unknown,
|
|
120
|
+
TResponseStyle extends ResponseStyle = 'fields',
|
|
121
|
+
ThrowOnError extends boolean = boolean,
|
|
122
|
+
Url extends string = string,
|
|
123
|
+
>
|
|
124
|
+
extends
|
|
125
|
+
Config<{
|
|
126
|
+
responseStyle: TResponseStyle;
|
|
127
|
+
throwOnError: ThrowOnError;
|
|
128
|
+
}>,
|
|
129
|
+
Pick<
|
|
130
|
+
ServerSentEventsOptions<TData>,
|
|
131
|
+
| 'onSseError'
|
|
132
|
+
| 'onSseEvent'
|
|
133
|
+
| 'sseDefaultRetryDelay'
|
|
134
|
+
| 'sseMaxRetryAttempts'
|
|
135
|
+
| 'sseMaxRetryDelay'
|
|
136
|
+
> {
|
|
137
|
+
/**
|
|
138
|
+
* Any body that you want to add to your request.
|
|
139
|
+
*
|
|
140
|
+
* {@link https://developer.mozilla.org/docs/Web/API/fetch#body}
|
|
141
|
+
*/
|
|
142
|
+
body?: unknown;
|
|
143
|
+
path?: Record<string, unknown>;
|
|
144
|
+
query?: Record<string, unknown>;
|
|
145
|
+
/**
|
|
146
|
+
* Security mechanism(s) to use for the request.
|
|
147
|
+
*/
|
|
148
|
+
security?: ReadonlyArray<Auth>;
|
|
149
|
+
url: Url;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export interface ResolvedRequestOptions<
|
|
153
|
+
TResponseStyle extends ResponseStyle = 'fields',
|
|
154
|
+
ThrowOnError extends boolean = boolean,
|
|
155
|
+
Url extends string = string,
|
|
156
|
+
> extends RequestOptions<unknown, TResponseStyle, ThrowOnError, Url> {
|
|
157
|
+
serializedBody?: string;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export type RequestResult<
|
|
161
|
+
TData = unknown,
|
|
162
|
+
TError = unknown,
|
|
163
|
+
ThrowOnError extends boolean = boolean,
|
|
164
|
+
TResponseStyle extends ResponseStyle = 'fields',
|
|
165
|
+
> = ThrowOnError extends true
|
|
166
|
+
? Promise<
|
|
167
|
+
TResponseStyle extends 'data'
|
|
168
|
+
? TData extends Record<string, unknown>
|
|
169
|
+
? TData[keyof TData]
|
|
170
|
+
: TData
|
|
171
|
+
: {
|
|
172
|
+
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
|
|
173
|
+
request: Request;
|
|
174
|
+
response: Response;
|
|
175
|
+
}
|
|
176
|
+
>
|
|
177
|
+
: Promise<
|
|
178
|
+
TResponseStyle extends 'data'
|
|
179
|
+
? (TData extends Record<string, unknown> ? TData[keyof TData] : TData) | undefined
|
|
180
|
+
: (
|
|
181
|
+
| {
|
|
182
|
+
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
|
|
183
|
+
error: undefined;
|
|
184
|
+
}
|
|
185
|
+
| {
|
|
186
|
+
data: undefined;
|
|
187
|
+
error: TError extends Record<string, unknown> ? TError[keyof TError] : TError;
|
|
188
|
+
}
|
|
189
|
+
) & {
|
|
190
|
+
request: Request;
|
|
191
|
+
response: Response;
|
|
192
|
+
}
|
|
193
|
+
>;
|
|
194
|
+
|
|
195
|
+
export interface ClientOptions {
|
|
196
|
+
baseUrl?: string;
|
|
197
|
+
responseStyle?: ResponseStyle;
|
|
198
|
+
throwOnError?: boolean;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
type MethodFn = <
|
|
202
|
+
TData = unknown,
|
|
203
|
+
TError = unknown,
|
|
204
|
+
ThrowOnError extends boolean = false,
|
|
205
|
+
TResponseStyle extends ResponseStyle = 'fields',
|
|
206
|
+
>(
|
|
207
|
+
options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'>,
|
|
208
|
+
) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
209
|
+
|
|
210
|
+
type SseFn = <
|
|
211
|
+
TData = unknown,
|
|
212
|
+
TError = unknown,
|
|
213
|
+
ThrowOnError extends boolean = false,
|
|
214
|
+
TResponseStyle extends ResponseStyle = 'fields',
|
|
215
|
+
>(
|
|
216
|
+
options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'>,
|
|
217
|
+
) => Promise<ServerSentEventsResult<TData, TError>>;
|
|
218
|
+
|
|
219
|
+
type RequestFn = <
|
|
220
|
+
TData = unknown,
|
|
221
|
+
TError = unknown,
|
|
222
|
+
ThrowOnError extends boolean = false,
|
|
223
|
+
TResponseStyle extends ResponseStyle = 'fields',
|
|
224
|
+
>(
|
|
225
|
+
options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'> &
|
|
226
|
+
Pick<Required<RequestOptions<TData, TResponseStyle, ThrowOnError>>, 'method'>,
|
|
227
|
+
) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
228
|
+
|
|
229
|
+
type BuildUrlFn = <
|
|
230
|
+
TData extends {
|
|
231
|
+
body?: unknown;
|
|
232
|
+
path?: Record<string, unknown>;
|
|
233
|
+
query?: Record<string, unknown>;
|
|
234
|
+
url: string;
|
|
235
|
+
},
|
|
236
|
+
>(
|
|
237
|
+
options: TData & Options<TData>,
|
|
238
|
+
) => string;
|
|
239
|
+
|
|
240
|
+
export type Client = CoreClient<RequestFn, Config, MethodFn, BuildUrlFn, SseFn> & {
|
|
241
|
+
interceptors: Middleware<Request, Response, unknown, ResolvedRequestOptions>;
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* The `createClientConfig()` function will be called on client initialization
|
|
246
|
+
* and the returned object will become the client's initial configuration.
|
|
247
|
+
*
|
|
248
|
+
* You may want to initialize your client this way instead of calling
|
|
249
|
+
* `setConfig()`. This is useful for example if you're using Next.js
|
|
250
|
+
* to ensure your client always has the correct values.
|
|
251
|
+
*/
|
|
252
|
+
export type CreateClientConfig<T extends ClientOptions = ClientOptions> = (
|
|
253
|
+
override?: Config<ClientOptions & T>,
|
|
254
|
+
) => Config<Required<ClientOptions> & T>;
|
|
255
|
+
|
|
256
|
+
export interface TDataShape {
|
|
257
|
+
body?: unknown;
|
|
258
|
+
headers?: unknown;
|
|
259
|
+
path?: unknown;
|
|
260
|
+
query?: unknown;
|
|
261
|
+
url: string;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
|
|
265
|
+
|
|
266
|
+
export type Options<
|
|
267
|
+
TData extends TDataShape = TDataShape,
|
|
268
|
+
ThrowOnError extends boolean = boolean,
|
|
269
|
+
TResponse = unknown,
|
|
270
|
+
TResponseStyle extends ResponseStyle = 'fields',
|
|
271
|
+
> = OmitKeys<
|
|
272
|
+
RequestOptions<TResponse, TResponseStyle, ThrowOnError>,
|
|
273
|
+
'body' | 'path' | 'query' | 'url'
|
|
274
|
+
> &
|
|
275
|
+
([TData] extends [never] ? unknown : Omit<TData, 'url'>);
|