Wayfinder.Processor.GroupRoutes (Wayfinder Ex v0.1.5)
View SourceHandle %Phoenix.Router.Route{}
entries —
These are the steps in this module.
- Group routes by their controller and action.
- Routes are grouped by shared static path prefix. Ex.:
/users/:id
andusers/:id/:name
- Within each group, the path with the most parameters becomes canonical. Ex.:
/users/:id/:name
- Routes are sorted with the shortest path first.
- All methods across the group are merged.
- Argument handling is inferred based on the variation in path parameters arity.
- We get for each route a map of all their arguments and if they are optional or not.
Also this is my best shot to simulating Phoenix has built-in support for optional parameters in the router. This is not a feature of Phoenix but if 2 routes are declared with 2 paths like this
get "/users/:id", UserController, :show
get "/users/:id/:name", UserController, :show
This is the logic here:
We assume :name
is optional and :id
is required.
We do all of this to generate a compresive TypeScript route definition
The final out is a list of %Wayfinder.Processor.Route{}
structs
Summary
Types
@type indexed_variant() :: {variant(), non_neg_integer()}
Functions
@spec call([Phoenix.Router.Route.t()], Wayfinder.Processor.Route.phoenix_route_opts()) :: [ Wayfinder.Processor.Route.t() ]