Skip to content

Commit 9c8268c

Browse files
committed
refactor: correct export
1 parent 3ef6793 commit 9c8268c

File tree

4 files changed

+56
-58
lines changed

4 files changed

+56
-58
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
} from './matcher-pattern'
66
import { MatcherPatternPathStar } from './matcher-pattern-path-star'
77
import { miss } from './errors'
8-
import { definePathParamParser } from './param-parsers/types'
8+
import { definePathParamParser } from './param-parsers'
99

1010
describe('MatcherPatternPathStatic', () => {
1111
describe('match()', () => {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { describe, expectTypeOf, it } from 'vitest'
22
import { MatcherPatternPathDynamic } from './matcher-pattern'
33
import { PATH_PARAM_PARSER_DEFAULTS } from './param-parsers'
44
import { PATH_PARAM_SINGLE_DEFAULT } from './param-parsers'
5-
import { definePathParamParser } from './param-parsers/types'
5+
import { definePathParamParser } from './param-parsers'
66

77
describe('MatcherPatternPathDynamic', () => {
88
it('can be generic', () => {

packages/router/src/experimental/route-resolver/matchers/param-parsers/index.ts

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1+
import type { MatcherQueryParamsValue } from '../matcher-pattern'
12
import type { ParamParser } from './types'
23

3-
export {
4-
definePathParamParser,
5-
defineParamParser,
6-
defineQueryParamParser,
7-
} from './types'
4+
export { PARAM_PARSER_BOOL } from './booleans'
5+
export { PARAM_PARSER_INT } from './integers'
86

97
export const PATH_PARAM_SINGLE_DEFAULT: ParamParser<string, string> = {}
108

@@ -34,5 +32,53 @@ export const PATH_PARAM_PARSER_DEFAULTS = {
3432

3533
export type { ParamParser }
3634

37-
export { PARAM_PARSER_INT } from './integers'
38-
export { PARAM_PARSER_BOOL } from './booleans'
35+
/**
36+
* Defines a path param parser.
37+
*
38+
* @param parser - the parser to define. Will be returned as is.
39+
*
40+
* @see {@link defineQueryParamParser}
41+
* @see {@link defineParamParser}
42+
*/
43+
/*! #__NO_SIDE_EFFECTS__ */
44+
45+
export function definePathParamParser<
46+
TParam,
47+
// path params are parsed by the router as these
48+
// we use extend to allow infering a more specific type
49+
TUrlParam extends string | string[] | null,
50+
// we can allow pushing with extra values
51+
TParamRaw,
52+
>(parser: Required<ParamParser<TParam, TUrlParam, TParamRaw>>) {
53+
return parser
54+
}
55+
56+
/**
57+
* Defines a query param parser. Note that query params can also be used as
58+
* path param parsers.
59+
*
60+
* @param parser - the parser to define. Will be returned as is.
61+
*
62+
* @see {@link definePathParamParser}
63+
* @see {@link defineParamParser}
64+
*/
65+
/*! #__NO_SIDE_EFFECTS__ */
66+
67+
export function defineQueryParamParser<
68+
TParam,
69+
// we can allow pushing with extra values
70+
TParamRaw = TParam,
71+
>(parser: Required<ParamParser<TParam, MatcherQueryParamsValue, TParamRaw>>) {
72+
return parser
73+
}
74+
75+
/**
76+
* Alias for {@link defineQueryParamParser}. Implementing a param parser like this
77+
* works for path, query, and hash params.
78+
*
79+
* @see {@link defineQueryParamParser}
80+
* @see {@link definePathParamParser}
81+
*/
82+
/*! #__NO_SIDE_EFFECTS__ */
83+
84+
export const defineParamParser = defineQueryParamParser

packages/router/src/experimental/route-resolver/matchers/param-parsers/types.ts

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MatcherQueryParamsValue } from '../matcher-pattern'
1+
import type { MatcherQueryParamsValue } from '../matcher-pattern'
22

33
/**
44
* Defines a parser that can read a param from the url (string-based) and
@@ -20,54 +20,6 @@ export interface ParamParser<
2020
set?: (value: TParamRaw) => TUrlParam
2121
}
2222

23-
/**
24-
* Defines a path param parser.
25-
*
26-
* @param parser - the parser to define. Will be returned as is.
27-
*
28-
* @see {@link defineQueryParamParser}
29-
* @see {@link defineParamParser}
30-
*/
31-
/*! #__NO_SIDE_EFFECTS__ */
32-
export function definePathParamParser<
33-
TParam,
34-
// path params are parsed by the router as these
35-
// we use extend to allow infering a more specific type
36-
TUrlParam extends string | string[] | null,
37-
// we can allow pushing with extra values
38-
TParamRaw,
39-
>(parser: Required<ParamParser<TParam, TUrlParam, TParamRaw>>) {
40-
return parser
41-
}
42-
43-
/**
44-
* Defines a query param parser. Note that query params can also be used as
45-
* path param parsers.
46-
*
47-
* @param parser - the parser to define. Will be returned as is.
48-
*
49-
* @see {@link definePathParamParser}
50-
* @see {@link defineParamParser}
51-
*/
52-
/*! #__NO_SIDE_EFFECTS__ */
53-
export function defineQueryParamParser<
54-
TParam,
55-
// we can allow pushing with extra values
56-
TParamRaw = TParam,
57-
>(parser: Required<ParamParser<TParam, MatcherQueryParamsValue, TParamRaw>>) {
58-
return parser
59-
}
60-
61-
/**
62-
* Alias for {@link defineQueryParamParser}. Implementing a param parser like this
63-
* works for path, query, and hash params.
64-
*
65-
* @see {@link defineQueryParamParser}
66-
* @see {@link definePathParamParser}
67-
*/
68-
/*! #__NO_SIDE_EFFECTS__ */
69-
export const defineParamParser = defineQueryParamParser
70-
7123
// TODO: I wonder if native param parsers should follow this or similar
7224
// these parsers can be used for both query and path params
7325
// export type ParamParserBoth<T> = ParamParser<T | T[] | null>

0 commit comments

Comments
 (0)