Skip to content

Commit

Permalink
(feat, express): pass next into express handlers (#3696)
Browse files Browse the repository at this point in the history
(feat): pass  into express handlers
  • Loading branch information
dsinghvi committed May 24, 2024
1 parent e2889e8 commit cda7b10
Show file tree
Hide file tree
Showing 131 changed files with 4,882 additions and 3,247 deletions.
11 changes: 11 additions & 0 deletions generators/typescript/express/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.15.0] - 2024-05-13

- Feature: Every endpoint method now accepts a third parameter called `next`. This gives
express authors access to the express internals if they are useful

```ts
getUsers: (req, res, next: NextFunction) => {
// implementation
}
```

## [0.14.0] - 2024-05-13

- Feature: Support a `skipResponseValidation` configuration so that users can disable
Expand Down
2 changes: 1 addition & 1 deletion generators/typescript/express/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.14.0
0.15.0
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ export class GeneratedExpressServiceImpl implements GeneratedExpressService {
}) {
const REQUEST_PARAMETER_NAME = "req";
const RESPONSE_PARAMETER_NAME = "res";
const NEXT_PARAMETER_NAME = "next";

const COOKIE_PARAMETER_NAME = "cookie";
const COOKIE_VALUE_PARAMETER_NAME = "value";
Expand Down Expand Up @@ -303,6 +304,10 @@ export class GeneratedExpressServiceImpl implements GeneratedExpressService {
)
])
)
},
{
name: NEXT_PARAMETER_NAME,
type: getTextOfTsNode(context.externalDependencies.express.NextFunction._getReferenceToType())
}
],
returnType: getTextOfTsNode(
Expand Down Expand Up @@ -673,7 +678,8 @@ export class GeneratedExpressServiceImpl implements GeneratedExpressService {
)
],
true
)
),
next
]
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export interface Express {
locals: (args: { referenceToExpressResponse: ts.Expression }) => ts.Expression;
_getReferenceToType: () => ts.TypeNode;
};
NextFunction: {
_getReferenceToType: () => ts.TypeNode;
};
App: {
use: (args: { referenceToApp: ts.Expression; path: ts.Expression; router: ts.Expression }) => ts.Expression;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ export class ExpressImpl extends ExternalDependency implements Express {
protected override PACKAGE = { name: "express", version: "4.18.2" };
protected override TYPES_PACKAGE = { name: "@types/express", version: "4.17.16" };

public NextFunction = {
_getReferenceToType: this.withDefaultImport("express", (withImport, express) =>
withImport(() => {
return ts.factory.createTypeReferenceNode(
ts.factory.createQualifiedName(ts.factory.createIdentifier(express), "NextFunction"),
[]
);
})
)
};

public Request = {
body: "body" as const,
_getReferenceToType: this.withDefaultImport("express", (withImport, express) =>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 16 additions & 11 deletions seed/ts-express/audiences/api/resources/foo/service/FooService.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit cda7b10

Please sign in to comment.