Skip to content

The memorable version 7πŸŽ‰

Choose a tag to compare

@cat394 cat394 released this 10 Sep 09:00
· 105 commits to main since this release

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:

  1. Transitioned the naming convention from camelCase to snake_case.

  2. The query property of the ExtractRouteData type has been renamed to queries, and the path property now infers more precise values.

  3. All properties in the third argument of the link function are now optional, and the use of ? to mark parameters as optional has been removed.

  4. Passing a value of 0 to a path parameter no longer omits that parameter.

Detailed Explanation

  1. 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

  2. Improvements to ExtractRouteData

    The path property of the ExtractRouteData type 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
  3. 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 link function.

    // 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.
  4. Bug Fixes Related to Path Parameters

    Previously, passing a value of 0 to 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 /:param in a route such as /route/:param with actual values, the /:param part 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 searchParams with query.

    • Type names starting with Exclude have been changed to start with Remove.