@@ -54,26 +54,7 @@ export type _ParamDelimiter =
54
54
| _ParamModifier
55
55
56
56
/**
57
- * Given a simple path, creates an object of the possible param values.
58
- *
59
- * @internal
60
- */
61
- export type _ExtractParamsPath <
62
- P extends string ,
63
- isRaw extends boolean
64
- > = P extends `${string } {${infer PP } }${infer Rest } `
65
- ? ( PP extends `${infer N } ${_ParamModifier } `
66
- ? PP extends `${N } ${infer M } `
67
- ? M extends _ParamModifier
68
- ? _ParamToObject < N , M , isRaw >
69
- : never
70
- : never
71
- : _ParamToObject < PP , '' , isRaw > ) &
72
- _ExtractParamsPath < Rest , isRaw >
73
- : { }
74
-
75
- /**
76
- * Given a path, extracts the possible params or {} when there are no params.
57
+ * Given a path, extracts the possible params or \{\} when there are no params.
77
58
*
78
59
* @internal
79
60
*/
@@ -93,34 +74,18 @@ export type _ExtractParamsOfPath<
93
74
>
94
75
? _ParamToObject < ParamName , Modifier , isRaw > &
95
76
_ExtractParamsOfPath < Rest2 , isRaw >
96
- : {
97
- NO : 1 // this should never happen as the modifier can be empty
98
- }
77
+ : never // this should never happen as the modifier can be empty
99
78
: // Nothing after the param: /:id, we are done
100
79
_ParamToObject < HasParam , '' , isRaw >
101
80
: {
102
81
// EMPTY: 1
103
82
}
104
83
105
- type a1 = _ExtractParamsOfPath < '/' , false >
106
- type a2 = _ExtractParamsOfPath < '/:id' , false >
107
- type a3 = _ExtractParamsOfPath < '/:id/:b' , false >
108
- type a4 = _ExtractParamsOfPath < '/:id(.*)' , false >
109
- type a5 = _ExtractParamsOfPath < '/:id(.*)/other' , false >
110
- type a6 = _ExtractParamsOfPath < '/:id(.*)+' , false >
111
- type a7 = _ExtractParamsOfPath < '/:id(.*)+/other' , false >
112
- type a8 = _ExtractParamsOfPath < '/:id(.*)+/other/:b/:c/:d' , false >
113
-
114
- type test1 =
115
- '/:id/:b' extends `${string } :${infer P } ${_ParamDelimiter } ${infer Rest } `
116
- ? [ P , Rest ]
117
- : never
118
-
119
84
/**
120
85
* Helper type to infer a param name extraction result
121
86
* @internal
122
87
*/
123
- interface _ParamExtractResult < P extends string , Rest extends string > {
88
+ export interface _ParamExtractResult < P extends string , Rest extends string > {
124
89
param : P
125
90
rest : Rest
126
91
}
@@ -146,10 +111,6 @@ type _ExtractParamName<
146
111
: // add the rest to the end after a % which is invalid in a path so it can be used as a delimiter
147
112
_ParamExtractResult < Head , Tail >
148
113
149
- type p1 = _ExtractParamName < 'id' >
150
- type p2 = _ExtractParamName < 'abc+/dos' >
151
- type p3 = _ExtractParamName < 'abc/:dos)' >
152
-
153
114
/**
154
115
* We consider a what comes after a param, e.g. For `/:id(\\d+)+/edit`, it would be `(\\d+)+/edit`. This should output
155
116
* everything after the regex while handling escaped `)`: `+/edit`. Note this type should be used with a string that
@@ -173,19 +134,6 @@ export type _StripRegex<S extends string> =
173
134
: // nothing to remove
174
135
S
175
136
176
- const a = '/:id(\\d+)+/edit/:more(.*)' as '/:id+/edit/:more'
177
-
178
- type r1 = _StripRegex < '(\\d+)+/edit/' >
179
- type r3 = _StripRegex < '(.*)*' >
180
- type r4 = _StripRegex < '?/rest' >
181
- type r5 = _StripRegex < '*' >
182
- type r6 = _StripRegex < '-other-stuff' >
183
- type r7 = _StripRegex < '/edit' >
184
-
185
- // type r8 = _StripRegex<'?/rest/:other(.*)'>
186
- // type r9 = _StripRegex<'(\\d+)+/edit/:other(.*)*'>
187
- // type r10 = _StripRegex<'?/rest/:other(.*)/more/:b(.*)'>
188
-
189
137
/**
190
138
* Helper type to infer a modifier extraction result.
191
139
*
@@ -217,12 +165,6 @@ export type _ExtractModifier<P extends string> =
217
165
: // No modifier present
218
166
_ModifierExtracTResult < '' , P >
219
167
220
- type m1 = _ExtractModifier < '' >
221
- type m2 = _ExtractModifier < '-rest' >
222
- type m3 = _ExtractModifier < 'edit' >
223
- type m4 = _ExtractModifier < '+' >
224
- type m5 = _ExtractModifier < '+/edit' >
225
-
226
168
/**
227
169
* Gets the possible type of a param based on its modifier M.
228
170
*
@@ -308,66 +250,12 @@ export type _RemoveUntilClosingPar<S extends string> =
308
250
S extends `${infer A } \\) ${infer Rest } `
309
251
? // the actual regexp finished before, A has no escaped )
310
252
A extends `${string } )${infer Rest2 } `
311
- ? Rest2 extends `${_ParamModifier } ${infer Rest3 } `
312
- ? Rest2 extends `${infer M } ${Rest3 } `
313
- ? `${M } }${Rest3 } \\) ${Rest } `
314
- : never
315
- : `}${Rest2 } \\) ${Rest } ` // job done
253
+ ? `${Rest2 } \\) ${Rest } ` // job done
316
254
: _RemoveUntilClosingPar < Rest > // we keep removing
317
255
: S extends `${string } )${infer Rest } `
318
- ? Rest extends `${_ParamModifier } ${infer Rest2 } `
319
- ? Rest extends `${infer M } ${Rest2 } `
320
- ? `${M } }${Rest2 } `
321
- : never
322
- : `}${Rest } `
256
+ ? Rest
323
257
: never // nothing to remove, should not have been called, easier to spot bugs
324
258
325
- type r = _RemoveUntilClosingPar < `aouest)/end`>
326
- type r2 = _RemoveUntilClosingPar < `aouest`>
327
-
328
- /**
329
- * Reformats a path string `/:id(custom-regex)/:other+` by wrapping params with
330
- * `{}` and removing custom regexps to make them easier to parse.
331
- *
332
- * @internal
333
- */
334
- export type _RemoveRegexpFromParam < S extends string > =
335
- S extends `${infer A } :${infer P } ${_ParamDelimiter } ${infer Rest } `
336
- ? P extends _ExtractFirstParamName < P >
337
- ? S extends `${A } :${P } ${infer D } ${Rest } `
338
- ? D extends _ParamModifier | ''
339
- ? `${A } {${P } ${D } }${S extends `${A } :${P } ${D } ${infer Rest2 } ` // we need to infer again...
340
- ? _RemoveRegexpFromParam < Rest2 >
341
- : never } `
342
- : D extends _ParamDelimiter
343
- ? '(' extends D
344
- ? `${A } {${P } ${S extends `${A } :${P } (${infer Rest2 } ` // we need to infer again to include D
345
- ? _RemoveRegexpFromParam < _RemoveUntilClosingPar < Rest2 > >
346
- : '}' } `
347
- : `${A } {${P } }${S extends `${A } :${P } ${infer Rest2 } ` // we need to infer again to include D
348
- ? _RemoveRegexpFromParam < Rest2 >
349
- : never } `
350
- : never
351
- : never
352
- : never
353
- : S extends `${infer A } :${infer P } `
354
- ? P extends _ExtractFirstParamName < P >
355
- ? `${A } {${P } }`
356
- : never
357
- : S
358
-
359
- /**
360
- * Extract the first param name (after a `:`) and ignores the rest.
361
- *
362
- * @internal
363
- */
364
- export type _ExtractFirstParamName < S extends string > =
365
- S extends `${infer P } ${_ParamDelimiter } ${string } `
366
- ? _ExtractFirstParamName < P >
367
- : S extends `${string } ${_ParamDelimiter } ${string } `
368
- ? never
369
- : S
370
-
371
259
/**
372
260
* Joins a prefix and a path putting a `/` between them when necessary
373
261
*
0 commit comments