@@ -3,6 +3,7 @@ import { CUSTOM_ROUTE_AGRS_METADATA, ROUTE_ARGS_METADATA } from '../../constants
33import { PipeTransform } from '../../index' ;
44import { Type } from '../../interfaces' ;
55import { CustomParamFactory } from '../../interfaces/features/custom-route-param-factory.interface' ;
6+ import { isNil , isString } from '../../utils/shared.utils' ;
67import { ParamData , RouteParamsMetadata } from './route-params.decorator' ;
78
89const assignCustomMetadata = (
@@ -33,18 +34,29 @@ const randomString = () =>
3334 */
3435export function createParamDecorator (
3536 factory : CustomParamFactory ,
36- ) : ( data ?: any , ...pipes : ( Type < PipeTransform > | PipeTransform ) [ ] ) => ParameterDecorator {
37+ ) : ( ...dataOrPipes : ( Type < PipeTransform > | PipeTransform | string ) [ ] ) => ParameterDecorator {
3738 const paramtype = randomString ( ) + randomString ( ) ;
38- return ( data ?, ...pipes : ( Type < PipeTransform > | PipeTransform ) [ ] ) : ParameterDecorator => (
39- target ,
40- key ,
41- index ,
42- ) => {
39+ return (
40+ data ?,
41+ ...pipes : ( Type < PipeTransform > | PipeTransform ) [ ] ,
42+ ) : ParameterDecorator => ( target , key , index ) => {
4343 const args =
4444 Reflect . getMetadata ( ROUTE_ARGS_METADATA , target . constructor , key ) || { } ;
45+
46+ const hasParamData = isNil ( data ) || isString ( data ) ;
47+ const paramData = hasParamData ? data : undefined ;
48+ const paramPipes = hasParamData ? pipes : [ data , ...pipes ] ;
49+
4550 Reflect . defineMetadata (
4651 ROUTE_ARGS_METADATA ,
47- assignCustomMetadata ( args , paramtype , index , factory , data , ...pipes ) ,
52+ assignCustomMetadata (
53+ args ,
54+ paramtype ,
55+ index ,
56+ factory ,
57+ paramData ,
58+ ...paramPipes ,
59+ ) ,
4860 target . constructor ,
4961 key ,
5062 ) ;
@@ -58,7 +70,10 @@ export function createParamDecorator(
5870 */
5971export function createRouteParamDecorator (
6072 factory : CustomParamFactory ,
61- ) : ( data ?: any , ...pipes : ( Type < PipeTransform > | PipeTransform ) [ ] ) => ParameterDecorator {
73+ ) : (
74+ data ?: any ,
75+ ...pipes : ( Type < PipeTransform > | PipeTransform ) [ ] ,
76+ ) => ParameterDecorator {
6277 deprecate (
6378 'The "createRouteParamDecorator" function is deprecated and will be removed within next major release. Use "createParamDecorator" instead.' ,
6479 ) ;
0 commit comments