Skip to content

Commit b015044

Browse files
committed
chore: biome lint error fix
1 parent 4962aaa commit b015044

File tree

2 files changed

+73
-119
lines changed

2 files changed

+73
-119
lines changed

packages/openapi-react-query/src/index.ts

Lines changed: 71 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,21 @@ export type QueryKey<
3737
Init = MaybeOptionalInit<Paths[Path], Method>,
3838
> = Init extends undefined ? readonly [Method, Path] : readonly [Method, Path, Init];
3939

40-
export type MutationKey<
41-
Method extends HttpMethod,
42-
Path,
43-
> = readonly [Method, Path];
40+
export type MutationKey<Method extends HttpMethod, Path> = readonly [Method, Path];
4441

45-
export type QueryOptionsFunction<
46-
Paths extends Record<string, Record<HttpMethod, {}>>,
47-
Media extends MediaType,
48-
> = <
42+
export type QueryOptionsFunction<Paths extends Record<string, Record<HttpMethod, {}>>, Media extends MediaType> = <
4943
Method extends HttpMethod,
5044
Path extends PathsWithMethod<Paths, Method>,
5145
Init extends MaybeOptionalInit<Paths[Path], Method>,
5246
Response extends Required<FetchResponse<Paths[Path][Method], Init, Media>>, // note: Required is used to avoid repeating NonNullable in UseQuery types
5347
Options extends Omit<
5448
UseQueryOptions<
55-
Response['data'],
56-
Response['error'],
57-
InferSelectReturnType<Response['data'], Options['select']>,
49+
Response["data"],
50+
Response["error"],
51+
InferSelectReturnType<Response["data"], Options["select"]>,
5852
QueryKey<Paths, Method, Path>
5953
>,
60-
'queryKey' | 'queryFn'
54+
"queryKey" | "queryFn"
6155
>,
6256
>(
6357
method: Method,
@@ -68,50 +62,38 @@ export type QueryOptionsFunction<
6862
) => NoInfer<
6963
Omit<
7064
UseQueryOptions<
71-
Response['data'],
72-
Response['error'],
73-
InferSelectReturnType<Response['data'], Options['select']>,
65+
Response["data"],
66+
Response["error"],
67+
InferSelectReturnType<Response["data"], Options["select"]>,
7468
QueryKey<Paths, Method, Path>
7569
>,
76-
'queryFn'
70+
"queryFn"
7771
> & {
7872
queryFn: Exclude<
7973
UseQueryOptions<
80-
Response['data'],
81-
Response['error'],
82-
InferSelectReturnType<Response['data'], Options['select']>,
74+
Response["data"],
75+
Response["error"],
76+
InferSelectReturnType<Response["data"], Options["select"]>,
8377
QueryKey<Paths, Method, Path>
84-
>['queryFn'],
78+
>["queryFn"],
8579
SkipToken | undefined
8680
>;
8781
}
8882
>;
8983

