Skip to content

Update swr-openapi dependencies and fix types #1993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/gentle-snails-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"swr-openapi": minor
---

Update dependencies and adjust paths signature to conform to updated helper signature
Empty file removed packages/swr-openapi/.npmignore
Empty file.
2 changes: 1 addition & 1 deletion packages/swr-openapi/LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Hunter Tunnicliff
Copyright (c) 2024 Hunter Tunnicliff

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
63 changes: 0 additions & 63 deletions packages/swr-openapi/eslint.config.js

This file was deleted.

10 changes: 5 additions & 5 deletions packages/swr-openapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
"version": "pnpm run build"
},
"peerDependencies": {
"openapi-fetch": "0.12",
"openapi-typescript": "7",
"openapi-fetch": "workspace:*",
"openapi-typescript": "workspace:7.x",
"react": "18 || 19",
"swr": "2",
"typescript": "^5.x"
Expand All @@ -68,7 +68,7 @@
}
},
"dependencies": {
"openapi-typescript-helpers": "0.0.13",
"openapi-typescript-helpers": "workspace:*",
"type-fest": "4.26.1"
},
"devDependencies": {
Expand All @@ -79,8 +79,8 @@
"husky": "9.1.5",
"lint-staged": "15.2.10",
"lodash": "4.17.21",
"openapi-fetch": "0.12.0",
"openapi-typescript": "7.4.0",
"openapi-fetch": "workspace:*",
"openapi-typescript": "workspace:7.x",
"react": "18.3.1",
"swr": "2.2.5",
"typescript": "5.5.4",
Expand Down
8 changes: 4 additions & 4 deletions packages/swr-openapi/src/__test__/types.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Pet = components["schemas"]["Pet"];
type PetInvalid = ErrorResponseJSON<paths["/pet/{petId}"]["get"]>;
type PetStatusInvalid = ErrorResponseJSON<paths["/pet/findByStatus"]["get"]>;
expectTypeOf<Pet>().toMatchTypeOf<{ name: string }>();
expectTypeOf<PetInvalid>().toMatchTypeOf<{ message: string }>();
expectTypeOf<PetInvalid>().toMatchTypeOf<{ message: string } | undefined>();
expectTypeOf<PetStatusInvalid>().toMatchTypeOf<{ message: string }>();

// Set up hooks
Expand Down Expand Up @@ -383,7 +383,7 @@ describe("TypesForRequest", () => {
it("returns correct error", () => {
expectTypeOf<GetPet["Error"]>().toEqualTypeOf<PetInvalid>();
expectTypeOf<FindPetsByStatus["Error"]>().toEqualTypeOf<PetStatusInvalid>();
expectTypeOf<FindPetsByTags["Error"]>().toEqualTypeOf<never>();
expectTypeOf<FindPetsByTags["Error"]>().toEqualTypeOf<undefined>();
});

it("returns correct path params", () => {
Expand Down Expand Up @@ -430,7 +430,7 @@ describe("TypesForRequest", () => {
it("returns correct SWR config", () => {
expectTypeOf<GetPet["SWRConfig"]>().toEqualTypeOf<SWR.SWRConfiguration<Pet, PetInvalid>>();
expectTypeOf<FindPetsByStatus["SWRConfig"]>().toEqualTypeOf<SWR.SWRConfiguration<Pet[], PetStatusInvalid>>();
expectTypeOf<FindPetsByTags["SWRConfig"]>().toEqualTypeOf<SWR.SWRConfiguration<Pet[], never>>();
expectTypeOf<FindPetsByTags["SWRConfig"]>().toEqualTypeOf<SWR.SWRConfiguration<Pet[], undefined>>();
});

it("returns correct SWR response", () => {
Expand All @@ -441,7 +441,7 @@ describe("TypesForRequest", () => {
SWR.SWRResponse<Pet[], PetStatusInvalid, SWR.SWRConfiguration<Pet[], PetStatusInvalid>>
>();
expectTypeOf<FindPetsByTags["SWRResponse"]>().toEqualTypeOf<
SWR.SWRResponse<Pet[], never, SWR.SWRConfiguration<Pet[], never>>
SWR.SWRResponse<Pet[], undefined, SWR.SWRConfiguration<Pet[], undefined>>
>();
});
});
1 change: 0 additions & 1 deletion packages/swr-openapi/src/mutate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import type { PartialDeep } from "type-fest";
import type { TypesForGetRequest } from "./types.js";

// Types are loose here to support ecosystem utilities like `_.isMatch`
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type CompareFn = (init: any, partialInit: any) => boolean;

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/swr-openapi/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type TryKey<T, K extends PropertyKey> = T extends { [Key in K]?: unknown } ? T[K
* Provides specific types used within a given request
*/
export type TypesForRequest<
Paths extends {},
Paths extends Record<string | number, any>,
Method extends Extract<HttpMethod, keyof Paths[keyof Paths]>,
Path extends PathsWithMethod<Paths, Method>,
// ---
Expand Down Expand Up @@ -42,6 +42,6 @@ export type TypesForRequest<
* Uses {@link TypesForRequest}
*/
export type TypesForGetRequest<
Paths extends {},
Paths extends Record<string | number, any>,
Path extends PathsWithMethod<Paths, Extract<"get", keyof Paths[keyof Paths]>>,
> = TypesForRequest<Paths, Extract<"get", keyof Paths[keyof Paths]>, Path>;
42 changes: 6 additions & 36 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading