Skip to content

Commit 274f862

Browse files
committed
refactor: enhance client and config interfaces with additional properties and serializers
1 parent 4f57d84 commit 274f862

File tree

1 file changed

+95
-95
lines changed
  • packages/openapi-ts-tests/main/test/plugins/@tanstack/__snapshots__/meta

1 file changed

+95
-95
lines changed

packages/openapi-ts-tests/main/test/plugins/@tanstack/__snapshots__/meta/types.ts

Lines changed: 95 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,122 @@
1-
import type { Auth } from '../core/auth';
1+
import type { Auth, AuthToken } from './auth';
22
import type {
3-
Client as CoreClient,
4-
Config as CoreConfig,
5-
} from '../core/types';
6-
import type { Middleware } from './utils';
3+
BodySerializer,
4+
QuerySerializer,
5+
QuerySerializerOptions,
6+
} from './bodySerializer';
77

8-
export type ResponseStyle = 'data' | 'fields';
8+
export interface Client<
9+
RequestFn = never,
10+
Config = unknown,
11+
MethodFn = never,
12+
BuildUrlFn = never,
13+
> {
14+
/**
15+
* Returns the final request URL.
16+
*/
17+
buildUrl: BuildUrlFn;
18+
connect: MethodFn;
19+
delete: MethodFn;
20+
get: MethodFn;
21+
getConfig: () => Config;
22+
head: MethodFn;
23+
options: MethodFn;
24+
patch: MethodFn;
25+
post: MethodFn;
26+
put: MethodFn;
27+
request: RequestFn;
28+
setConfig: (config: Config) => Config;
29+
trace: MethodFn;
30+
}
931