90-
export type MutationOptionsFunction<
91-
Paths extends Record<string, Record<HttpMethod, {}>>,
92-
Media extends MediaType,
93-
> = <
84+
export type MutationOptionsFunction<Paths extends Record<string, Record<HttpMethod, {}>>, Media extends MediaType> = <
9485
Method extends HttpMethod,
9586
Path extends PathsWithMethod<Paths, Method>,
9687
Init extends MaybeOptionalInit<Paths[Path], Method>,
9788
Response extends Required<FetchResponse<Paths[Path][Method], Init, Media>>,
98-
Options extends Omit<
99-
UseMutationOptions<Response['data'], Response['error'], Init>,
100-
'mutationKey' | 'mutationFn'
101-
>,
89+
Options extends Omit<UseMutationOptions<Response["data"], Response["error"], Init>, "mutationKey" | "mutationFn">,
10290
>(
10391
method: Method,
10492
path: Path,
105-
options?: Options
93+
options?: Options,
10694
) => NoInfer<
107-
Omit<
108-
UseMutationOptions<Response['data'], Response['error'], Init>,
109-
'mutationFn'
110-
> & {
111-
mutationFn: Exclude<
112-
UseMutationOptions<Response['data'], Response['error'], Init>['mutationFn'],
113-
undefined
114-
>;
95+
Omit<UseMutationOptions<Response["data"], Response["error"], Init>, "mutationFn"> & {
96+
mutationFn: Exclude<UseMutationOptions<Response["data"], Response["error"], Init>["mutationFn"], undefined>;
11597
}
11698
>;
11799

@@ -128,13 +110,13 @@ export type InfiniteQueryOptionsFunction<
128110
Response extends Required<FetchResponse<Paths[Path][Method], Init, Media>>,
129111
Options extends Omit<
130112
UseInfiniteQueryOptions<
131-
Response['data'],
132-
Response['error'],
133-
InferSelectReturnType<InfiniteData<Response['data']>, Options['select']>,
113+
Response["data"],
114+
Response["error"],
115+
InferSelectReturnType<InfiniteData<Response["data"]>, Options["select"]>,
134116
QueryKey<Paths, Method, Path>,
135117
InferPageParamType<Options>
136118
>,
137-
'queryKey' | 'queryFn'
119+
"queryKey" | "queryFn"
138120
> & {
139121
pageParamName?: string;
140122
initialPageParam: InferPageParamType<Options>;
@@ -143,73 +125,67 @@ export type InfiniteQueryOptionsFunction<
143125
method: Method,
144126
path: Path,
145127
init: InitWithUnknowns<Init>,
146-
options: Options
128+
options: Options,
147129
) => NoInfer<
148130
Omit<
149131
UseInfiniteQueryOptions<
150-
Response['data'],
151-
Response['error'],
152-
InferSelectReturnType<InfiniteData<Response['data']>, Options['select']>,
132+
Response["data"],
133+
Response["error"],
134+
InferSelectReturnType<InfiniteData<Response["data"]>, Options["select"]>,
153135
QueryKey<Paths, Method, Path>,
154136
InferPageParamType<Options>
155137
>,
156-
'queryFn'
138+
"queryFn"
157139
> & {
158140
queryFn: Exclude<
159141
UseInfiniteQueryOptions<
160-
Response['data'],
161-
Response['error'],
162-
InferSelectReturnType<InfiniteData<Response['data']>, Options['select']>,
142+
Response["data"],
143+
Response["error"],
144+
InferSelectReturnType<InfiniteData<Response["data"]>, Options["select"]>,
163145
QueryKey<Paths, Method, Path>,
164146
InferPageParamType<Options>
165-
>['queryFn'],
147+
>["queryFn"],
166148
SkipToken | undefined
167149
>;
168150
}
169151
>;
170152

171-
export type UseQueryMethod<
172-
Paths extends Record<string, Record<HttpMethod, {}>>,
173-
Media extends MediaType,
174-
> = <
153+
export type UseQueryMethod<Paths extends Record<string, Record<HttpMethod, {}>>, Media extends MediaType> = <
175154
Method extends HttpMethod,
176155
Path extends PathsWithMethod<Paths, Method>,
177156
Init extends MaybeOptionalInit<Paths[Path], Method>,
178157
Response extends Required<FetchResponse<Paths[Path][Method], Init, Media>>, // note: Required is used to avoid repeating NonNullable in UseQuery types
179158
Options extends Omit<
180159
UseQueryOptions<
181-
Response['data'],
182-
Response['error'],
183-
InferSelectReturnType<Response['data'], Options['select']>,
160+
Response["data"],
161+
Response["error"],
162+
InferSelectReturnType<Response["data"], Options["select"]>,
184163
QueryKey<Paths, Method, Path>
185164
>,
186-
'queryKey' | 'queryFn'
165+
"queryKey" | "queryFn"
187166
>,
188167
>(
189168
method: Method,
190169
url: Path,
191170
...[init, options, queryClient]: RequiredKeysOf<Init> extends never
192171
? [InitWithUnknowns<Init>?, Options?, QueryClient?]
193172
: [InitWithUnknowns<Init>, Options?, QueryClient?]
194-
) => UseQueryResult<InferSelectReturnType<Response['data'], Options['select']>, Response['error']>;
173+
) => UseQueryResult<InferSelectReturnType<Response["data"], Options["select"]>, Response["error"]>;
195174

