Skip to content

Commit

Permalink
feat(platform-router): add PlatformHandlerMetadata.isRawMiddleware
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed Mar 24, 2024
1 parent c18add2 commit 998fb62
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/platform/platform-fastify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@
"@tsed/di": "workspace:*",
"@tsed/platform-test-sdk": "workspace:*",
"@types/content-disposition": "^0.5.4",
"barrelsby": "2.8.1",
"cross-env": "7.0.3",
"fastify": "4.23.2",
"fastify-raw-body": ">=4.3.0",
"jest": "^29.2.0",
"ts-node": "10.9.2"
},
"peerDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe("PlatformHandlerMetadata", () => {
expect(handlerMetadata.hasNextFunction).toEqual(false);
expect(handlerMetadata.hasErrorParam).toEqual(false);
expect(handlerMetadata.toString()).toEqual("");
expect(handlerMetadata.isRawMiddleware()).toEqual(false);
});
});
describe("from function", () => {
Expand All @@ -48,6 +49,7 @@ describe("PlatformHandlerMetadata", () => {
expect(handlerMetadata.hasNextFunction).toEqual(true);
expect(handlerMetadata.hasErrorParam).toEqual(false);
expect(handlerMetadata.toString()).toEqual("handler");
expect(handlerMetadata.isRawMiddleware()).toEqual(true);
});
});
describe("from function err", () => {
Expand All @@ -65,6 +67,7 @@ describe("PlatformHandlerMetadata", () => {
expect(handlerMetadata.hasErrorParam).toEqual(true);
expect(handlerMetadata.propertyKey).toBeUndefined();
expect(handlerMetadata.toString()).toEqual("handler");
expect(handlerMetadata.isRawMiddleware()).toEqual(true);
});
});
describe("from function without nextFn", () => {
Expand All @@ -83,6 +86,7 @@ describe("PlatformHandlerMetadata", () => {
expect(handlerMetadata.hasErrorParam).toEqual(false);
expect(handlerMetadata.propertyKey).toBeUndefined();
expect(handlerMetadata.toString()).toEqual("handler");
expect(handlerMetadata.isRawMiddleware()).toEqual(true);
});
});
describe("from endpoint/middleware with injection", () => {
Expand Down Expand Up @@ -116,6 +120,7 @@ describe("PlatformHandlerMetadata", () => {

expect(handlerMetadata.getParams()[0].paramType).toEqual("REQUEST");
expect(handlerMetadata.getParams()[1].paramType).toEqual("NEXT_FN");
expect(handlerMetadata.isRawMiddleware()).toEqual(false);
});
});

Expand Down Expand Up @@ -144,6 +149,7 @@ describe("PlatformHandlerMetadata", () => {
expect(handlerMetadata.hasErrorParam).toEqual(true);
expect(handlerMetadata.propertyKey).toEqual("use");
expect(handlerMetadata.toString()).toEqual("Test.use");
expect(handlerMetadata.isRawMiddleware()).toEqual(false);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ export class PlatformHandlerMetadata {
return this.type === PlatformHandlerType.RESPONSE_FN;
}

public isRawMiddleware() {
return !this.isInjectable() && (this.type === PlatformHandlerType.RAW_FN || this.type === PlatformHandlerType.RAW_ERR_FN);
}

toString() {
return [nameOf(this.target), this.propertyKey].filter(Boolean).join(".");
}
Expand Down
4 changes: 3 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7323,10 +7323,12 @@ __metadata:
"@tsed/di": "workspace:*"
"@tsed/platform-test-sdk": "workspace:*"
"@types/content-disposition": "npm:^0.5.4"
barrelsby: "npm:2.8.1"
content-disposition: "npm:>=0.5.4"
cross-env: "npm:7.0.3"
fastify: "npm:4.23.2"
fastify-raw-body: "npm:>=4.3.0"
jest: "npm:^29.2.0"
ts-node: "npm:10.9.2"
tslib: "npm:2.6.1"
peerDependencies:
Expand Down Expand Up @@ -11274,7 +11276,7 @@ __metadata:
languageName: node
linkType: hard

"barrelsby@npm:^2.8.1":
"barrelsby@npm:2.8.1, barrelsby@npm:^2.8.1":
version: 2.8.1
resolution: "barrelsby@npm:2.8.1"
dependencies:
Expand Down

0 comments on commit 998fb62

Please sign in to comment.