The memorable version 7π
Summary of Updates
This update includes a significant number of changes, effectively giving the link-generator a fresh start.
For those who may not want to go through all the details, here are the key highlights:
-
Transitioned the naming convention from camelCase to snake_case.
-
The
queryproperty of theExtractRouteDatatype has been renamed toqueries, and thepathproperty now infers more precise values. -
All properties in the third argument of the
linkfunction are now optional, and the use of?to mark parameters as optional has been removed. -
Passing a value of
0to a path parameter no longer omits that parameter.
Detailed Explanation
-
Transition from camelCase to snake_case
To improve consistency and readability, we have transitioned from camelCase to snake_case across the project.
We have rewritten the entire project using snake_case instead of camelCase.
The following function names have been updated:
-
flattenRouteConfig=>flatten_route_config -
createLinkGenerator=>create_link_generator
-
-
Improvements to
ExtractRouteDataThe
pathproperty of theExtractRouteDatatype has been improved, and now returns the value without the constraint area.const route_config = { route1: { path: "/:param<string>?key" } } as const; // Before const flat_route_config = flattenRouteConfig(route_config); type Route1Path = ExtractRouteData<typeof flat_route_config>["route1"]; // => /:param<string> // After Version 7 const flat_route_config = flatten_route_config(route_config); type RoutePath = ExtractRouteData<typeof flat_route_config>["route1"]; // => /:param
-
Removed the syntax for making query parameters optional using
?Since all query parameters are assumed to be optional, we have adjusted the types to reflect this.
As of version 7, the use of
?for optional query parameters has been removed.const route_config = { route1: { path: "/?key1&key2", }, } as const; // Before const flat_route_config = flattenRouteConfig(route_config); type Route1Query = ExtractRouteData<typeof flat_route_config>; // => { key1: DefaultParamValue, key2: DefaultParamValue } // After Version 7 const flat_route_config = flatten_route_config(route_config); type Route1Query = ExtractRouteData<typeof flat_route_config>; // => Partial<{ key1: DefaultParamValue, key2: DefaultParamValue }>
This change makes all query parameters optional when generating links with the
linkfunction.// Before link("route1", undefined, {}); // Type error! The query object must have key1 and key2 properties. // If you wanted all properties to be optional you had to add a "?" as a suffix to all query names. const optional_route_config = { route1: { path: "/?key1?&key2?", }, } as const; link("route1", undefined, {}); // After Version 7 // This uses the link function generated from the route_config mentioned above. link("route1", undefined, {}); // key1 and key2 are optional.
-
Bug Fixes Related to Path Parameters
Previously, passing a value of
0to a path parameter would result in that parameter being omitted.In version 7, this has been fixed, and the correct path is now generated.
const route_config = { route1: { path: "/:param" } } as const; // Before link("route1", { param: 0 }); // => "/" // After Version 7 link("route1", { param: 0 }); // => "/0"
Internal Changes
-
Documentation Update
In line with the changes above, we have rewritten all instances of camelCase in the documentation to snake_case.
Additionally, we have removed sections of the README that referred to the now-deprecated syntax for optional query parameters.
-
Test Updates
Previously, all tests were written in a single file. Recognizing that this was not scalable for testing multiple cases, we have split the tests into the following files:
-
path_abusolute.test.ts -
path_constraint.test.ts -
path_static.test.ts -
path_with_params_and_query.test.ts -
path_with_params.test.ts -
path_with_queries.test.ts
This improves scalability by allowing individual test cases to be managed separately.
-
-
File Name Updates
To make file names more intuitive, we have aligned them with their respective function names.
-
generator.ts=>create_link_generator.ts -
flatConfig.ts=>flatten_route_config.ts
-
-
Simplified Logic for Replacing Path Parameter Values
Previously, when replacing path parameters like
/:paramin a route such as/route/:paramwith actual values, the/:parampart was captured and replaced as/value. However, the initial/was unnecessary to match, so we have changed the logic to exclude the initial/using a positive lookahead. This is necessary to distinguish between port numbers and path parameters. -
Other Changes
-
We have unified variable and type names, such as replacing instances of
searchParamswithquery. -
Type names starting with
Excludehave been changed to start withRemove.
-