Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): createRequestParamDecorator default support throw error #3656

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 18 additions & 21 deletions packages/core/src/decorator/web/paramMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ export interface RouterParamValue {
}

const createParamMapping = function (type: RouteParamTypes) {
return (propertyOrPipes?: any, pipes?: Array<PipeUnionTransform>) => {
return (propertyOrPipes: any, options: ParamDecoratorOptions = {}) => {
let propertyData = propertyOrPipes;
if (Array.isArray(propertyOrPipes) && pipes === undefined) {
pipes = propertyOrPipes;
if (Array.isArray(propertyOrPipes) && options.pipes === undefined) {
options.pipes = propertyOrPipes;
propertyData = undefined;
}
return createCustomParamDecorator(
Expand All @@ -40,9 +40,7 @@ const createParamMapping = function (type: RouteParamTypes) {
type,
propertyData,
},
{
pipes,
}
options
);
};
};
Expand Down Expand Up @@ -70,45 +68,44 @@ export const createRequestParamDecorator = function (
pipes: pipesOrOptions as Array<PipeUnionTransform>,
};
}
return createParamMapping(RouteParamTypes.CUSTOM)(
transform,
pipesOrOptions.pipes
);
if (pipesOrOptions.throwError == null) pipesOrOptions.throwError = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里还是 breaking 了,可以合到 4.x

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以的,先发你之前的小Patch吧


return createParamMapping(RouteParamTypes.CUSTOM)(transform, pipesOrOptions);
};

export const Session = (
propertyOrPipes?: string | PipeUnionTransform[],
pipes?: PipeUnionTransform[]
) => createParamMapping(RouteParamTypes.SESSION)(propertyOrPipes, pipes);
) => createParamMapping(RouteParamTypes.SESSION)(propertyOrPipes, { pipes });
export const Body = (
propertyOrPipes?: string | PipeUnionTransform[],
pipes?: PipeUnionTransform[]
) => createParamMapping(RouteParamTypes.BODY)(propertyOrPipes, pipes);
) => createParamMapping(RouteParamTypes.BODY)(propertyOrPipes, { pipes });
export const Query = (
propertyOrPipes?: string | PipeUnionTransform[],
pipes?: PipeUnionTransform[]
) => createParamMapping(RouteParamTypes.QUERY)(propertyOrPipes, pipes);
) => createParamMapping(RouteParamTypes.QUERY)(propertyOrPipes, { pipes });
export const Param = (
propertyOrPipes?: string | PipeUnionTransform[],
pipes?: PipeUnionTransform[]
) => createParamMapping(RouteParamTypes.PARAM)(propertyOrPipes, pipes);
) => createParamMapping(RouteParamTypes.PARAM)(propertyOrPipes, { pipes });
export const Headers = (
propertyOrPipes?: string | PipeUnionTransform[],
pipes?: PipeUnionTransform[]
) => createParamMapping(RouteParamTypes.HEADERS)(propertyOrPipes, pipes);
) => createParamMapping(RouteParamTypes.HEADERS)(propertyOrPipes, { pipes });
export const File = (propertyOrPipes?: any, pipes?: PipeUnionTransform[]) =>
createParamMapping(RouteParamTypes.FILESTREAM)(propertyOrPipes, pipes);
createParamMapping(RouteParamTypes.FILESTREAM)(propertyOrPipes, { pipes });
export const Files = (propertyOrPipes?: any, pipes?: PipeUnionTransform[]) =>
createParamMapping(RouteParamTypes.FILESSTREAM)(propertyOrPipes, pipes);
createParamMapping(RouteParamTypes.FILESSTREAM)(propertyOrPipes, { pipes });
export const RequestPath = (pipes?: PipeUnionTransform[]) =>
createParamMapping(RouteParamTypes.REQUEST_PATH)(undefined, pipes);
createParamMapping(RouteParamTypes.REQUEST_PATH)(undefined, { pipes });
export const RequestIP = (pipes?: PipeUnionTransform[]) =>
createParamMapping(RouteParamTypes.REQUEST_IP)(undefined, pipes);
createParamMapping(RouteParamTypes.REQUEST_IP)(undefined, { pipes });
export const Queries = (
propertyOrPipes?: string | PipeUnionTransform[],
pipes?: PipeUnionTransform[]
) => createParamMapping(RouteParamTypes.QUERIES)(propertyOrPipes, pipes);
) => createParamMapping(RouteParamTypes.QUERIES)(propertyOrPipes, { pipes });
export const Fields = (
propertyOrPipes?: string | PipeUnionTransform[],
pipes?: PipeUnionTransform[]
) => createParamMapping(RouteParamTypes.FIELDS)(propertyOrPipes, pipes);
) => createParamMapping(RouteParamTypes.FIELDS)(propertyOrPipes, { pipes });
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ exports[`/test/web/paramMapping.test.ts paramMapping decorator should be ok 1`]
"pipes": [
[Function],
],
"throwError": true,
},
"parameterIndex": 9,
"propertyName": "doget",
Expand Down Expand Up @@ -162,6 +163,7 @@ exports[`/test/web/paramMapping.test.ts paramMapping decorator should be ok 1`]
"pipes": [
[Function],
],
"throwError": true,
},
"parameterIndex": 0,
"propertyName": "dogetError",
Expand Down
Loading