@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.
Files changed (56) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +381 -0
  3. package/bin/run.cmd +3 -0
  4. package/bin/run.js +18 -0
  5. package/dist/clients/angular/client.ts +237 -0
  6. package/dist/clients/angular/index.ts +23 -0
  7. package/dist/clients/angular/types.ts +231 -0
  8. package/dist/clients/angular/utils.ts +408 -0
  9. package/dist/clients/axios/client.ts +154 -0
  10. package/dist/clients/axios/index.ts +21 -0
  11. package/dist/clients/axios/types.ts +158 -0
  12. package/dist/clients/axios/utils.ts +206 -0
  13. package/dist/clients/core/auth.ts +39 -0
  14. package/dist/clients/core/bodySerializer.ts +82 -0
  15. package/dist/clients/core/params.ts +167 -0
  16. package/dist/clients/core/pathSerializer.ts +169 -0
  17. package/dist/clients/core/queryKeySerializer.ts +115 -0
  18. package/dist/clients/core/serverSentEvents.ts +241 -0
  19. package/dist/clients/core/types.ts +102 -0
  20. package/dist/clients/core/utils.ts +138 -0
  21. package/dist/clients/fetch/client.ts +286 -0
  22. package/dist/clients/fetch/index.ts +23 -0
  23. package/dist/clients/fetch/types.ts +211 -0
  24. package/dist/clients/fetch/utils.ts +314 -0
  25. package/dist/clients/ky/client.ts +318 -0
  26. package/dist/clients/ky/index.ts +24 -0
  27. package/dist/clients/ky/types.ts +243 -0
  28. package/dist/clients/ky/utils.ts +312 -0
  29. package/dist/clients/next/client.ts +253 -0
  30. package/dist/clients/next/index.ts +21 -0
  31. package/dist/clients/next/types.ts +162 -0
  32. package/dist/clients/next/utils.ts +413 -0
  33. package/dist/clients/nuxt/client.ts +213 -0
  34. package/dist/clients/nuxt/index.ts +22 -0
  35. package/dist/clients/nuxt/types.ts +189 -0
  36. package/dist/clients/nuxt/utils.ts +384 -0
  37. package/dist/clients/ofetch/client.ts +259 -0
  38. package/dist/clients/ofetch/index.ts +23 -0
  39. package/dist/clients/ofetch/types.ts +275 -0
  40. package/dist/clients/ofetch/utils.ts +504 -0
  41. package/dist/index.d.mts +8634 -0
  42. package/dist/index.d.mts.map +1 -0
  43. package/dist/index.mjs +4 -0
  44. package/dist/init-DlaW5Djq.mjs +13832 -0
  45. package/dist/init-DlaW5Djq.mjs.map +1 -0
  46. package/dist/internal.d.mts +33 -0
  47. package/dist/internal.d.mts.map +1 -0
  48. package/dist/internal.mjs +4 -0
  49. package/dist/run.d.mts +1 -0
  50. package/dist/run.mjs +60 -0
  51. package/dist/run.mjs.map +1 -0
  52. package/dist/src-BYA2YioO.mjs +225 -0
  53. package/dist/src-BYA2YioO.mjs.map +1 -0
  54. package/dist/types-Ba27ofyy.d.mts +157 -0
  55. package/dist/types-Ba27ofyy.d.mts.map +1 -0
  56. package/package.json +109 -0
