taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit eef5b37306ed430fe6140c1b332e1f001fc0b969
parent 713711806b148408c6d29835d7e3fb9689a91d9f
Author: Sebastian <sebasjm@gmail.com>
Date:   Thu,  4 Jul 2024 10:04:57 -0300

on 404 return no-name but request params

Diffstat:
Mpackages/web-util/src/context/navigation.ts | 3++-
Mpackages/web-util/src/index.build.ts | 1+
Mpackages/web-util/src/utils/route.ts | 25++++++++++++++++---------
3 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/packages/web-util/src/context/navigation.ts b/packages/web-util/src/context/navigation.ts @@ -22,6 +22,7 @@ import { Location, findMatch, RouteDefinition, + LocationNotFound, } from "../utils/route.js"; /** @@ -44,7 +45,7 @@ export const useNavigationContext = (): Type => useContext(Context); // eslint-disable-next-line @typescript-eslint/no-explicit-any export function useCurrentLocation<T extends ObjectOf<RouteDefinition<any>>>( pagesMap: T, -): Location<T> | undefined { +): Location<T> | LocationNotFound<T> { const pageList = Object.keys(pagesMap as object) as Array<keyof T>; const { path, params } = useNavigationContext(); diff --git a/packages/web-util/src/index.build.ts b/packages/web-util/src/index.build.ts @@ -292,6 +292,7 @@ export function computeConfig(params: BuildParams): esbuild.BuildOptions { entryPoints: params.source.js, publicPath: params.public, outdir: params.destination, + treeShaking: true, minify: false, //params.type === "production", sourcemap: true, //params.type !== "production", define: { diff --git a/packages/web-util/src/utils/route.ts b/packages/web-util/src/utils/route.ts @@ -75,7 +75,7 @@ export function findMatch<T extends ObjectOf<RouteDefinition>>( pageList: Array<keyof T>, path: string, params: Record<string, string[]>, -): Location<T> | undefined { +): Location<T> | LocationNotFound<T> { for (let idx = 0; idx < pageList.length; idx++) { const name = pageList[idx]; const found = pagesMap[name].pattern.exec(path); @@ -92,7 +92,8 @@ export function findMatch<T extends ObjectOf<RouteDefinition>>( return { name, parent: pagesMap, values, params }; } } - return undefined; + // @ts-expect-error values is a map string which is equivalent to the RouteParamsType + return { name: undefined, parent: pagesMap, values: {}, params }; } /** @@ -109,13 +110,13 @@ type RouteParamsType< */ type MapKeyValue<Type> = { [Key in keyof Type]: Key extends string - ? { - parent: Type; - name: Key; - values: RouteParamsType<Type, Key>; - params: Record<string, string[]>; - } - : never; + ? { + parent: Type; + name: Key; + values: RouteParamsType<Type, Key>; + params: Record<string, string[]>; + } + : never; }; /** @@ -124,3 +125,9 @@ type MapKeyValue<Type> = { type EnumerationOf<T> = T[keyof T]; export type Location<T> = EnumerationOf<MapKeyValue<T>>; +export type LocationNotFound<Type> = { + parent: Type; + name: undefined; + values: RouteParamsType<Type, keyof Type>; + params: Record<string, string[]>; +};