10-
export interface Config<T extends ClientOptions = ClientOptions>
11-
extends Omit<RequestInit, 'body' | 'headers' | 'method'>,
12-
CoreConfig {
32+
export interface Config {
1333
/**
14-
* Base URL for all requests made by this client.
34+
* Auth token or a function returning auth token. The resolved value will be
35+
* added to the request payload as defined by its `security` array.
1536
*/
16-
baseUrl?: T['baseUrl'];
37+
auth?: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken;
1738
/**
18-
* Fetch API implementation. You can use this option to provide a custom
19-
* fetch instance.
20-
*
21-
* @default globalThis.fetch
39+
* A function for serializing request body parameter. By default,
40+
* {@link JSON.stringify()} will be used.
2241
*/
23-
fetch?: (request: Request) => ReturnType<typeof fetch>;
42+
bodySerializer?: BodySerializer | null;
2443
/**
25-
* Please don't use the Fetch client for Next.js applications. The `next`
26-
* options won't have any effect.
44+
* An object containing any HTTP headers that you want to pre-populate your
45+
* `Headers` object with.
2746
*
28-
* Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead.
47+
* {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more}
2948
*/
30-
next?: never;
49+
headers?:
50+
| RequestInit['headers']
51+
| Record<
52+
string,
53+
| string
54+
| number
55+
| boolean
56+
| (string | number | boolean)[]
57+
| null
58+
| undefined
59+
| unknown
60+
>;
3161
/**
32-
* Return the response data parsed in a specified format. By default, `auto`
33-
* will infer the appropriate method from the `Content-Type` response header.
34-
* You can override this behavior with any of the {@link Body} methods.
35-
* Select `stream` if you don't want to parse response data at all.
62+
* The request method.
3663
*
37-
* @default 'auto'
64+
* {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more}
3865
*/
39-
parseAs?:
40-
| 'arrayBuffer'
41-
| 'auto'
42-
| 'blob'
43-
| 'formData'
44-
| 'json'
45-
| 'stream'
46-
| 'text';
66+
method?:
67+
| 'CONNECT'
68+
| 'DELETE'
69+
| 'GET'
70+
| 'HEAD'
71+
| 'OPTIONS'
72+
| 'PATCH'
73+
| 'POST'
74+
| 'PUT'
75+
| 'TRACE';
4776
/**
48-
* Should we return only data or multiple fields (data, error, response, etc.)?
77+
* A function for serializing request query parameters. By default, arrays
78+
* will be exploded in form style, objects will be exploded in deepObject
79+
* style, and reserved characters are percent-encoded.
80+
*
81+
* This method will have no effect if the native `paramsSerializer()` Axios
82+
* API function is used.
4983
*
50-
* @default 'fields'
84+
* {@link https://swagger.io/docs/specification/serialization/#query View examples}
5185
*/
52-
responseStyle?: ResponseStyle;
86+
querySerializer?: QuerySerializer | QuerySerializerOptions;
5387
/**
54-
* Throw an error instead of returning it in the response?
55-
*
56-
* @default false
88+
* A function validating request data. This is useful if you want to ensure
89+
* the request conforms to the desired shape, so it can be safely sent to
90+
* the server.
5791
*/
58-
throwOnError?: T['throwOnError'];
59-
}
60-
61-
export interface RequestOptions<
62-
TResponseStyle extends ResponseStyle = 'fields',
63-
ThrowOnError extends boolean = boolean,
64-
Url extends string = string,
65-
> extends Config<{
66-
responseStyle: TResponseStyle;
67-
throwOnError: ThrowOnError;
68-
}> {
92+
requestValidator?: (data: unknown) => Promise<unknown>;
6993
/**
70-
* Any body that you want to add to your request.
71-
*
72-
* {@link https://developer.mozilla.org/docs/Web/API/fetch#body}
94+
* A function transforming response data before it's returned. This is useful
95+
* for post-processing data, e.g. converting ISO strings into Date objects.
7396
*/
74-
body?: unknown;
75-
path?: Record<string, unknown>;
76-
query?: Record<string, unknown>;
97+
responseTransformer?: (data: unknown) => Promise<unknown>;
7798
/**
78-
* Security mechanism(s) to use for the request.
99+
* A function validating response data. This is useful if you want to ensure
100+
* the response conforms to the desired shape, so it can be safely passed to
101+
* the transformers and returned to the user.
79102
*/
80-
security?: ReadonlyArray<Auth>;
81-
url: Url;
103+
responseValidator?: (data: unknown) => Promise<unknown>;
82104
}
83105

84-
export type RequestResult<
85-
TData = unknown,
86-
TError = unknown,
87-
ThrowOnError extends boolean = boolean,
88-
TResponseStyle extends ResponseStyle = 'fields',
89-
> = ThrowOnError extends true
90-
? Promise<
91-
TResponseStyle extends 'data'
92-
? TData extends Record<string, unknown>
93-
? TData[keyof TData]
94-
: TData
95-
: {
96-
data: TData extends Record<string, unknown>
97-
? TData[keyof TData]
98-
: TData;
99-
request: Request;
100-
response: Response;
101-
}
102-
>
103-
: Promise<
104-
TResponseStyle extends 'data'
105-
?
106-
| (TData extends Record<string, unknown>
107-
? TData[keyof TData]
108-
: TData)
109-
| undefined
110-
: (
111-
| {
112-
data: TData extends Record<string, unknown>
113-
? TData[keyof TData]
114-
: TData;
115-
error: undefined;
116-
}
117-
| {
118-
data: undefined;
119-
error: TError extends Record<string, unknown>
106+
type IsExactlyNeverOrNeverUndefined<T> = [T] extends [never]
107+
? true
108+
: [T] extends [never | undefined]
109+
? [undefined] extends [T]
110+
? false
111+
: true
112+
: false;
113+
114+
export type OmitNever<T extends Record<string, unknown>> = {
115+
[K in keyof T as IsExactlyNeverOrNeverUndefined<T[K]> extends true
116+
? never
117+
: K]: T[K];
118+
};
119+
n>
120120
? TError[keyof TError]
121121
: TError;
122122
}

0 commit comments

Comments
 (0)