@@ -0,0 +1,213 @@
1
+ import { useAsyncData, useFetch, useLazyAsyncData, useLazyFetch } from 'nuxt/app';
2
+ import { reactive, ref, watch } from 'vue';
3
+
4
+ import { createSseClient } from '../core/serverSentEvents';
5
+ import type { HttpMethod } from '../core/types';
6
+ import { getValidRequestBody } from '../core/utils';
7
+ import type { Client, Config, RequestOptions } from './types';
8
+ import {
9
+ buildUrl,
10
+ createConfig,
11
+ executeFetchFn,
12
+ mergeConfigs,
13
+ mergeHeaders,
14
+ mergeInterceptors,
15
+ serializeBody,
16
+ setAuthParams,
17
+ unwrapRefs,
18
+ } from './utils';
19
+
20
+ export const createClient = (config: Config = {}): Client => {
21
+ let _config = mergeConfigs(createConfig(), config);
22
+
23
+ const getConfig = (): Config => ({ ..._config });
24
+
25
+ const setConfig = (config: Config): Config => {
26
+ _config = mergeConfigs(_config, config);
27
+ return getConfig();
28
+ };
29
+
30
+ const beforeRequest = async (options: RequestOptions) => {
31
+ const opts = {
32
+ ..._config,
33
+ ...options,
34
+ $fetch: options.$fetch ?? _config.$fetch ?? $fetch,
35
+ headers: mergeHeaders(_config.headers, options.headers),
36
+ onRequest: mergeInterceptors(_config.onRequest, options.onRequest),
37
+ onResponse: mergeInterceptors(_config.onResponse, options.onResponse),
38
+ };
39
+
40
+ if (opts.security) {
41
+ await setAuthParams({
42
+ ...opts,
43
+ security: opts.security,
44
+ });
45
+ }
46
+
47
+ if (opts.requestValidator) {
48
+ await opts.requestValidator(opts);
49
+ }
50
+
51
+ const url = buildUrl(opts);
52
+
53
+ return { opts, url };
54
+ };
55
+
56
+ const request: Client['request'] = ({ asyncDataOptions, composable = '$fetch', ...options }) => {
57
+ const key = options.key;
58
+ const opts = {
59
+ ..._config,
60
+ ...options,
61
+ $fetch: options.$fetch ?? _config.$fetch ?? $fetch,
62
+ headers: mergeHeaders(_config.headers, options.headers),
63
+ onRequest: mergeInterceptors(_config.onRequest, options.onRequest),
64
+ onResponse: mergeInterceptors(_config.onResponse, options.onResponse),
65
+ };
66
+
67
+ const { requestValidator, responseTransformer, responseValidator, security } = opts;
68
+ if (requestValidator || security) {
69
+ // auth must happen in interceptors otherwise we'd need to require
70
+ // asyncContext enabled
71
+ // https://nuxt.com/docs/guide/going-further/experimental-features#asynccontext
72
+ opts.onRequest = [
73
+ async ({ options }) => {
74
+ if (security) {
75
+ await setAuthParams({
76
+ auth: opts.auth,
77
+ headers: options.headers,
78
+ query: options.query,
79
+ security,
80
+ });
81
+ }
82
+
83
+ if (requestValidator) {
84
+ await requestValidator({
85
+ ...options,
86
+ // @ts-expect-error
87
+ body: options.rawBody,
88
+ });
89
+ }
90
+ },
91
+ ...opts.onRequest,
92
+ ];
93
+ }
94
+
95
+ if (responseTransformer || responseValidator) {
96
+ opts.onResponse = [
97
+ ...opts.onResponse,
98
+ async ({ options, response }) => {
99
+ if (options.responseType && options.responseType !== 'json') {
100
+ return;
101
+ }
102
+
103
+ if (!response.ok) {
104
+ return;
105
+ }
106
+
107
+ if (responseValidator) {
108
+ await responseValidator(response._data);
109
+ }
110
+
111
+ if (responseTransformer) {
112
+ response._data = await responseTransformer(response._data);
113
+ }
114
+ },
115
+ ];
116
+ }
117
+
118
+ // remove Content-Type header if body is empty to avoid sending invalid requests
119
+ if (opts.body === undefined || opts.body === '') {
120
+ opts.headers.delete('Content-Type');
121
+ }
122
+
123
+ const fetchFn = opts.$fetch;
124
+
125
+ if (composable === '$fetch') {
126
+ return executeFetchFn(
127
+ // @ts-expect-error
128
+ opts,
129
+ fetchFn,
130
+ );
131
+ }
132
+
133
+ if (composable === 'useFetch' || composable === 'useLazyFetch') {
134
+ opts.rawBody = opts.body;
135
+ const bodyParams = reactive({
136
+ body: opts.body,
137
+ bodySerializer: opts.bodySerializer,
138
+ });
139
+ const body = ref(serializeBody(opts));
140
+ opts.body = body;
141
+ watch(bodyParams, (changed) => {
142
+ body.value = serializeBody(changed);
143
+ });
144
+ return composable === 'useLazyFetch'
145
+ ? useLazyFetch(() => buildUrl(opts), opts)
146
+ : useFetch(() => buildUrl(opts), opts);
147
+ }
148
+
149
+ const handler: any = () =>
150
+ executeFetchFn(
151
+ // @ts-expect-error
152
+ opts,
153
+ fetchFn,
154
+ );
155
+
156
+ if (composable === 'useAsyncData') {
157
+ return key
158
+ ? useAsyncData(key, handler, asyncDataOptions)
159
+ : useAsyncData(handler, asyncDataOptions);
160
+ }
161
+
162
+ if (composable === 'useLazyAsyncData') {
163
+ return key
164
+ ? useLazyAsyncData(key, handler, asyncDataOptions)
165
+ : useLazyAsyncData(handler, asyncDataOptions);
166
+ }
167
+
168
+ return undefined as any;
169
+ };
170
+
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
+ };
186
+
187
+ return {
188
+ buildUrl,
189
+ connect: makeMethodFn('CONNECT'),
190
+ delete: makeMethodFn('DELETE'),
191
+ get: makeMethodFn('GET'),
192
+ getConfig,
193
+ head: makeMethodFn('HEAD'),
194
+ options: makeMethodFn('OPTIONS'),
195
+ patch: makeMethodFn('PATCH'),
196
+ post: makeMethodFn('POST'),
197
+ put: makeMethodFn('PUT'),
198
+ request,
199
+ setConfig,
200
+ sse: {
201
+ connect: makeSseFn('CONNECT'),
202
+ delete: makeSseFn('DELETE'),
203
+ get: makeSseFn('GET'),
204
+ head: makeSseFn('HEAD'),
205
+ options: makeSseFn('OPTIONS'),
206
+ patch: makeSseFn('PATCH'),
207
+ post: makeSseFn('POST'),
208
+ put: makeSseFn('PUT'),
209
+ trace: makeSseFn('TRACE'),
210
+ },
211
+ trace: makeMethodFn('TRACE'),
212
+ } as Client;
213
+ };
@@ -0,0 +1,22 @@
1
+ export type { Auth } from '../core/auth';
2
+ export type { QuerySerializerOptions } from '../core/bodySerializer';
3
+ export {
4
+ formDataBodySerializer,
5
+ jsonBodySerializer,
6
+ urlSearchParamsBodySerializer,
7
+ } from '../core/bodySerializer';
8
+ export { buildClientParams } from '../core/params';
9
+ export { serializeQueryKeyValue } from '../core/queryKeySerializer';
10
+ export { createClient } from './client';
11
+ export type {
12
+ Client,
13
+ ClientOptions,
14
+ Composable,
15
+ Config,
16
+ CreateClientConfig,
17
+ Options,
18
+ RequestOptions,
19
+ RequestResult,
20
+ TDataShape,
21
+ } from './types';
22
+ export { createConfig } from './utils';
@@ -0,0 +1,189 @@
1
+ import type {
2
+ AsyncDataOptions,
3
+ useAsyncData,
4
+ useFetch,
5
+ UseFetchOptions,
6
+ useLazyAsyncData,
7
+ useLazyFetch,
8
+ } from 'nuxt/app';
9
+ import type { Ref } from 'vue';
10
+
11
+ import type { Auth } from '../core/auth';
12
+ import type { QuerySerializerOptions } from '../core/bodySerializer';
13
+ import type {
14
+ ServerSentEventsOptions,
15
+ ServerSentEventsResult,
16
+ } from '../core/serverSentEvents';
17
+ import type { Client as CoreClient, Config as CoreConfig } from '../core/types';
18
+
19
+ export type ArraySeparatorStyle = ArrayStyle | MatrixStyle;
20
+ type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited';
21
+ type MatrixStyle = 'label' | 'matrix' | 'simple';
22
+ export type ObjectSeparatorStyle = ObjectStyle | MatrixStyle;
23
+ type ObjectStyle = 'form' | 'deepObject';
24
+
25
+ export type QuerySerializer = (query: Parameters<Client['buildUrl']>[0]['query']) => string;
26
+
27
+ type WithRefs<TData> = {
28
+ [K in keyof TData]: NonNullable<TData[K]> extends object
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>;
31
+ };
32
+
33
+ // copied from Nuxt
34
+ export type KeysOf<T> = Array<T extends T ? (keyof T extends string ? keyof T : never) : never>;
35
+
36
+ export interface Config<T extends ClientOptions = ClientOptions>
37
+ extends
38
+ Omit<FetchOptions<unknown>, 'baseURL' | 'body' | 'headers' | 'method' | 'query'>,
39
+ WithRefs<Pick<FetchOptions<unknown>, 'query'>>,
40
+ Omit<CoreConfig, 'querySerializer'> {
41
+ /**
42
+ * Base URL for all requests made by this client.
43
+ */
44
+ baseURL?: T['baseURL'];
45
+ /**
46
+ * A function for serializing request query parameters. By default, arrays
47
+ * will be exploded in form style, objects will be exploded in deepObject
48
+ * style, and reserved characters are percent-encoded.
49
+ *
50
+ * {@link https://swagger.io/docs/specification/serialization/#query View examples}
51
+ */
52
+ querySerializer?: QuerySerializer | QuerySerializerOptions;
53
+ }
54
+
55
+ export interface RequestOptions<
56
+ TComposable extends Composable = '$fetch',
57
+ ResT = unknown,
58
+ DefaultT = undefined,
59
+ Url extends string = string,
60
+ >
61
+ extends
62
+ Config,
63
+ WithRefs<{
64
+ path?: FetchOptions<unknown>['query'];
65
+ query?: FetchOptions<unknown>['query'];
66
+ }>,
67
+ Pick<
68
+ ServerSentEventsOptions<ResT>,
69
+ | 'onSseError'
70
+ | 'onSseEvent'
71
+ | 'sseDefaultRetryDelay'
72
+ | 'sseMaxRetryAttempts'
73
+ | 'sseMaxRetryDelay'
74
+ > {
75
+ asyncDataOptions?: AsyncDataOptions<ResT, ResT, KeysOf<ResT>, DefaultT>;
76
+ /**
77
+ * Any body that you want to add to your request.
78
+ *
79
+ * {@link https://developer.mozilla.org/docs/Web/API/fetch#body}
80
+ */
81
+ body?: NonNullable<unknown> | Ref<NonNullable<unknown>> | null;
82
+ composable?: TComposable;
83
+ key?: string;
84
+ rawBody?: NonNullable<unknown> | Ref<NonNullable<unknown>> | null;
85
+ /**
86
+ * Security mechanism(s) to use for the request.
87
+ */
88
+ security?: ReadonlyArray<Auth>;
89
+ url: Url;
90
+ }
91
+
92
+ export type RequestResult<
93
+ TComposable extends Composable,
94
+ ResT,
95
+ TError,
96
+ > = TComposable extends '$fetch'
97
+ ? ReturnType<typeof $fetch<ResT>>
98
+ : TComposable extends 'useAsyncData'
99
+ ? ReturnType<typeof useAsyncData<ResT | null, TError>>
100
+ : TComposable extends 'useFetch'
101
+ ? ReturnType<typeof useFetch<ResT | null, TError>>
102
+ : TComposable extends 'useLazyAsyncData'
103
+ ? ReturnType<typeof useLazyAsyncData<ResT | null, TError>>
104
+ : TComposable extends 'useLazyFetch'
105
+ ? ReturnType<typeof useLazyFetch<ResT | null, TError>>
106
+ : never;
107
+
108
+ export interface ClientOptions {
109
+ baseURL?: string;
110
+ }
111
+
112
+ type MethodFn = <
113
+ TComposable extends Composable = '$fetch',
114
+ ResT = unknown,
115
+ TError = unknown,
116
+ DefaultT = undefined,
117
+ >(
118
+ options: Omit<RequestOptions<TComposable, ResT, DefaultT>, 'method'>,
119
+ ) => RequestResult<TComposable, ResT, TError>;
120
+
121
+ type SseFn = <
122
+ TComposable extends Composable = '$fetch',
123
+ ResT = unknown,
124
+ TError = unknown,
125
+ DefaultT = undefined,
126
+ >(
127
+ options: Omit<RequestOptions<TComposable, ResT, DefaultT>, 'method'>,
128
+ ) => Promise<ServerSentEventsResult<RequestResult<TComposable, ResT, TError>>>;
129
+
130
+ type RequestFn = <
131
+ TComposable extends Composable = '$fetch',
132
+ ResT = unknown,
133
+ TError = unknown,
134
+ DefaultT = undefined,
135
+ >(
136
+ options: Omit<RequestOptions<TComposable, ResT, DefaultT>, 'method'> &
137
+ Pick<Required<RequestOptions<TComposable, ResT, DefaultT>>, 'method'>,
138
+ ) => RequestResult<TComposable, ResT, TError>;
139
+
140
+ /**
141
+ * The `createClientConfig()` function will be called on client initialization
142
+ * and the returned object will become the client's initial configuration.
143
+ *
144
+ * You may want to initialize your client this way instead of calling
145
+ * `setConfig()`. This is useful for example if you're using Next.js
146
+ * to ensure your client always has the correct values.
147
+ */
148
+ export type CreateClientConfig<T extends ClientOptions = ClientOptions> = (
149
+ override?: Config<ClientOptions & T>,
150
+ ) => Config<Required<ClientOptions> & T>;
151
+
152
+ export interface TDataShape {
153
+ body?: unknown;
154
+ headers?: unknown;
155
+ path?: FetchOptions<unknown>['query'];
156
+ query?: FetchOptions<unknown>['query'];
157
+ url: string;
158
+ }
159
+
160
+ export type BuildUrlOptions<
161
+ TData extends Omit<TDataShape, 'headers'> = Omit<TDataShape, 'headers'>,
162
+ > = Pick<WithRefs<TData>, 'path' | 'query'> &
163
+ Pick<TData, 'url'> &
164
+ Pick<Options<'$fetch', TData>, 'baseURL' | 'querySerializer'>;
165
+
166
+ type BuildUrlFn = <TData extends Omit<TDataShape, 'headers'>>(
167
+ options: BuildUrlOptions<TData>,
168
+ ) => string;
169
+
170
+ export type Client = CoreClient<RequestFn, Config, MethodFn, BuildUrlFn, SseFn>;
171
+
172
+ type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
173
+
174
+ export type Options<
175
+ TComposable extends Composable = '$fetch',
176
+ TData extends TDataShape = TDataShape,
177
+ ResT = unknown,
178
+ DefaultT = undefined,
179
+ > = OmitKeys<RequestOptions<TComposable, ResT, DefaultT>, 'body' | 'path' | 'query' | 'url'> &
180
+ ([TData] extends [never] ? unknown : WithRefs<Omit<TData, 'url'>>);
181
+
182
+ type FetchOptions<TData> = Omit<UseFetchOptions<TData, TData>, keyof AsyncDataOptions<TData>>;
183
+
184
+ export type Composable =
185
+ | '$fetch'
186
+ | 'useAsyncData'
187
+ | 'useFetch'
188
+ | 'useLazyAsyncData'
189
+ | 'useLazyFetch';