Skip to content

Design Type Validation that supports new Vercel App Routes #57

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

Open
seveibar opened this issue Mar 24, 2023 · 2 comments
Open

Design Type Validation that supports new Vercel App Routes #57

seveibar opened this issue Mar 24, 2023 · 2 comments
Assignees

Comments

@seveibar
Copy link
Contributor

seveibar commented Mar 24, 2023

New Vercel App endpoints don't support res

Could this also help with method-discriminated validation more generally?

export const GET = withRouteSpec.get({
	queryParams: z.object({ })
} as const, async (req) => {
  return Response(200, JSON.stringify("{}"))
//  return NextApiResponse.json({ })
})
@itelo itelo self-assigned this Mar 27, 2023
@itelo
Copy link
Contributor

itelo commented Mar 29, 2023

Based on the output of the command: grep -r methods pages/ > /tmp/methods.txt, I believe the withRouteSpec should have the methods:

get
post
put
patch
delete
getAndPost
postAndPut
postAndPatch
postAndDelete

We may want to exclude the postAndPut because only one route uses it.
Also, it would be good to add some jsdoc to explain why the methods like getAndPost are helpful (I only understand why we do this after @seveibar explained it in a slack thread for someone else)
Furthermore, we should have a custom method that accepts the method key inside the route_spec to be more future-proof and handle edge cases.

@seveibar
Copy link
Contributor Author

seveibar commented Mar 29, 2023

Nice analysis.

As an alternative to "custom", in typescript, it's possible to have a method that has properties like this:

interface myRouteSpec {
  get: ({ }) => {};
  ({ methods: string[] }) => {}
}

// usage
myRouteSpec({ methods: ["GET"] })
myRouteSpec.get({ })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants