From 08dfd9e2bbe2ec20c6f4443e4975612c2cab42bb Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Fri, 8 Aug 2025 23:25:35 +0200 Subject: [PATCH] refactor: merge the parser config --- packages/experiments-playground/src/router/index.ts | 4 +--- .../route-resolver/matchers/matcher-pattern.spec.ts | 4 ++-- .../route-resolver/matchers/matcher-pattern.ts | 12 ++++++------ 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/packages/experiments-playground/src/router/index.ts b/packages/experiments-playground/src/router/index.ts index accf3723..27789265 100644 --- a/packages/experiments-playground/src/router/index.ts +++ b/packages/experiments-playground/src/router/index.ts @@ -144,9 +144,7 @@ const r_profiles_detail = normalizeRouteRecord({ path: new MatcherPatternPathCustomParams( /^\/profiles\/([^/]+)$/i, { - userId: { - parser: PARAM_INTEGER, - }, + userId: PARAM_INTEGER, }, ['profiles', 0] ), diff --git a/packages/router/src/experimental/route-resolver/matchers/matcher-pattern.spec.ts b/packages/router/src/experimental/route-resolver/matchers/matcher-pattern.spec.ts index 5ddf274f..0a4c8b04 100644 --- a/packages/router/src/experimental/route-resolver/matchers/matcher-pattern.spec.ts +++ b/packages/router/src/experimental/route-resolver/matchers/matcher-pattern.spec.ts @@ -141,7 +141,7 @@ describe('MatcherPatternPathCustom', () => { const pattern = new MatcherPatternPathCustomParams( /^\/teams(?:\/([^/]+?))?\/b$/i, { - teamId: { optional: true }, + teamId: {}, }, ['teams', 0, 'b'] ) @@ -177,7 +177,7 @@ describe('MatcherPatternPathCustom', () => { const pattern = new MatcherPatternPathCustomParams( /^\/teams(?:\/(.+?))?\/b$/i, { - teamId: { repeat: true, optional: true }, + teamId: { repeat: true }, }, ['teams', 0, 'b'] ) diff --git a/packages/router/src/experimental/route-resolver/matchers/matcher-pattern.ts b/packages/router/src/experimental/route-resolver/matchers/matcher-pattern.ts index e1f21b78..083902a1 100644 --- a/packages/router/src/experimental/route-resolver/matchers/matcher-pattern.ts +++ b/packages/router/src/experimental/route-resolver/matchers/matcher-pattern.ts @@ -198,11 +198,11 @@ export type ParamsFromParsers

> = { interface MatcherPatternPathCustomParamOptions< TIn extends string | string[] | null = string | string[] | null, TOut = string | string[] | null, -> { +> extends Param_GetSet { repeat?: boolean - // TODO: not needed because in the regexp, the value is undefined if the group is optional and not given - optional?: boolean - parser?: Param_GetSet + // NOTE: not needed because in the regexp, the value is undefined if + // the group is optional and not given + // optional?: boolean } /** @@ -295,7 +295,7 @@ export class MatcherPatternPathCustomParams< ) : decode(currentMatch) - params[paramName] = (paramOptions.parser?.get || (v => v))( + params[paramName] = (paramOptions.get || (v => v))( value // NOTE: paramName and paramOptions are not connected from TS point of view ) @@ -325,7 +325,7 @@ export class MatcherPatternPathCustomParams< const paramName = this.paramsKeys[paramIndex++] const paramOptions = this.params[paramName] const value: ReturnType> = ( - paramOptions.parser?.set || (v => v) + paramOptions.set || (v => v) )(params[paramName]) return Array.isArray(value) -- 2.47.3