196-
export type UseInfiniteQueryMethod<
197-
Paths extends Record<string, Record<HttpMethod, {}>>,
198-
Media extends MediaType,
199-
> = <
175+
export type UseInfiniteQueryMethod<Paths extends Record<string, Record<HttpMethod, {}>>, Media extends MediaType> = <
200176
Method extends HttpMethod,
201177
Path extends PathsWithMethod<Paths, Method>,
202178
Init extends MaybeOptionalInit<Paths[Path], Method>,
203179
Response extends Required<FetchResponse<Paths[Path][Method], Init, Media>>,
204180
Options extends Omit<
205181
UseInfiniteQueryOptions<
206-
Response['data'],
207-
Response['error'],
208-
InferSelectReturnType<InfiniteData<Response['data']>, Options['select']>,
182+
Response["data"],
183+
Response["error"],
184+
InferSelectReturnType<InfiniteData<Response["data"]>, Options["select"]>,
209185
QueryKey<Paths, Method, Path>,
210186
unknown
211187
>,
212-
'queryKey' | 'queryFn'
188+
"queryKey" | "queryFn"
213189
> & {
214190
pageParamName?: string;
215191
},
@@ -218,58 +194,46 @@ export type UseInfiniteQueryMethod<
218194
url: Path,
219195
init: InitWithUnknowns<Init>,
220196
options: Options,
221-
queryClient?: QueryClient
197+
queryClient?: QueryClient,
222198
) => UseInfiniteQueryResult<
223-
InferSelectReturnType<InfiniteData<Response['data']>, Options['select']>,
224-
Response['error']
199+
InferSelectReturnType<InfiniteData<Response["data"]>, Options["select"]>,
200+
Response["error"]
225201
>;
226202

227-
export type UseSuspenseQueryMethod<
228-
Paths extends Record<string, Record<HttpMethod, {}>>,
229-
Media extends MediaType,
230-
> = <
203+
export type UseSuspenseQueryMethod<Paths extends Record<string, Record<HttpMethod, {}>>, Media extends MediaType> = <
231204
Method extends HttpMethod,
232205
Path extends PathsWithMethod<Paths, Method>,
233206
Init extends MaybeOptionalInit<Paths[Path], Method>,
234207
Response extends Required<FetchResponse<Paths[Path][Method], Init, Media>>, // note: Required is used to avoid repeating NonNullable in UseQuery types
235208
Options extends Omit<
236209
UseSuspenseQueryOptions<
237-
Response['data'],
238-
Response['error'],
239-
InferSelectReturnType<Response['data'], Options['select']>,
210+
Response["data"],
211+
Response["error"],
212+
InferSelectReturnType<Response["data"], Options["select"]>,
240213
QueryKey<Paths, Method, Path>
241214
>,
242-
'queryKey' | 'queryFn'
215+
"queryKey" | "queryFn"
243216
>,
244217
>(
245218
method: Method,
246219
url: Path,
247220
...[init, options, queryClient]: RequiredKeysOf<Init> extends never
248221
? [InitWithUnknowns<Init>?, Options?, QueryClient?]
249222
: [InitWithUnknowns<Init>, Options?, QueryClient?]
250-
) => UseSuspenseQueryResult<
251-
InferSelectReturnType<Response['data'], Options['select']>,
252-
Response['error']
253-
>;
223+
) => UseSuspenseQueryResult<InferSelectReturnType<Response["data"], Options["select"]>, Response["error"]>;
254224

255-
export type UseMutationMethod<
256-
Paths extends Record<string, Record<HttpMethod, {}>>,
257-
Media extends MediaType,
258-
> = <
225+
export type UseMutationMethod<Paths extends Record<string, Record<HttpMethod, {}>>, Media extends MediaType> = <
259226
Method extends HttpMethod,
260227
Path extends PathsWithMethod<Paths, Method>,
261228
Init extends MaybeOptionalInit<Paths[Path], Method>,
262229
Response extends Required<FetchResponse<Paths[Path][Method], Init, Media>>, // note: Required is used to avoid repeating NonNullable in UseQuery types
263-
Options extends Omit<
264-
UseMutationOptions<Response['data'], Response['error'], Init>,
265-
'mutationKey' | 'mutationFn'
266-
>,
230+
Options extends Omit<UseMutationOptions<Response["data"], Response["error"], Init>, "mutationKey" | "mutationFn">,
267231
>(
268232
method: Method,
269233
url: Path,
270234
options?: Options,
271-
queryClient?: QueryClient
272-
) => UseMutationResult<Response['data'], Response['error'], Init>;
235+
queryClient?: QueryClient,
236+
) => UseMutationResult<Response["data"], Response["error"], Init>;
273237

