Skip to content

Commit 0e88eee

Browse files
committed
Add RequestTypes utility back
1 parent b2c91cf commit 0e88eee

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
"exports": {
2121
".": {
2222
"import": {
23-
"types": "./dist/query.d.ts",
24-
"default": "./dist/query.js"
23+
"types": "./dist/index.d.ts",
24+
"default": "./dist/index.js"
2525
},
2626
"require": {
27-
"types": "./dist/query.d.cts",
28-
"default": "./dist/query.cjs"
27+
"types": "./dist/index.d.cts",
28+
"default": "./dist/index.cjs"
2929
}
3030
},
3131
"./immutable": {

src/index.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import type {
2+
ErrorResponseJSON,
3+
FilterKeys,
4+
PathsWithMethod,
5+
SuccessResponseJSON,
6+
} from "openapi-typescript-helpers";
7+
import type { SWRConfiguration, SWRResponse } from "swr";
8+
9+
export * from "./query.js";
10+
11+
export type RequestTypes<
12+
Paths extends object,
13+
Path extends PathsWithMethod<Paths, "get">,
14+
Req = FilterKeys<Paths[Path], "get">,
15+
Data = SuccessResponseJSON<Req>,
16+
Error = ErrorResponseJSON<Req>,
17+
Params = Req extends { parameters: infer P } ? P : never,
18+
PathParams = Params extends { path?: infer P } ? P : never,
19+
QueryParams = Params extends { query?: infer Q } ? Q : never,
20+
HeaderParams = Params extends { header?: infer H } ? H : never,
21+
CookieParams = Params extends { cookie?: infer C } ? C : never,
22+
SWRConfig = SWRConfiguration<Data, Error>,
23+
> = {
24+
Data: Data;
25+
Error: Error;
26+
PathParams: PathParams;
27+
QueryParams: QueryParams;
28+
Headers: HeaderParams;
29+
Cookies: CookieParams;
30+
SWRConfig: SWRConfig;
31+
SWRResponse: SWRResponse<Data, Error, SWRConfig>;
32+
};

tsup.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { defineConfig } from "tsup";
33
export default defineConfig({
44
entryPoints: [
55
"src/immutable.ts",
6+
"src/index.ts",
67
"src/infinite.ts",
78
"src/mutate.ts",
89
"src/query.ts",

0 commit comments

Comments
 (0)