Skip to content

Commit 08dfd9e

Browse files
committed
refactor: merge the parser config
1 parent a1abbcb commit 08dfd9e

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

packages/experiments-playground/src/router/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,7 @@ const r_profiles_detail = normalizeRouteRecord({
144144
path: new MatcherPatternPathCustomParams(
145145
/^\/profiles\/([^/]+)$/i,
146146
{
147-
userId: {
148-
parser: PARAM_INTEGER,
149-
},
147+
userId: PARAM_INTEGER,
150148
},
151149
['profiles', 0]
152150
),

packages/router/src/experimental/route-resolver/matchers/matcher-pattern.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ describe('MatcherPatternPathCustom', () => {
141141
const pattern = new MatcherPatternPathCustomParams(
142142
/^\/teams(?:\/([^/]+?))?\/b$/i,
143143
{
144-
teamId: { optional: true },
144+
teamId: {},
145145
},
146146
['teams', 0, 'b']
147147
)
@@ -177,7 +177,7 @@ describe('MatcherPatternPathCustom', () => {
177177
const pattern = new MatcherPatternPathCustomParams(
178178
/^\/teams(?:\/(.+?))?\/b$/i,
179179
{
180-
teamId: { repeat: true, optional: true },
180+
teamId: { repeat: true },
181181
},
182182
['teams', 0, 'b']
183183
)

packages/router/src/experimental/route-resolver/matchers/matcher-pattern.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,11 @@ export type ParamsFromParsers<P extends Record<string, ParamParser_Generic>> = {
198198
interface MatcherPatternPathCustomParamOptions<
199199
TIn extends string | string[] | null = string | string[] | null,
200200
TOut = string | string[] | null,
201-
> {
201+
> extends Param_GetSet<TIn, TOut> {
202202
repeat?: boolean
203-
// TODO: not needed because in the regexp, the value is undefined if the group is optional and not given
204-
optional?: boolean
205-
parser?: Param_GetSet<TIn, TOut>
203+
// NOTE: not needed because in the regexp, the value is undefined if
204+
// the group is optional and not given
205+
// optional?: boolean
206206
}
207207

208208
/**
@@ -295,7 +295,7 @@ export class MatcherPatternPathCustomParams<
295295
)
296296
: decode(currentMatch)
297297

298-
params[paramName] = (paramOptions.parser?.get || (v => v))(
298+
params[paramName] = (paramOptions.get || (v => v))(
299299
value
300300
// NOTE: paramName and paramOptions are not connected from TS point of view
301301
)
@@ -325,7 +325,7 @@ export class MatcherPatternPathCustomParams<
325325
const paramName = this.paramsKeys[paramIndex++]
326326
const paramOptions = this.params[paramName]
327327
const value: ReturnType<NonNullable<Param_GetSet['set']>> = (
328-
paramOptions.parser?.set || (v => v)
328+
paramOptions.set || (v => v)
329329
)(params[paramName])
330330

331331
return Array.isArray(value)

0 commit comments

Comments
 (0)