274238
export interface OpenapiQueryClient<Paths extends {}, Media extends MediaType = MediaType> {
275239
queryOptions: QueryOptionsFunction<Paths, Media>;
@@ -287,17 +251,13 @@ export type MethodResponse<
287251
? PathsWithMethod<Paths, Method>
288252
: never,
289253
Options = object,
290-
> =
291-
CreatedClient extends OpenapiQueryClient<
292-
infer Paths extends { [key: string]: any },
293-
infer Media extends MediaType
294-
>
295-
? NonNullable<FetchResponse<Paths[Path][Method], Options, Media>['data']>
296-
: never;
254+
> = CreatedClient extends OpenapiQueryClient<infer Paths extends { [key: string]: any }, infer Media extends MediaType>
255+
? NonNullable<FetchResponse<Paths[Path][Method], Options, Media>["data"]>
256+
: never;
297257

298258
// TODO: Add the ability to bring queryClient as argument
299259
export default function createClient<Paths extends {}, Media extends MediaType = MediaType>(
300-
client: FetchClient<Paths, Media>
260+
client: FetchClient<Paths, Media>,
301261
): OpenapiQueryClient<Paths, Media> {
302262
const queryFn = async <Method extends HttpMethod, Path extends PathsWithMethod<Paths, Method>>({
303263
queryKey: [method, path, init],
@@ -309,19 +269,16 @@ export default function createClient<Paths extends {}, Media extends MediaType =
309269
if (error) {
310270
throw error;
311271
}
312-
if (response.status === 204 || response.headers.get('Content-Length') === '0') {
272+
if (response.status === 204 || response.headers.get("Content-Length") === "0") {
313273
return data ?? null;
314274
}
315275

316276
return data;
317277
};
318278

319-
const createMutationFn = <
320-
Method extends HttpMethod,
321-
Path extends PathsWithMethod<Paths, Method>
322-
>(
279+
const createMutationFn = <Method extends HttpMethod, Path extends PathsWithMethod<Paths, Method>>(
323280
method: Method,
324-
path: Path
281+
path: Path,
325282
) => {
326283
return async (init: any) => {
327284
const mth = method.toUpperCase() as Uppercase<typeof method>;
@@ -336,9 +293,11 @@ export default function createClient<Paths extends {}, Media extends MediaType =
336293
};
337294

338295
const queryOptions: QueryOptionsFunction<Paths, Media> = (method, path, ...[init, options]) => ({
339-
queryKey: (init === undefined
340-
? ([method, path] as const)
341-
: ([method, path, init] as const)) as QueryKey<Paths, typeof method, typeof path>,
296+
queryKey: (init === undefined ? ([method, path] as const) : ([method, path, init] as const)) as QueryKey<
297+
Paths,
298+
typeof method,
299+
typeof path
300+
>,
342301
queryFn,
343302
...options,
344303
});
@@ -353,10 +312,7 @@ export default function createClient<Paths extends {}, Media extends MediaType =
353312
queryOptions,
354313
mutationOptions,
355314
useQuery: (method, path, ...[init, options, queryClient]) =>
356-
useQuery(
357-
queryOptions(method, path, init as InitWithUnknowns<typeof init>, options),
358-
queryClient
359-
),
315+
useQuery(queryOptions(method, path, init as InitWithUnknowns<typeof init>, options), queryClient),
360316
useSuspenseQuery: (method, path, ...[init, options, queryClient]) =>
361317
useSuspenseQuery(queryOptions(method, path, init as InitWithUnknowns<typeof init>, options), queryClient),
362318
useInfiniteQuery: (method, path, init, options, queryClient) => {
@@ -398,7 +354,7 @@ export default function createClient<Paths extends {}, Media extends MediaType =
398354
mutationFn: createMutationFn(method, path),
399355
...options,
400356
},
401-
queryClient
357+
queryClient,
402358
),
403359
};
404-
}
360+
}

packages/openapi-react-query/test/index.test.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {
22
QueryClient,
33
QueryClientProvider,
4-
useMutation,
54
skipToken,
5+
useMutation,
66
useQueries,
77
useQuery,
88
useSuspenseQuery,
@@ -11,12 +11,10 @@ import { act, fireEvent, render, renderHook, screen, waitFor } from "@testing-li
1111
import createFetchClient from "openapi-fetch";
1212
import { type ReactNode, Suspense } from "react";
1313
import { ErrorBoundary } from "react-error-boundary";
14+
import { afterAll, afterEach, beforeAll, describe, expect, expectTypeOf, it, vi } from "vitest";
1415
import createClient, { type MethodResponse } from "../src/index.js";
1516
import type { paths } from "./fixtures/api.js";
1617
import { baseUrl, server, useMockRequestHandler } from "./fixtures/mock-server.js";
17-
import { afterAll, afterEach, beforeAll, describe, expect, expectTypeOf, it, vi } from "vitest";
18-
19-
const mini = "3";
2018

2119
type minimalGetPaths = {
2220
// Without parameters.

0 commit comments

Comments
 (0)