@hey-api/openapi-ts 0.81.0 → 0.82.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.
@@ -117,7 +117,7 @@ export interface ClientOptions {
117
117
  throwOnError?: boolean;
118
118
  }
119
119
 
120
- type MethodFnBase = <
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 MethodFnServerSentEvents = <
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<RequestFn, Config, MethodFn, BuildUrlFn> & {
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,34 +181,47 @@ export const createClient = (config: Config = {}): Client => {
180
181
  return undefined as any;
181
182
  };
182
183
 
183
- const makeMethod = (method: Required<Config>['method']) => {
184
- const fn = (options: RequestOptions) => request({ ...options, method });
185
- fn.sse = async (options: RequestOptions) => {
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),
189
193
  body: opts.body as BodyInit | null | undefined,
190
194
  method,
195
+ onRequest: undefined,
191
196
  signal: unwrapRefs(opts.signal) as AbortSignal,
192
197
  url,
193
198
  });
194
199
  };
195
- return fn;
196
- };
197
200
 
198
201
  return {
199
202
  buildUrl,
200
- connect: makeMethod('CONNECT'),
201
- delete: makeMethod('DELETE'),
202
- get: makeMethod('GET'),
203
+ connect: makeMethodFn('CONNECT'),
204
+ delete: makeMethodFn('DELETE'),
205
+ get: makeMethodFn('GET'),
203
206
  getConfig,
204
- head: makeMethod('HEAD'),
205
- options: makeMethod('OPTIONS'),
206
- patch: makeMethod('PATCH'),
207
- post: makeMethod('POST'),
208
- put: makeMethod('PUT'),
207
+ head: makeMethodFn('HEAD'),
208
+ options: makeMethodFn('OPTIONS'),
209
+ patch: makeMethodFn('PATCH'),
210
+ post: makeMethodFn('POST'),
211
+ put: makeMethodFn('PUT'),
209
212
  request,
210
213
  setConfig,
211
- trace: makeMethod('TRACE'),
214
+ sse: {
215
+ connect: makeSseFn('CONNECT'),
216
+ delete: makeSseFn('DELETE'),
217
+ get: makeSseFn('GET'),
218
+ head: makeSseFn('HEAD'),
219
+ options: makeSseFn('OPTIONS'),
220
+ patch: makeSseFn('PATCH'),
221
+ post: makeSseFn('POST'),
222
+ put: makeSseFn('PUT'),
223
+ trace: makeSseFn('TRACE'),
224
+ },
225
+ trace: makeMethodFn('TRACE'),
212
226
  } as Client;
213
227
  };
@@ -116,7 +116,7 @@ export interface ClientOptions {
116
116
  baseURL?: string;
117
117
  }
118
118
 
119
- type MethodFnBase = <
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 MethodFnServerSentEvents = <
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