Skip to content

Commit

Permalink
feat: Allow passing a signal field to the fetcher (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
Embraser01 authored Jun 21, 2024
1 parent 764bd70 commit 33f5523
Show file tree
Hide file tree
Showing 20 changed files with 5,784 additions and 2,458 deletions.
5 changes: 5 additions & 0 deletions .yarn/versions/86b31116.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
releases:
"@typoas/cli": minor
"@typoas/generator": minor
"@typoas/react-query": minor
"@typoas/runtime": minor
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## Unreleased

- Add `-p,--prettier` option to the cli to format the generated code with prettier [#51](https://github.com/Embraser01/typoas/pull/51)
- Add a new `@typoas/react-query` package to generate fully typed react-query hooks [#63](https://github.com/Embraser01/typoas/pull/63)
- **BREAKING**: `FetcherData` must now extend `BaseFetcherData`. This change allow to have default options like `signal` for every request (fixes [#62](https://github.com/Embraser01/typoas/issues/62)) [#64](https://github.com/Embraser01/typoas/issues/64)
- **BREAKING**: Generate all responses types (fixes [#57](https://github.com/Embraser01/typoas/issues/57)) [#60](https://github.com/Embraser01/typoas/pull/60)
- Functions will not throw on non-2XX http status anymore
- Instead, users will have to check themselves or use the ok helper function
Expand Down
2,542 changes: 1,781 additions & 761 deletions examples/src/github-sample.ts

Large diffs are not rendered by default.

3,538 changes: 2,492 additions & 1,046 deletions examples/src/github.ts

Large diffs are not rendered by default.

42 changes: 22 additions & 20 deletions examples/src/petstore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export function configureAuth(
),
};
}
export function createContext<FetcherData>(
export function createContext<FetcherData extends r.BaseFetcherData>(
params?: r.CreateContextParams<AuthMethods, FetcherData>,
): r.Context<AuthMethods, FetcherData> {
return new r.Context<AuthMethods, FetcherData>({
Expand All @@ -156,7 +156,7 @@ export function createContext<FetcherData>(
* Update an existing pet by Id
* Tags: pet
*/
export async function updatePet<FetcherData>(
export async function updatePet<FetcherData extends r.BaseFetcherData>(
ctx: r.Context<AuthMethods, FetcherData>,
params: {},
body: Pet,
Expand All @@ -182,7 +182,7 @@ export async function updatePet<FetcherData>(
* Add a new pet to the store
* Tags: pet
*/
export async function addPet<FetcherData>(
export async function addPet<FetcherData extends r.BaseFetcherData>(
ctx: r.Context<AuthMethods, FetcherData>,
params: {},
body: Pet,
Expand All @@ -203,7 +203,7 @@ export async function addPet<FetcherData>(
* Multiple status values can be provided with comma separated strings
* Tags: pet
*/
export async function findPetsByStatus<FetcherData>(
export async function findPetsByStatus<FetcherData extends r.BaseFetcherData>(
ctx: r.Context<AuthMethods, FetcherData>,
params: {
status?: 'available' | 'pending' | 'sold';
Expand All @@ -225,7 +225,7 @@ export async function findPetsByStatus<FetcherData>(
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
* Tags: pet
*/
export async function findPetsByTags<FetcherData>(
export async function findPetsByTags<FetcherData extends r.BaseFetcherData>(
ctx: r.Context<AuthMethods, FetcherData>,
params: {
tags?: string[];
Expand All @@ -247,7 +247,7 @@ export async function findPetsByTags<FetcherData>(
* Returns a single pet
* Tags: pet
*/
export async function getPetById<FetcherData>(
export async function getPetById<FetcherData extends r.BaseFetcherData>(
ctx: r.Context<AuthMethods, FetcherData>,
params: {
petId: number;
Expand All @@ -271,7 +271,7 @@ export async function getPetById<FetcherData>(
* Updates a pet in the store with form data
* Tags: pet
*/
export async function updatePetWithForm<FetcherData>(
export async function updatePetWithForm<FetcherData extends r.BaseFetcherData>(
ctx: r.Context<AuthMethods, FetcherData>,
params: {
petId: number;
Expand All @@ -294,7 +294,7 @@ export async function updatePetWithForm<FetcherData>(
* Deletes a pet
* Tags: pet
*/
export async function deletePet<FetcherData>(
export async function deletePet<FetcherData extends r.BaseFetcherData>(
ctx: r.Context<AuthMethods, FetcherData>,
params: {
api_key?: string;
Expand All @@ -315,7 +315,7 @@ export async function deletePet<FetcherData>(
* uploads an image
* Tags: pet
*/
export async function uploadFile<FetcherData>(
export async function uploadFile<FetcherData extends r.BaseFetcherData>(
ctx: r.Context<AuthMethods, FetcherData>,
params: {
petId: number;
Expand All @@ -340,7 +340,7 @@ export async function uploadFile<FetcherData>(
* Returns a map of status codes to quantities
* Tags: store
*/
export async function getInventory<FetcherData>(
export async function getInventory<FetcherData extends r.BaseFetcherData>(
ctx: r.Context<AuthMethods, FetcherData>,
params: {},
opts?: FetcherData,
Expand All @@ -366,7 +366,7 @@ export async function getInventory<FetcherData>(
* Place a new order in the store
* Tags: store
*/
export async function placeOrder<FetcherData>(
export async function placeOrder<FetcherData extends r.BaseFetcherData>(
ctx: r.Context<AuthMethods, FetcherData>,
params: {},
body: Order,
Expand All @@ -392,7 +392,7 @@ export async function placeOrder<FetcherData>(
* For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions.
* Tags: store
*/
export async function getOrderById<FetcherData>(
export async function getOrderById<FetcherData extends r.BaseFetcherData>(
ctx: r.Context<AuthMethods, FetcherData>,
params: {
orderId: number;
Expand Down Expand Up @@ -422,7 +422,7 @@ export async function getOrderById<FetcherData>(
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
* Tags: store
*/
export async function deleteOrder<FetcherData>(
export async function deleteOrder<FetcherData extends r.BaseFetcherData>(
ctx: r.Context<AuthMethods, FetcherData>,
params: {
orderId: number;
Expand All @@ -442,7 +442,7 @@ export async function deleteOrder<FetcherData>(
* This can only be done by the logged in user.
* Tags: user
*/
export async function createUser<FetcherData>(
export async function createUser<FetcherData extends r.BaseFetcherData>(
ctx: r.Context<AuthMethods, FetcherData>,
params: {},
body: User,
Expand All @@ -462,7 +462,9 @@ export async function createUser<FetcherData>(
* Creates list of users with given input array
* Tags: user
*/
export async function createUsersWithListInput<FetcherData>(
export async function createUsersWithListInput<
FetcherData extends r.BaseFetcherData,
>(
ctx: r.Context<AuthMethods, FetcherData>,
params: {},
body: User[],
Expand All @@ -481,7 +483,7 @@ export async function createUsersWithListInput<FetcherData>(
* Logs user into the system
* Tags: user
*/
export async function loginUser<FetcherData>(
export async function loginUser<FetcherData extends r.BaseFetcherData>(
ctx: r.Context<AuthMethods, FetcherData>,
params: {
username?: string;
Expand All @@ -502,7 +504,7 @@ export async function loginUser<FetcherData>(
* Logs out current logged in user session
* Tags: user
*/
export async function logoutUser<FetcherData>(
export async function logoutUser<FetcherData extends r.BaseFetcherData>(
ctx: r.Context<AuthMethods, FetcherData>,
params: {},
opts?: FetcherData,
Expand All @@ -519,7 +521,7 @@ export async function logoutUser<FetcherData>(
* Get user by user name
* Tags: user
*/
export async function getUserByName<FetcherData>(
export async function getUserByName<FetcherData extends r.BaseFetcherData>(
ctx: r.Context<AuthMethods, FetcherData>,
params: {
username: string;
Expand All @@ -543,7 +545,7 @@ export async function getUserByName<FetcherData>(
* This can only be done by the logged in user.
* Tags: user
*/
export async function updateUser<FetcherData>(
export async function updateUser<FetcherData extends r.BaseFetcherData>(
ctx: r.Context<AuthMethods, FetcherData>,
params: {
username: string;
Expand All @@ -565,7 +567,7 @@ export async function updateUser<FetcherData>(
* This can only be done by the logged in user.
* Tags: user
*/
export async function deleteUser<FetcherData>(
export async function deleteUser<FetcherData extends r.BaseFetcherData>(
ctx: r.Context<AuthMethods, FetcherData>,
params: {
username: string;
Expand Down
Loading

0 comments on commit 33f5523

Please sign in to comment.